Feature request: Per-session usage summary in session data
Feature Request
Summary
Add per-session aggregated token usage data that is easily accessible without parsing the entire JSONL transcript file.
Current Behavior
Currently, Claude Code stores token usage data only at the per-message level, embedded within each assistant event in the session JSONL transcript files:
{
"type": "assistant",
"message": {
"usage": {
"input_tokens": 3,
"cache_creation_input_tokens": 43538,
"cache_read_input_tokens": 0,
"output_tokens": 2,
"service_tier": "standard"
}
}
}
The only aggregated usage data available is in ~/.claude/stats-cache.json, but this provides only global/daily totals - not per-session breakdowns.
To get per-session usage totals, one must:
- Read the entire JSONL file (which can be 10MB+)
- Parse every line
- Filter for
assistanttype events - Sum up
input_tokens,output_tokens,cache_creation_input_tokens, andcache_read_input_tokensfrom eachmessage.usageobject
Desired Behavior
Provide per-session aggregated token usage in an easily accessible location. Possible approaches:
- End-of-session summary event: Add a
"type": "session_summary"event at the end of the JSONL file when a session completes, containing total token counts - Session metadata file: Store aggregated usage in a companion JSON metadata file (e.g.,
<session-id>.meta.json) alongside the JSONL transcript - Include in session list API: If Claude Code has internal APIs for listing sessions, include usage totals in the response
Use Case
Building tools that display session history with usage information (e.g., a local diff viewer / session browser). Currently, calculating per-session usage requires parsing potentially very large JSONL files, which is slow and memory-intensive for sessions with many messages.
Additional Context
- Session JSONL files can contain hundreds or thousands of assistant events
- Event types found in session files:
user,assistant,progress,system,queue-operation,file-history-snapshot- none contain aggregated usage - The
stats-cache.jsonfile only provides daily/model-level aggregation, not per-session
This issue has 2 comments on GitHub. Read the full discussion on GitHub ↗