A Claude Code statusline that shows what's left
The default statusline doesn’t show how much context is left, and that’s the only number I ever look down there for.
/statusline Set up my statusline as a bash script that reads the session JSON
from stdin and parses it with jq. Print one line, three segments joined by " | ".
Segment 1, model: .model.display_name, falling back to "?". No color.
Segment 2, context bar, omitted entirely when .context_window.used_percentage is
absent or empty. Round it with printf '%.0f'. Render ten characters: N filled "▓"
then (10 - N) empty "░", where N = pct * 10 / 100 in integer arithmetic. Color the
bar with raw ANSI and reset with \033[0m: green \033[32m below 50, yellow \033[33m
from 50 to 79, red \033[31m at 80 and above. Then a space and the integer
percentage plus "%". The percentage itself is not colored.
Segment 3, a "●" on the same thresholds, or blue \033[34m when the percentage is
absent; then the basename of .workspace.current_dir (falling back to .cwd, then
"?") in blue.
Plain bash and jq only, printf with raw escapes rather than tput, exactly one
line. Do not compute values you don't print.Green to yellow to red as the window fills:

That length is the point. It’s a spec, not a request. Every threshold, every escape code, every fallback spelled out, because whatever you leave open gets filled in with somebody else’s taste.
The last line does more work than it looks. My old script called whoami and hostname -s and printed neither of them, and it had the colour thresholds copy-pasted into two if-blocks. “Do not compute values you don’t print” is what turned a reproduction into a cleanup. Drop that sentence, ask for a byte-for-byte copy instead, and the warts come back with the output.
One caveat. That JSON shape is a property of the CLI version and nobody has promised it as an API. The // empty and // "?" fallbacks are what keep the line rendering the day a field gets renamed, instead of printing null at me.