Feature request: Per-session usage summary in session data

Resolved 💬 2 comments Opened Feb 9, 2026 by tacogips Closed Feb 9, 2026

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:

  1. Read the entire JSONL file (which can be 10MB+)
  2. Parse every line
  3. Filter for assistant type events
  4. Sum up input_tokens, output_tokens, cache_creation_input_tokens, and cache_read_input_tokens from each message.usage object

Desired Behavior

Provide per-session aggregated token usage in an easily accessible location. Possible approaches:

  1. 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
  2. Session metadata file: Store aggregated usage in a companion JSON metadata file (e.g., <session-id>.meta.json) alongside the JSONL transcript
  3. 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.json file only provides daily/model-level aggregation, not per-session

View original on GitHub ↗

This issue has 2 comments on GitHub. Read the full discussion on GitHub ↗