PostToolUse hook not sending tool_use_id field as documented
Problem
The PostToolUse hook is not sending the tool_use_id field in the hook data, despite being documented in the official hooks documentation.
Documentation vs. Reality
According to the documentation (PostToolUse Input):
The hook should receive:
{
"tool_name": "Read",
"tool_input": {...},
"tool_response": {...},
"tool_use_id": "toolu_01XX...",
"session_id": "...",
"transcript_path": "...",
...
}
In reality:
The tool_use_id field is always null or missing from the hook data.
Impact
Without tool_use_id, we cannot:
- Correlate tool executions with Claude's internal transcript
- Match PreToolUse and PostToolUse events for the same tool call
- Handle parallel tool execution correctly (multiple tools running simultaneously)
- Build accurate trace hierarchies for LangSmith-style visualization
Current Workaround
We're forced to parse the transcript JSONL file to extract tool_use_id by searching for the most recent tool_use block that matches the tool name:
# Workaround: Parse transcript to find tool_use_id
def _extract_tool_use_id_from_transcript(transcript_path: str, tool_name: str):
# Read last 100 lines of transcript
# Parse JSONL entries
# Find most recent {"type": "tool_use", "name": tool_name, "id": "toolu_..."}
# Return the id
This is fragile because:
- It's slow (reads 100+ lines per tool call)
- Can mismatch tools with the same name
- Fails with parallel tool execution
- Adds unnecessary complexity
Expected Behavior
Claude Code should send tool_use_id in both PreToolUse and PostToolUse hook data, exactly as documented.
Environment
- Claude Code version: Latest (as of 2024-12-06)
- Hook: PostToolUse
- Platform: macOS (but affects all platforms)
Request
Please add the tool_use_id field to the hook data as documented, so we can correlate tool executions without parsing transcript files.
Thank you!
This issue has 5 comments on GitHub. Read the full discussion on GitHub ↗