SETTINGS · cost-engineering

Status line: live cost, quota, and cache share

A status line script showing the session's API-equivalent dollars, context usage, cache-read share of the last request, and Pro/Max quota windows: the numbers that steer spend, always in view.

✓ verified 2026-07-09 · stack: claude-code · source

Dashboards steer platform teams; the status line steers the person typing. This script keeps the four numbers that change spending behaviour in view on every prompt: what the session has consumed in API-equivalent dollars, how full the context window is, what share of the last request was cache reads, and, on Pro and Max, how much of the five-hour and seven-day quota windows is gone. Background: subscription arbitrage and instrumenting Claude Code.

.claude/settings.json (or ~/.claude/settings.json for all projects)
{
"statusLine": {
"type": "command",
"command": "~/.claude/statusline-cost.sh"
}
}
~/.claude/statusline-cost.sh (chmod +x)
#!/usr/bin/env bash
# Claude Code status line: cost, context, cache share, quota.
# Input: session JSON on stdin (see code.claude.com/docs/en/statusline).
input=$(cat)
model=$(jq -r '.model.display_name // "?"' <<<"$input")
cost=$(jq -r '.cost.total_cost_usd // 0' <<<"$input")
ctx=$(jq -r '.context_window.used_percentage // 0 | floor' <<<"$input")
# Cache-read share of the last request's input. current_usage is null
# before the first API call and immediately after /compact.
cache=$(jq -r '
.context_window.current_usage as $u
| if $u == null then "-"
else ( ($u.cache_read_input_tokens // 0) as $r
| ($r + ($u.input_tokens // 0) + ($u.cache_creation_input_tokens // 0)) as $in
| if $in == 0 then "-"
else ((100 * $r / $in) | floor | tostring) + "%"
end )
end' <<<"$input")
# Subscription quota windows: present only for Pro/Max, and only after
# the first API response. Each window may be independently absent.
q5=$(jq -r '.rate_limits.five_hour.used_percentage // empty | floor' <<<"$input")
q7=$(jq -r '.rate_limits.seven_day.used_percentage // empty | floor' <<<"$input")
quota=""
[ -n "$q5" ] && quota=" | 5h ${q5}%"
[ -n "$q7" ] && quota="${quota} 7d ${q7}%"
printf '[%s] $%.2f | ctx %s%% | cache %s%s\n' \
"$model" "$cost" "$ctx" "$cache" "$quota"

A working line looks like:

[Sonnet] $1.84 | ctx 42% | cache 91% | 5h 37% 7d 12%

What it does

  • $ figure: cost.total_cost_usd, the client-side API-equivalent estimate for this session. On a subscription this is not a bill; it is the number that makes the subscription-versus-API comparison possible, one session at a time.
  • ctx: context_window.used_percentage. Context size is the main cost driver per message, so this is the earliest cheap-to-act-on signal: a /clear at a natural boundary is worth more than any model switch.
  • cache: cache reads as a share of the last request’s input tokens, from context_window.current_usage. Healthy agentic sessions run high; a sudden drop means something invalidated the prefix cache and every subsequent message is paying write premiums.
  • 5h / 7d: the subscription quota windows, from rate_limits. These fields exist only on Pro/Max sessions, so the script prints them when present and stays silent on API billing. The same script works for both funding models.
  • The script is read-only, runs on every status line refresh, and needs only jq.

Failure modes

  • Fields arrive late or not at all. current_usage is null before the first API call and right after /compact; rate_limits appears only after the first API response and each window can be independently absent. Every access above has a // fallback. Keep that pattern if you extend the script, or the status line goes blank exactly when a session starts.
  • The dollars are estimates. Client-side, list-price maths: treat as steering, not billing, and expect drift against the Console’s usage page.
  • Cache share reads low on small requests. A request with little input besides fresh text (a short prompt after /clear) legitimately shows a low share; the signal is the trend within a long session, not any single reading.
  • Usage elsewhere is invisible. Quota percentages reflect this account’s consumption including other devices, but the cost figure is this session only; neither includes claude.ai chat usage in the cost line.
  • prompt_id needs a current CLI. If you extend the script to log lines per prompt (joining to OTel events via prompt.id), that field requires Claude Code v2.1.196 or later. Guard it like the others.

Verified against the Claude Code status line documentation (field names, null behaviour, rate-limit window semantics, settings shape), 2026-07-09.