Trace Claude Agent SDK agents with Weave
- Python
- TypeScript
The Weave SDK autopatches the Claude Agent SDK for Python, letting you capture traces from your Claude agents with minimal setup.This guide shows how to initialize Weave and run a Claude agent with MCP tools through
ClaudeSDKClient. Weave automatically traces the conversation, model calls, and tool calls end-to-end.Prerequisites
- A W&B account and API key set as a
WANDB_API_KEYenvironment variable. - An Anthropic API key set as an
ANTHROPIC_API_KEYenvironment variable. - Python 3.10+.
Install packages
Install the following packages in your developer environment. Theweave package captures traces, and claude-agent-sdk provides the agent runtime.
Initialize Weave in your code
- Python
- TypeScript
Add When the script runs,
weave.init to the project, update your W&B team and project names, and then build an agent the way you normally would. weave.init enables the autopatching that captures traces from the Claude Agent SDK.The following code creates a Claude agent with two MCP math tools and runs it while Weave captures the traces.weave.init() prints a link to your project. Open the link to inspect the captured traces for the agent’s query, model responses, and tool calls.See your agent traces in the Agents view
After the script runs,weave.init() prints a link to your project. Open the Agents view to inspect:
- A session containing the conversation’s turns.
- Each turn rendered as an
invoke_agentspan with nestedchatandexecute_toolchildren. - The full input, model, output, token usage, and tool results at each step.