[FEATURE] Include session usage totals in Stop/SubagentStop hook payload
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
The Stop and SubagentStop hook payloads currently contain no usage or cost data. Tools that track developer LLM usage (dashboards, cost allocation systems, etc.) must work around this by reading the local transcript JSONL file — which is incomplete.
Current payload (Stop)
{
"hook_event_name": "Stop",
"session_id": "...",
"transcript_path": "...",
"cwd": "...",
"prompt_id": "...",
"permission_mode": "...",
"effort": { "level": "high" },
"stop_hook_active": false,
"last_assistant_message": "...",
"background_tasks": [],
"session_crons": []
}
No usage field.
Problem
Claude CLI tracks complete session usage in memory (visible via /usage), including:
Internal session title generation calls (e.g. Haiku ai-title)
Other background API calls
None of these are written to the transcript JSONL. Since the Stop hook payload also omits usage data, external tools have no way to capture the complete picture. The gap is small but causes a persistent mismatch between what /usage reports and what any external dashboard can track.
Proposed Solution
Add a usage object to the Stop and SubagentStop hook payloads containing cumulative session totals at the time the hook fires:
{
"hook_event_name": "Stop",
"session_id": "...",
"usage": {
"input_tokens": 349,
"output_tokens": 214,
"cache_read_input_tokens": 90500,
"cache_creation_input_tokens": 12000,
"cost_usd": 0.1031
},
...
}
For SubagentStop, this would be the subagent's own cumulative totals (same data Claude Code already tracks per-agent for /usage).
Alternative Solutions
Currently I work around this by reading the local transcript JSONL file (.claude/projects/{session_id}.jsonl) at Stop hook time and summing token usage from each assistant entry. However, this misses internal background API calls (e.g. session title generation using Haiku) that Claude CLI tracks in memory but never writes to the transcript. There is no other known data source available from outside the CLI.
Priority
Medium - Would be very helpful
Feature Category
CLI commands and flags
Use Case Example
Example scenario:
My team uses a shared AI usage dashboard to track Claude CLI token costs per developer, per project, and per story/ticket.
The Stop hook fires and we POST token totals to our backend API.
With the current setup, the dashboard consistently shows fewer tokens than claude /usage reports, because internal calls like session title generation are not in the transcript.
With a usage field in the Stop hook payload, we could POST the exact same totals that Claude CLI already has in memory — no parsing, no gap, fully accurate cost tracking.
Additional Context
This single addition would allow external usage-tracking integrations to be fully accurate without any JSONL parsing, and would close the gap caused by internal background calls that never appear in transcripts.
This issue has 2 comments on GitHub. Read the full discussion on GitHub ↗