Claude Agent SDK

Trace the Claude Agent SDK with Neatlogs (TypeScript).

Import wrapClaudeAgentSDK from neatlogs/claude-agent-sdk to trace @anthropic-ai/claude-agent-sdk runs. Pass it the SDK module; it returns a copy with an instrumented query (all other exports pass through unchanged). A query(...) becomes an AGENT root (claude_agent.query) with one LLM span per assistant turn and TOOL spans for each tool use. Subagents spawned via the Task tool nest under their own claude_agent.subagent.<type> span.

Prerequisites

npm install neatlogs@latest @anthropic-ai/claude-agent-sdk

Usage

import { init, flush, shutdown } from 'neatlogs';
import { wrapClaudeAgentSDK } from 'neatlogs/claude-agent-sdk';
import * as claudeAgentSDK from '@anthropic-ai/claude-agent-sdk';

async function main() {
  await init({ apiKey: process.env.NEATLOGS_API_KEY, workflowName: 'claude-agent-demo' });

  // Wrap the SDK module, then use its `query` as usual.
  const { query } = wrapClaudeAgentSDK(claudeAgentSDK);

  for await (const message of query({
    prompt: 'List the files in the current directory and summarize what this project does.',
    options: { model: 'claude-sonnet-4-5' },
  })) {
    if (message.type === 'result') console.log(message.result);
  }

  await flush();
  await shutdown();
}

main().catch(console.error);

The AGENT span is itself a valid trace root, so no WORKFLOW wrapper is needed. Per-turn coalescing keeps one LLM span per model turn with its full input/output and token usage.

On this page