Skip to main content

Documentation Index

Fetch the complete documentation index at: https://traceroot.ai/docs/llms.txt

Use this file to discover all available pages before exploring further.

Automatically capture agent invocations, subagent delegations, tool calls, and token usage from the Claude Agent SDK (Claude Code as a library).

Setup

import traceroot
from traceroot import Integration

traceroot.initialize(integrations=[Integration.CLAUDE_AGENT_SDK])

Usage

from claude_agent_sdk import query, ClaudeAgentOptions, AgentDefinition

# Define subagents
researcher = AgentDefinition(
    description="Research specialist for gathering information.",
    prompt="You are a research specialist. Use WebSearch to find info.",
    tools=["WebSearch"],
    model="haiku",
)

# Run the agent with subagents
async for message in query(
    prompt="Research the latest trends in AI observability",
    options=ClaudeAgentOptions(
        allowed_tools=["Agent", "Bash", "Read", "Glob", "Grep"],
        agents={"researcher": researcher},
    ),
):
    if hasattr(message, "result"):
        print(message.result)

What Gets Captured

AttributeDescription
Agent queriesEach query() call as a top-level agent span
Subagent invocationsEach subagent delegation via the Agent tool
Tool callsBuilt-in tools (Read, Write, Bash, Glob, Grep, WebSearch)
Token usageAggregated input/output tokens per query
CostTotal cost for the full query execution
Model nameThe model used (e.g., claude-sonnet-4-6, claude-haiku-4-5)

Run the example

Clone the repo and run a complete agent end-to-end.

Python

Run the Python example

TypeScript

Run the TypeScript example