Skip to content

feat(claude_agent_sdk): Instrument hooks#141

Merged
Abhijeet Prasad (AbhiPrasad) merged 2 commits intomainfrom
abhi-claude-agent-sdk-hooks
Mar 25, 2026
Merged

feat(claude_agent_sdk): Instrument hooks#141
Abhijeet Prasad (AbhiPrasad) merged 2 commits intomainfrom
abhi-claude-agent-sdk-hooks

Conversation

@AbhiPrasad
Copy link
Copy Markdown
Member

@AbhiPrasad Abhijeet Prasad (AbhiPrasad) commented Mar 25, 2026

resolves #67

Add support for instrumenting hooks for the claude agent sdk (https://platform.claude.com/docs/en/agent-sdk/hooks).

image

Instrument Claude Agent SDK hook callbacks through the Braintrust integration.

This changes the request-scoped tracing flow so hook callbacks running on the SDK control channel are captured alongside the existing Claude Agent task, LLM, and tool spans. The integration now starts request tracing at query time, wraps registered hook callbacks, records hook inputs and outputs as FUNCTION spans, and preserves correct parentage for tool lifecycle hooks and Stop hooks.

Users now get end-to-end visibility into Claude Agent SDK hooks, including UserPromptSubmit, PreToolUse, PostToolUse, and Stop callbacks. Hook spans attach to the matching tool span when possible, otherwise to the active LLM or task context, and UserPromptSubmit traces keep the original prompt attached to the request and LLM input.

Tests were updated with cassette-backed coverage for UserPromptSubmit hook tracing, tool hook tracing, hook parent/child relationships, and prompt attachment with UserPromptSubmit enabled. The Claude Agent SDK integration test suite passes against both the latest supported SDK and 0.1.10 replay environments.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

good to merge

@AbhiPrasad Abhijeet Prasad (AbhiPrasad) merged commit 8b15ad6 into main Mar 25, 2026
34 checks passed
@AbhiPrasad Abhijeet Prasad (AbhiPrasad) deleted the abhi-claude-agent-sdk-hooks branch March 25, 2026 20:05
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.

Make the Claude Agent SDK support instrumenting hooks

2 participants