Skip to main content
Use this integration for applications that call the Claude Agent SDK, formerly the Claude Code SDK. Python can patch query() during setup() before import. TypeScript uses an explicit wrapper because ESM namespace bindings cannot be safely patched in place. If your app shells out to the claude binary instead of importing @anthropic-ai/claude-agent-sdk or claude_agent_sdk, use Claude Code SDK traces.

Install

bun add @inference/tracing @anthropic-ai/claude-agent-sdk

TypeScript Wrapped Query

TypeScript
import { query } from "@anthropic-ai/claude-agent-sdk";
import { setup, wrapClaudeAgentSdkQuery } from "@inference/tracing";

const tracing = await setup({ serviceName: "claude-agent" });
const tracedQuery = wrapClaudeAgentSdkQuery(query, tracing);

const stream = tracedQuery({
  prompt:
    "Count the number of files matching *.md under the current directory tree. " +
    "Use the Bash tool. Reply with just the integer.",
  options: {
    maxTurns: 4,
    allowedTools: ["Bash"],
    permissionMode: "bypassPermissions",
  },
});

for await (const message of stream) {
  console.log(message);
}

await tracing.shutdown();

Python Query Loop

Python
import asyncio

from inference_catalyst_tracing import setup

tracing = setup(service_name="claude-agent")

from claude_agent_sdk import ClaudeAgentOptions, query

async def main() -> None:
    options = ClaudeAgentOptions(
        max_turns=4,
        allowed_tools=["Bash"],
        permission_mode="bypassPermissions",
    )
    async for message in query(
        prompt=(
            "Count files matching *.md under the current directory tree. "
            "Use the Bash tool. Reply with just the integer."
        ),
        options=options,
    ):
        print(message)

asyncio.run(main())
tracing.shutdown()

What To Look For

  • An AGENT span for the query run
  • Nested LLM turns from the Claude Agent SDK
  • Tool-use and tool-result data when built-in tools are used
  • Final assistant output captured on the span