Claude Code Status Line Examples: Context, Rate Limits and Cache (Tested)
Claude Code's status line is one row (or more) at the bottom of the terminal that runs any script you point it at. Claude Code pipes session data to the script as JSON, and whatever the script prints is what you see. It runs locally and doesn't use API tokens. Set up well, it tells you three things before they cost you: the context window is filling, a plan limit is close, or the prompt cache is about to go cold.
Everything here was checked against Claude Code's status line documentation on 2026-11-18. The scripts were tested by piping 35 sample payloads through them (the test file is in the download). We have not tested them on Windows or inside a live Claude Code session, and Claude Code changes often, so re-check the docs for anything you rely on.
Download free-claude-statusline.zip (MIT, Python 3 standard library, no jq; a minimal bash + jq version; settings snippets; test.sh)
[Opus high] | my-app@feature-x +1 ~1 | ctx ▓▓▓▓▓▓▓░░░ 72% of 200k
5h 23% ↺1h33m | 7d 91% ↺5d1h | cache 1m
Set it up in two minutes
The quick way is to ask Claude Code itself: /statusline show model name and context percentage with a progress bar. It writes a script into ~/.claude/ and updates your settings.
To use your own script, save it (for example as ~/.claude/statusline.py), run chmod +x on it, and add this to ~/.claude/settings.json:
{
"statusLine": {
"type": "command",
"command": "python3 ~/.claude/statusline.py",
"refreshInterval": 30
}
}
type must be "command". padding (extra spaces) and refreshInterval (re-run every N seconds, minimum 1) are optional. By default the script only runs on events: session start, each new assistant message, after /compact, when the permission mode or vim mode changes, and when a rate-limit window or warm cache reaches its reset or expiry time. Updates are debounced at 300 ms. If your line shows a countdown, set refreshInterval so it doesn't sit stale while you read.
The fields worth showing
Claude Code sends a lot of JSON. These are the fields that answer "am I about to waste usage?":
| Field | What it tells you | Watch out |
|---|---|---|
context_window.used_percentage |
How full the context window is | Can be null early in a session |
context_window.context_window_size |
Max tokens for the current model | Use it with the percentage instead of assuming 200k |
rate_limits.five_hour.used_percentage, .resets_at |
5-hour plan usage, reset time (epoch seconds) | Only Pro, Max and Ultra, and only after the first reply |
rate_limits.seven_day.used_percentage, .resets_at |
Weekly plan usage and reset | Each window can be absent on its own |
rate_limits.spend_limit.* |
Spend against a Claude apps gateway limit | used_usd and limit_usd can arrive after the percentage |
prompt_cache.warm, .expires_at |
Whether the cached prefix is still warm, and when it goes cold | Absent until the first API response |
prompt_cache.recache_tokens_if_cold |
Tokens the next request re-caches if the cache has gone cold | null right after a compaction |
cost.total_cost_usd |
Estimated session cost | Client-side estimate at list price, not your bill |
effort.level |
Reasoning effort for the session | Absent when the model doesn't support effort |
session_id |
Stable per session | Use it to name cache files, not the process ID |
Two notes from the docs that save debugging time. /context can read higher than the status line, because the status line uses counts from the last API response while /context adds an estimate for messages since then. And rate_limits simply isn't there on API-key billing, so a script that assumes it exists prints errors or nothing.
Example 1: one line with jq
The smallest useful script. Missing fields are skipped instead of printing null:
#!/usr/bin/env bash
input=$(cat)
j() { printf '%s' "$input" | jq -r "$1" 2>/dev/null; }
MODEL=$(j '.model.display_name // .model.id // "Claude"')
DIR=$(j '.workspace.current_dir // .cwd // empty')
CTX=$(j '.context_window.used_percentage // empty | floor')
H5=$(j '.rate_limits.five_hour.used_percentage // empty | floor')
D7=$(j '.rate_limits.seven_day.used_percentage // empty | floor')
OUT="[$MODEL] ${DIR##*/}"
[ -n "$CTX" ] && OUT="$OUT | ctx $CTX%"
[ -n "$H5" ] && OUT="$OUT | 5h $H5%"
[ -n "$D7" ] && OUT="$OUT | 7d $D7%"
printf '%s\n' "$OUT"
Output: [Opus] my-app | ctx 72% | 5h 23% | 7d 91%. The download's statusline.sh adds the git branch.
Example 2: context bar with traffic-light colors
A 10-character bar in Python, no jq:
#!/usr/bin/env python3
import json, sys
d = json.load(sys.stdin)
pct = int((d.get("context_window") or {}).get("used_percentage") or 0)
color = "31" if pct >= 90 else "33" if pct >= 70 else "32" # red / yellow / green
bar = "▓" * round(pct / 10) + "░" * (10 - round(pct / 10))
print(f"\033[{color}mctx {bar} {pct}%\033[0m")
The 70% and 90% thresholds are our choice, not an Anthropic recommendation. Yellow is a reminder to finish the current step and put decisions somewhere durable (a note or CLAUDE.md) before Claude Code compacts. When you switch topics, /clear beats compacting.
Example 3: plan limits with time to reset
resets_at is Unix epoch seconds, so a countdown is one subtraction:
import time # d = json.load(sys.stdin), as in Example 2
def until(epoch):
s = int(epoch - time.time())
if s <= 0: return "now"
d, r = divmod(s, 86400); h, r = divmod(r, 3600)
return f"{d}d{h}h" if d else f"{h}h{r // 60:02d}m" if h else f"{r // 60}m"
limits = d.get("rate_limits") or {}
for key, name in (("five_hour", "5h"), ("seven_day", "7d")):
w = limits.get(key)
if w and w.get("used_percentage") is not None:
print(f"{name} {int(w['used_percentage'])}% ↺{until(w['resets_at'])}", end=" ")
This shows 5h 23% ↺1h33m 7d 91% ↺5d1h. Claude Code drops a window once its reset time passes, so the segment disappears on its own instead of showing a stale 100%.
Example 4: the prompt-cache countdown (the one most status lines skip)
Most of a long session's input is cache reads, which are cheap. When the cache goes cold, for example after you step away longer than its TTL, the next message re-sends the whole prefix at full price. prompt_cache tells you when that will happen:
# uses d and until() from the examples above
c = d.get("prompt_cache") or {}
now = time.time()
if c.get("warm") and c.get("expires_at") and c["expires_at"] > now:
print(f"cache {until(c['expires_at'])}")
elif c.get("warm") is False and c.get("recache_tokens_if_cold"):
print(f"cache cold (next msg re-caches ~{c['recache_tokens_if_cold'] // 1000}k)")
If you see cache 1m and still have a follow-up question, asking it now reuses the warm cache; after expiry the whole prefix is cached again at the higher write price. If you see cache cold (next msg re-caches ~152k) on a nearly full context, a /clear with a short summary may be cheaper than continuing. Our usage limits guide covers why cache misses cost so much.
Example 5: git branch without slowing everything down
The script runs after every assistant message, and git status in a big repo can take a while. A slow script blocks updates, and if a new update triggers while it's still running, Claude Code cancels it. Cache git output for a few seconds, keyed by session_id (stable for the session, unique across sessions; $$ or os.getpid() changes on every run and defeats the cache):
import os, subprocess, tempfile, time
cache = os.path.join(tempfile.gettempdir(), f"sl-git-{d.get('session_id', 'x')}")
if not os.path.exists(cache) or time.time() - os.path.getmtime(cache) > 5:
b = subprocess.run(["git", "-C", d["workspace"]["current_dir"], "branch", "--show-current"],
capture_output=True, text=True, timeout=1).stdout.strip()
open(cache, "w").write(b)
branch = open(cache).read()
The download's statusline.py also counts staged and modified files and shows the worktree name when you're in one.
Test it without opening Claude Code
echo '{"model":{"display_name":"Opus"},"workspace":{"current_dir":"/home/me/my-app"},"context_window":{"used_percentage":25},"session_id":"t1"}' | python3 ~/.claude/statusline.py
# [Opus] | my-app | ctx ▓▓▓░░░░░░░ 25%
The download's test.sh runs 35 checks: a full payload, the first message of a session (null context, no limits), an API-key user, a gateway spend limit with and without dollar fields, a cold cache, bad JSON, empty input and color thresholds. It prints 35 passed, 0 failed.
Status line blank? Check these
- Workspace trust. The status line runs under the same trust rule as hooks. Until you accept the trust dialog, it stays blank, and
claude --debuglogsStatus line command skipped: workspace trust not accepted. - Exit code and stdout. Output only appears after the script exits 0. A non-zero exit or no output leaves the line blank. Print to stdout, not stderr.
- Not executable. Run
chmod +xon the script, or call it through the interpreter as inpython3 ~/.claude/statusline.py. disableAllHooks. If it'strueoutside managed settings, only a managedstatusLineruns. If your org setsallowManagedHooksOnly, your own status line disappears without a warning.- Windows paths. With Git Bash, backslashes in the
commandget eaten. WriteC:/Users/you/.claude/statusline.pywith forward slashes. - Width.
tput colsdoesn't work inside the script. Claude Code setsCOLUMNSandLINESinstead. Keep the line short, because notifications share the row and can truncate it.
Honest limits
- The status line is a view, not a meter.
/usageis the source of truth for plan usage, andcost.total_cost_usdis an estimate. - Plan percentages appear only for Pro, Max and Ultra subscribers (or behind a gateway with a spend limit) and only after the first reply. Until then, our script shows line 1 only.
- Colors and the
▓░blocks depend on your terminal and font. SetNO_COLOR=1for plain text. - Community projects such as ccstatusline offer themes and many more widgets. Ours is deliberately small: one file, no dependencies, easy to read before you run it.
Related
To actually make your limits last longer, start with the free Claude Code usage limits guide. The paid Claude Code Usage Saver Kit adds lean settings, a test-output hook and small-model subagents. For guard scripts that run on the same events, see the Claude Code hooks examples, and for what Claude Code is allowed to do, the settings.json permissions guide.
Written with AI assistance and checked against the official documentation on the date above. Not affiliated with Anthropic.
AI Coding Agent Config Kit
Instruction-file templates for 12 stacks and 12 prompts that write and audit them. 34-page PDF, $14.
Not ready to buy? Start with the free PDF.
Get 10 of our most-used prompts as a free PDF from Gumroad. You will be asked for your email so Gumroad can deliver it.