Skip to content

fix: Fix claude agent SDK tool nesting#1755

Merged
Luca Forstner (lforst) merged 4 commits intomainfrom
lforst/agent-sdk-tool-nesting
Apr 8, 2026
Merged

fix: Fix claude agent SDK tool nesting#1755
Luca Forstner (lforst) merged 4 commits intomainfrom
lforst/agent-sdk-tool-nesting

Conversation

@lforst
Copy link
Copy Markdown
Member

@lforst Luca Forstner (lforst) commented Apr 7, 2026

Resolves #1655
Resolves #1658

Fixes claude agent SDK tool nesting by switching from the hook based events (PreToolUse, PostToolUse) that started and ended the span to using AsyncLocalStorage and having proper execution context. For remote tools we are still using the hooks because we don't have any local tools to wrap.

Screenshot 2026-04-08 at 12 48 47

@lforst Luca Forstner (lforst) marked this pull request as ready for review April 8, 2026 10:36
spanAttributes: {
type: SpanTypeAttribute.LLM,
},
startTime: getCurrentUnixTimestamp(),
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not sure if this timestamp is correct, isn't that relative to when the tool call ran? And not actually when the llm call itself ran?

@lforst Luca Forstner (lforst) merged commit 61e8a60 into main Apr 8, 2026
49 checks passed
@lforst Luca Forstner (lforst) deleted the lforst/agent-sdk-tool-nesting branch April 8, 2026 14:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

wrapClaudeAgentSDK should re-enter active tool spans inside local tool handlers Claude Agent SDK JS tool spans should nest under the active LLM span

2 participants