claude-code - 💡(How to fix) Fix [FEATURE] Add prompt_id to PostToolUse and PreToolUse hook payloads

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…

Code Example

{
  "session_id": "abc123",
  "prompt_id": "550e8400-e29b-41d4-a716-446655440000",
  "hook_event_name": "PostToolUse",
  "tool_name": "Write",
  "tool_input": { ... },
  "tool_response": { ... },
  "tool_use_id": "..."
}
RAW_BUFFERClick to expand / collapse

Preflight Checklist

  • I have searched existing requests and this feature hasn't been requested yet
  • 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 exposes session_id.

This creates an inconsistency: the PostToolUse hook fires at the same lifecycle moment as the claude_code.tool_result OTel event, but the two outputs don't share a common key below session_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 existing session_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_usd per prompt_id from 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. With prompt_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

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING