Overview
Moda tracks your Claude Agent SDK sessions, including Claude Code and custom agents built withclaude-agent-sdk. Token usage, tool calls, agent turns, and session metadata are all captured automatically.
Why a Separate Package?
The Claude Agent SDK spawns Claude as a subprocess rather than making direct Anthropic API calls. This means standard Anthropic API instrumentation (moda-anthropic) does not fire. The moda-claude-agent-sdk package provides a dedicated instrumentor that wraps ClaudeSDKClient to capture agent-level spans.
Setup
The Claude Agent SDK is Python-only. Node.js is not currently supported.
Quick Start
Supported Features
| Feature | Captured |
|---|---|
| Agent sessions | Yes |
| Streaming responses | Yes |
| Tool use tracking | Yes (count of tool calls across turns) |
| Token usage | Yes (input, output, total, including cache tokens) |
| Model name | Yes (request and response) |
| Session ID | Yes |
| Turn count | Yes |
Data Captured
| Attribute | Description |
|---|---|
gen_ai.request.model | Requested model name |
gen_ai.response.model | Actual model used in response |
gen_ai.usage.input_tokens | Input token count (including cache tokens) |
gen_ai.usage.output_tokens | Output token count |
llm.usage.total_tokens | Total token count |
claude_agent.num_turns | Number of conversation turns |
claude_agent.session_id | Agent session identifier |
claude_agent.tool_call_count | Total tool calls across all turns |
moda.conversation_id | Conversation ID (when set) |
moda.user_id | User ID (when set) |
Troubleshooting
Data not appearing?- Make sure you installed
moda-claude-agent-sdkseparately — it is not included withmoda-ai - Ensure
moda.init()is called before creating theClaudeSDKClient - Call
moda.flush()before your program exits
- Token usage comes from the
ResultMessageat the end of the stream. Make sure you consume the full async generator fromreceive_response()
- Verify that
claude-agent-sdkis installed and importable - Check that the instrumentor is active:
moda.init()automatically enables it when the package is installed
For full SDK documentation, see the Python SDK guide.