Repository navigation
fix(claude-agent-sdk): keep new hook input fields on hook spans - #981
Merged
Abhijeet Prasad (AbhiPrasad) merged 1 commit intoOct 19, 2026
Merged
Conversation
Claude Agent SDK 0.2.166 added hook input fields that the top-level hook allowlist silently dropped. Add duration_ms, prompt_id, effort, last_assistant_message, error and is_interrupt to _HOOK_ALLOWED_FIELDS. background_tasks and session_crons stay excluded for now. Fixes #973 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
Andrew Kent (realark)
approved these changes
Oct 19, 2026
Abhijeet Prasad (AbhiPrasad)
deleted the
abhi/allow-claude-hook-fields-c3da787f
branch
October 19, 2026 23:15
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.
Fixes #973
AI Summary
Problem
Hook spans filter the hook's
input_datathrough_HOOK_ALLOWED_FIELDS, a top-level allowlist. The allowlist is there to keep local paths such ascwdandtranscript_pathout of Braintrust. Any key not on the list is dropped.claude-agent-sdk 0.2.166 (bundled Claude Code CLI) started sending more hook input fields. None of them were on the allowlist, so they never reached the span.
errorandis_interruptonPostToolUseFailurewere already missing before that release.prompt_id,effortBaseHookInput)duration_msPostToolUse,PostToolUseFailureerror,is_interruptPostToolUseFailurelast_assistant_messageStop,SubagentStopSo a failed tool's hook span didn't say why it failed, and hook spans couldn't be linked to the prompt they ran for.
Fix
Add the fields to the allowlist in
py/src/braintrust/integrations/claude_agent_sdk/tracing.py:_HOOK_ALLOWED_FIELDS = frozenset( { # Common input fields "session_id", "hook_event_name", + "prompt_id", + "effort", # Event-specific input fields "tool_name", "tool_input", "tool_response", + "duration_ms", + "error", + "is_interrupt", "prompt", "message", "stop_hook_active", + "last_assistant_message", ...It stays an allowlist, so
cwd,transcript_pathandagent_transcript_pathare still dropped.Decisions:
background_tasks/session_cronsstay excluded, as the issue asked. They are lists of shell commands and cron prompts that can be large and contain user content, so they need a separate decision.duration_msgoes in the spaninputonly, not the metrics. It measures how long the tool ran. The hook span's own start and end measure the hook callback, so putting tool runtime in that span's metrics would be misleading.The hook cassettes for
latestwere re-recorded with the pinned SDK so they contain the new fields. One new cassette coversPostToolUseFailure.test_tool_hooks_create_function_spansoverlapped withtest_hook_spans_parent_to_matching_tool_and_final_llm, so it was merged into that test and its cassettes were removed.🤖 Generated with Claude Code