[FEATURE] Expose session cost and context usage in hook event data

Resolved 💬 4 comments Opened Mar 1, 2026 by mingrath Closed Apr 2, 2026

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

I built claude-code-statusline, a custom statusline that shows real-time session cost, context token usage, and rate limit percentages. To get this data, I had to reverse-engineer the OAuth API and parse internal response headers — the official statusLine JSON input doesn't include cost or detailed context data.

Hooks also don't receive any cost/usage metadata. If I want to trigger an action when context usage exceeds 80% (e.g., remind myself to compact), I have no clean way to do it.

Proposed Solution

Include session metrics in the JSON data passed to:

  1. statusLine command input — already receives some JSON, add these fields:
{
  "session": {
    "cost_usd": 1.23,
    "duration_seconds": 342,
    "input_tokens": 45000,
    "output_tokens": 12000
  },
  "context": {
    "used_tokens": 87000,
    "max_tokens": 200000,
    "percentage": 43.5
  },
  "rate_limit": {
    "five_hour_percentage": 67.2,
    "five_hour_reset_seconds": 4200
  }
}
  1. Hook event data — pass the same metrics so hooks can react to thresholds.

Feature Area

Developer tools/SDK

Use Case Example

  1. I'm building a custom statusline that shows session cost
  2. Currently I have to hit the OAuth API directly and parse x-ratelimit-* headers
  3. With this feature, I'd just read context.percentage and rate_limit.five_hour_percentage from the statusline JSON input
  4. My statusline code drops from 300 lines to 50 lines
  5. Hooks could also fire alerts when context.percentage > 80 — "consider compacting"

Additional Context

I built claude-code-statusline that already does this by calling the API directly. The existing statusLine JSON input includes git info and basic state, but not the metrics power users need most: cost, context %, and rate limits.

Note: There are several existing issues requesting rate limit data in statusline JSON (#27508, #26108, #25420). This request is broader — it includes session cost and context token usage alongside rate limits, and extends to hook event data as well.

View original on GitHub ↗

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