Commit 8b15ad6
authored
feat(claude_agent_sdk): Instrument hooks (#141)
* feat(claude_agent_sdk): Instrument hooks
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.
* relax assertion because windows timing1 parent 01d0cea commit 8b15ad6
5 files changed
Lines changed: 2364 additions & 37 deletions
File tree
- py/src/braintrust/integrations/claude_agent_sdk
- cassettes
0 commit comments