> ## Documentation Index
> Fetch the complete documentation index at: https://langchain-5e9cc07a-preview-update-1770920925-e15dbde.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# Trace Claude Agent SDK applications

The [Claude Agent SDK](https://platform.claude.com/docs/en/agent-sdk/overview) is an SDK for building agentic applications with Claude. LangSmith provides native integration with the Claude Agent SDK to automatically trace your agent executions, tool calls, and interactions with Claude models.

## Installation

Install the LangSmith integration for Claude Agent SDK

<CodeGroup>
  ```bash pip theme={null}
  pip install "langsmith[claude-agent-sdk]"
  ```

  ```bash uv theme={null}
  uv add "langsmith[claude-agent-sdk]"
  ```

  ```bash npm theme={null}
  npm install @anthropic-ai/claude-agent-sdk
  ```
</CodeGroup>

## Setup

Set your [API keys](/langsmith/create-account-api-key):

```bash theme={null}
export LANGSMITH_API_KEY=<your-langsmith-api-key>
export LANGSMITH_TRACING=true
export LANGSMITH_PROJECT=<your-project-name>
export ANTHROPIC_API_KEY=<your-api-key>
```

You can find your LangSmith API key and project name in the [LangSmith UI](https://smith.langchain.com) under **Settings**.

For an Anthropic API key, refer to the [Claude console](https://claude.ai/login).

## Quickstart

To enable LangSmith tracing for your Claude Agent SDK application, call `configure_claude_agent_sdk()` at the start of your application:

<CodeGroup>
  ```python Python theme={null}
  import asyncio
  from claude_agent_sdk import (
      ClaudeAgentOptions,
      ClaudeSDKClient,
      tool,
      create_sdk_mcp_server,
  )
  from typing import Any

  from langsmith.integrations.claude_agent_sdk import configure_claude_agent_sdk

  # Setup claude_agent_sdk with langsmith tracing
  configure_claude_agent_sdk()

  @tool(
      "get_weather",
      "Gets the current weather for a given city",
      {
          "city": str,
      },
  )
  async def get_weather(args: dict[str, Any]) -> dict[str, Any]:
      """Simulated weather lookup tool"""
      city = args["city"]

      # Simulated weather data
      weather_data = {
          "San Francisco": "Foggy, 62°F",
          "New York": "Sunny, 75°F",
          "London": "Rainy, 55°F",
          "Tokyo": "Clear, 68°F",
      }

      weather = weather_data.get(city, "Weather data not available")
      return {"content": [{"type": "text", "text": f"Weather in {city}: {weather}"}]}


  async def main():
      # Create SDK MCP server with the weather tool
      weather_server = create_sdk_mcp_server(
          name="weather",
          version="1.0.0",
          tools=[get_weather],
      )

      options = ClaudeAgentOptions(
          model="claude-sonnet-4-5-20250929",
          system_prompt="You are a friendly travel assistant who helps with weather information.",
          mcp_servers={"weather": weather_server},
          allowed_tools=["mcp__weather__get_weather"],
      )

      async with ClaudeSDKClient(options=options) as client:
          await client.query("What's the weather like in San Francisco and Tokyo?")

          async for message in client.receive_response():
              print(message)


  if __name__ == "__main__":
      asyncio.run(main())
  ```

  ```typescript TypeScript theme={null}
  import * as originalSdk from "@anthropic-ai/claude-agent-sdk";
  import { wrapClaudeAgentSDK } from "langsmith/experimental/anthropic";
  import { z } from "zod/v4";

  const sdk = wrapClaudeAgentSDK(originalSdk);

  const getWeather = sdk.tool("get_weather", "Gets the current weather for a given city", { city: z.string() }, async ({ city }) => {
      const weatherData = {
          "San Francisco": "Foggy, 62°F",
          "New York": "Sunny, 75°F",
          London: "Rainy, 55°F",
          Tokyo: "Clear, 68°F",
      };

      const weather = weatherData[city] ?? "Weather data not available";
      return { content: [{ type: "text", text: weather }] };
  });

  const weatherServer = sdk.createSdkMcpServer({
      name: "weather",
      version: "1.0.0",
      tools: [getWeather],
  });

  const query = sdk.query({
      prompt: "What's the weather like in San Francisco and Tokyo?",
      options: {
          model: "claude-sonnet-4-5-20250929",
          systemPrompt: "You are a friendly travel assistant who helps with weather information.",
          mcpServers: { weather: weatherServer },
          allowedTools: ["mcp__weather__get_weather"],
      },
  });

  for await (const chunk of query) {
      console.log(chunk);
  }
  ```
</CodeGroup>

Once configured, all Claude Agent SDK operations will be automatically traced to LangSmith, including:

* Agent queries and responses
* Tool invocations and results
* Claude model interactions
* MCP server operations

***

<Callout icon="pen-to-square" iconType="regular">
  [Edit this page on GitHub](https://github.com/langchain-ai/docs/edit/main/src/langsmith/trace-claude-agent-sdk.mdx) or [file an issue](https://github.com/langchain-ai/docs/issues/new/choose).
</Callout>

<Tip icon="terminal" iconType="regular">
  [Connect these docs](/use-these-docs) to Claude, VSCode, and more via MCP for real-time answers.
</Tip>
