[FEATURE] Add prompt_id to PostToolUse and PreToolUse hook payloads
Preflight Checklist
- [x] I have searched existing requests and this feature hasn't been requested yet
- [x] This is a single feature request (not multiple features)
Problem Statement
Claude Code already generates a prompt_id for every user prompt and emits it on OTel events
both claude_code.api_request and claude_code.tool_result carry it. However, prompt_id is
not present in the PostToolUse (or PreToolUse) hook JSON payload, which only exposessession_id.
This creates an inconsistency: the PostToolUse hook fires at the same lifecycle moment as theclaude_code.tool_result OTel event, but the two outputs don't share a common key belowsession_id. I imagine this value exists in the runtime at hook-fire time since it's being attached
to the concurrent OTel events.
Proposed Solution
Add prompt_id to the PostToolUse and PreToolUse hook JSON payloads alongside the existingsession_id. The change is additive and non-breaking.
{
"session_id": "abc123",
"prompt_id": "550e8400-e29b-41d4-a716-446655440000",
"hook_event_name": "PostToolUse",
"tool_name": "Write",
"tool_input": { ... },
"tool_response": { ... },
"tool_use_id": "..."
}
Alternative Solutions
_No response_
Priority
High - Significant impact on productivity
Feature Category
Other
Use Case Example
We're building a cost attribution pipeline to associate Claude Code API spend with
PRs and engineering initiatives. The architecture joins two BigQuery pipelines:
- Hooks pipeline captures which files were modified by which Claude session, via
PostToolUse hooks writing (session_id, file_path) tuples at edit time and reconciling
against committed files at push time.
- OTel pipeline captures token counts and
cost_usdperprompt_idfrom
claude_code.api_request events.
These pipelines currently can only join at session_id grain, which is too coarse since a session
spans hours and dozens of prompts, only some of which are relevant to any given commit. Withprompt_id in the hook payload, we can join at prompt grain and produce accurate per-PR and
per-initiative cost attribution.
Additional Context
_No response_
This issue has 3 comments on GitHub. Read the full discussion on GitHub ↗