A Claude Code status line for watching context and cache
Most of what a Claude Code session costs is decided by two things you can’t see by default: how big the context has grown, and whether the prompt cache is still warm. I wrote a status line that keeps both on screen, along with the session cost and my plan usage. It’s on GitHub at SnowySailor/claude.

From left to right:
- Model and effort level, e.g.
[Opus 5.5 · high] - 💰 Session cost, Claude Code’s estimate at list prices
- 🎟️ Input tokens in the context window
- Context used, as a percentage of the window. Green below 70%, yellow below 90%, red after that
- 🧊 Prompt cache countdown and its lifetime (
5mor1h), orcoldonce it has expired - ⏱️ Session and weekly plan usage, with the time until each resets (subscriptions only)
- 🌿 Git branch, with a red
*when there are uncommitted changes
How status lines work
A status line is any command you put under statusLine in ~/.claude/settings.json. Claude Code runs it,
pipes in a JSON object describing the session, and shows whatever it prints in a row under the prompt.1
{
"statusLine": {
"type": "command",
"command": "~/.claude/statusline.sh",
"refreshInterval": 10
}
}
The script runs again when a new message arrives, after /compact, when you switch permission mode, and
when a warm cache reaches its expiry time. The countdown needs to tick down while you’re reading or away
from the keyboard, though, so refreshInterval also re-runs it every 10 seconds.
The JSON includes far more than I show. The fields this status line reads are:
| Field | Shown as |
|---|---|
context_window.total_input_tokens |
🎟️ input tokens |
context_window.used_percentage |
context % |
cost.total_cost_usd |
💰 session cost |
prompt_cache.warm, .ttl, .expires_at |
🧊 cache countdown |
rate_limits.five_hour, .seven_day |
⏱️ plan usage and reset times |
Why watch the context size
The model doesn’t remember anything between requests. Every time Claude replies to you or calls a tool, Claude Code sends the whole conversation again: the system prompt, your CLAUDE.md, every message, every file it has read and every command output so far.2 A turn in a 400k-token session sends 400k tokens, even if all you typed was “thanks”.
Most of that is read from the prompt cache, which is cheap per token. But it’s paid for again on every turn, and the turns keep coming: a single request from you can easily become dozens of tool calls. In my sessions this makes the total cost grow roughly with the square of the context size, which I go into in Subagents make Claude Code cheaper.
That’s why the status line shows the token count next to the percentage. With a 1M-token context window, “20%” sounds harmless, but it means every turn is re-sending 200k tokens. When the number gets large I do one of these:
/clearwhen I’m moving on to something unrelated/compactat a natural break, when I still need the gist of what came before- Hand the next big chunk of work to a subagent, so its file reads and logs never land in the main context
Why watch the cache
Prompt caching is what keeps long sessions affordable. The API keeps the processed context around for a while, and as long as the next request starts with exactly the same content, it’s billed at the cache read price instead of being processed again. Each cache hit resets the timer. If nothing is sent before the timer runs out, the cache expires, and the next request has to process and write the entire context again.3
Claude Code picks the cache lifetime (TTL) for you:
| Main conversation | Subagents | |
|---|---|---|
| Claude subscription, within plan usage | 1 hour | 5 minutes |
| API key, cloud provider, or usage credits | 5 minutes | 5 minutes |
You can change these with the promptCacheTtl and subagentPromptCacheTtl settings. The cost of an
expired cache is easy to underestimate, because cache reads are so cheap. With Claude Opus 5.5’s list
prices,4 the next turn of a 400k-token session costs:
| Next turn | Price per million tokens | Cost of 400k tokens |
|---|---|---|
| Cache still warm (cache read) | $0.20 | $0.08 |
| Expired, 5-minute TTL (cache write) | $5.00 | $2.00 |
| Expired, 1-hour TTL (cache write) | $8.00 | $3.20 |
Coming back to a cold session costs 25–40 times as much as one more turn would have. Do it a few times a day in a big session and it adds up fast. The countdown turns this into a decision instead of a surprise:
- If the cache is about to expire and I’m not done, I send the next message now rather than after a coffee.
- If I’m stepping away from a large session, I
/clearor/compactit first, or I accept that the first turn back will be expensive. - If the line says
cold, it may be cheaper to start fresh than to resume a 500k-token conversation for one more question.
The cache also resets on things other than time. Switching models, turning on fast mode and compacting all start a new cache, and the official docs list the rest.3 Expiry is the one you can see coming, though.
Plan usage
If you use a Claude subscription, the JSON also has rate_limits: the percentage used of the rolling
5-hour session limit and of the weekly limit, and when each one resets. The status line shows both, so I
know when to slow down before hitting a limit.
The dollar figure is still useful on a subscription. You don’t pay per token, but your usage is measured in tokens, so plan usage rises in step with the cost estimate. Everything above that saves money also stretches your limits.
With an API key, the plan usage fields aren’t there, and the line shows the cache countdown with a 5-minute TTL:

Under the hood
The script is plain bash and jq. Most fields are a one-liner, using jq’s // operator for a default when
a field is missing:
input=$(cat)
COST=$(echo "$input" | jq -r '.cost.total_cost_usd // 0')
PCT=$(echo "$input" | jq -r '.context_window.used_percentage // 0' | cut -d. -f1)
SESSION_PCT=$(echo "$input" | jq -r '.rate_limits.five_hour.used_percentage // empty')
The cache fields need one trick. // treats false the same as a missing value, so
.prompt_cache.warm // empty prints nothing when the cache is cold, which is exactly the case you want to
show. The script checks that the object exists instead:
CACHE_WARM=$(echo "$input" | jq -r 'if .prompt_cache then (.prompt_cache.warm | tostring) else empty end')
CACHE_EXP=$(echo "$input" | jq -r '.prompt_cache.expires_at // empty' | cut -d. -f1)
CACHE_LEFT=$((CACHE_EXP - $(date +%s)))
The prompt_cache object needs Claude Code v2.1.251 or later. It has more in it than I use, such as the
session’s cache hit ratio and the likely cause of the last cache miss, if you want to build on it.
Install
You need jq, plus git for the branch segment.
git clone https://github.com/SnowySailor/claude.git
cd claude
./install.sh
The installer copies statusline.sh to ~/.claude/statusline.sh and adds the statusLine setting to
~/.claude/settings.json, leaving your other settings alone. It asks before replacing a different
statusline.sh that’s already there. Restart Claude Code to see it.
References
Footnotes
-
Claude Code docs, Customize your status line: “It receives JSON session data on stdin and displays whatever your script prints, giving you a persistent, at-a-glance view of context usage, costs, git status, or anything else you want to track.” ↩
-
Claude Code docs, How Claude Code uses prompt caching: “The model doesn’t remember anything between requests, so Claude Code re-sends the full context: the system prompt, your project context, every prior message and tool result, and your new message.” ↩
-
Claude Code docs, How Claude Code uses prompt caching: “Each request that hits the cache resets the timer, so the cache stays warm as long as you keep working. After a long enough gap, the next request recomputes the full input and re-establishes the cache.” ↩ ↩2