feat(closes OPEN-10635): Claude Agent SDK TypeScript integration#208
Merged
gustavocidornelas merged 1 commit intoJun 5, 2026
Merged
Conversation
Merged
4 tasks
b6cbfdd to
21b1225
Compare
21b1225 to
90e07e5
Compare
Add tracing integration for Anthropic's Claude Agent SDK
(@anthropic-ai/claude-agent-sdk on npm).
- Drop-in import: `import { query } from "openlayer/lib/integrations/claudeAgentSdk"`
exposes a query() with the same signature as the SDK's, auto-traced.
- One-line setup alternative: traceClaudeAgentSdk() monkey-patches the
SDK's query and ClaudeSDKClient prototype for codebases that can't
change imports. Idempotent.
- Trace shape: root AGENT step "Claude Agent SDK query" per query()
call, with nested CHAT_COMPLETION per assistant turn and TOOL per
tool call. Subagent dispatches via the Agent tool become nested
AGENT steps; the subagent's chats and tools nest underneath via
parent_tool_use_id.
- Hooks (PreToolUse / PostToolUse / PostToolUseFailure) compose with
any user-provided hooks; we never replace.
- AsyncLocalStorage isolates per-query state so concurrent queries
don't trample each other's bookkeeping.
- New subpath export: ./integrations/claude-agent-sdk.
@anthropic-ai/claude-agent-sdk declared as an optional
peerDependency (^0.2.111).
- Tracer change limited to exporting createStep / getCurrentStep as
internal helpers so the integration can drive step lifecycle.
Captures: cost, tokens, duration, session_id, model, systemPrompt,
agent_config (resolved tools / mcp_servers / skills / plugins),
agents_defined (subagent definitions), permission_denials, modelUsage,
raw assistant messages, raw ResultMessage. MCP server env / headers /
authorization are redacted by default.
Tests: 17 unit tests + 1 live integration test (gated on
ANTHROPIC_API_KEY). Live test runs successfully against the real SDK
and Openlayer ingest.
Examples: examples/claude-agent-sdk-tracing.ts (basic + subagent
scenarios) and examples/claude-agent-sdk-multi-agent.ts (in-process
MCP server, multiple subagents, end-to-end audit report). Layout
matches repo conventions (flat, kebab-case).
Closes OPEN-10635. Parallel Python work in openlayer-ai/openlayer-python
under OPEN-10634.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
90e07e5 to
6dc052a
Compare
gustavocidornelas
approved these changes
Jun 5, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
First-party Openlayer tracing for the Claude Agent SDK (
@anthropic-ai/claude-agent-sdkon npm).import { query } from "openlayer/lib/integrations/claudeAgentSdk"— same signature as the SDK'squery, auto-traced.traceClaudeAgentSdk()runtime-patch init for codebases that can't change imports; patchesqueryandClaudeSDKClient.prototypeidempotently.PreToolUse/PostToolUse/PostToolUseFailure); we never replace.AGENTstep perquery(), nestedCHAT_COMPLETIONper assistant turn,TOOLper tool call. Subagents nest viaparent_tool_use_id. MCP tools parsed (mcp__server__tool). Cost/tokens/duration/session_id/agent_configon root. Per-query state isolated viaAsyncLocalStorage. Stream is a pure observer../integrations/claude-agent-sdkand@anthropic-ai/claude-agent-sdkdeclared as optional peerDependency (^0.2.111).Companion Python PR at openlayer-ai/openlayer-python#641 (OPEN-10634).
Test plan
yarn jest tests/integrations/claudeAgentSdk.test.tsANTHROPIC_API_KEY)examples/tracing/claude-agent-sdk/claudeAgentSdkTracing.tsruns end-to-end vianpx tsxyarn buildsucceeds and produces correct ESM/CJS/types for the new subpath exportyarn lintcleanPlan deviations (documented in individual commits)
@anthropic-ai/claude-agent-sdkis ESM-only; loader usesrequire()with a dynamic-import()fallback so Jest workers and older Node both work.AgentStepinstance because the baseStep.log()filters unknown keys.tsxas a devDependency so the example script can be smoke-tested locally.Closes OPEN-10635.
🤖 Generated with Claude Code