I work on two Macs and I kept losing track of which one a Claude Code session was running on. The fix was small: put the hostname in the status line. Once I had the script open, I kept going. By the end of the hour the bottom line of every session looked like this:
m1 ~/work/acme/acme-shop (main*) | Fable 5.1 | ctx 88% (123k/1M) | $6.18/24.21zł (+$0.14/0.56zł) | 7d 52%
Everything comes from one JSON blob
Claude Code runs the status line command after every update and pipes a JSON document into it. The script I had only read the directory, the model name and the context percentage. I dumped the whole document to a file once to see what else is in there, and it is a lot more than the docs made me expect.
| Field | What it holds | Where it ends up |
|---|---|---|
workspace.current_dir | the folder the session works in | ~/work/acme/acme-shop |
model.display_name | the model | Fable 5.1 |
context_window.remaining_percentage | free context, in percent | ctx 88% |
context_window.current_usage | input, cache write and cache read tokens | 123k |
context_window.context_window_size | the window size for this model and plan | 1M |
cost.total_cost_usd | running cost of the session at API prices | $6.18 |
rate_limits.seven_day.used_percentage | how much of the weekly plan limit is used | 7d 52% |
prompt_id | a new id for every message I send | the +$0.14 trick below |
The two surprises were the window size and the cost. I had assumed 200k tokens; the field said 1,000,000. And the cost is already there, computed by Claude Code, so nobody has to multiply tokens by a price list.
The percentage is in tokens, not bytes. A token is about four characters of English, so a 300-line source file costs 3,000 to 5,000 tokens and a long git log can cost more than the whole conversation so far.
Cost per request from a running total
Claude Code only sends the total for the session. I wanted to see what the message I just sent is costing while it runs. The prompt_id field made that a ten-line addition: the script keeps a small state file per session, and when it sees a new prompt id it saves the current total as the base. The bracket shows total minus base, and it grows live while the agent works.
flowchart LR
CC["Claude Code<br/>JSON after every update"] --> SH["statusline-command.sh"]
SH --> ST["state file<br/>prompt id, base cost"]
ST --> SH
SH --> NBP["NBP API<br/>USD/PLN mid rate,<br/>cached 12 h"]
SH --> LINE["one coloured line"]
session_id=$(echo "$input" | jq -r '.session_id // "default"')
prompt_id=$(echo "$input" | jq -r '.prompt_id // empty')
state="${TMPDIR:-/tmp}/claude-statusline-$session_id"
[ -f "$state" ] && IFS=$'\t' read -r saved_prompt saved_base saved_total < "$state"
if [ "$saved_prompt" = "$prompt_id" ]; then
base=$saved_base
else
base=${saved_total:-$cost} # new prompt: what was spent so far belongs to earlier requests
fi
printf '%s\t%s\t%s\n' "$prompt_id" "$base" "$cost" > "$state"
delta=$(echo "$cost - $base" | bc -l)
The PLN part is the same idea with a cache. The script asks the NBP API for the USD mid rate, stores it in ~/.cache, and refreshes it in the background when the file is older than twelve hours. The status line never waits on the network; the first run after an expiry shows USD only for a second, then both currencies.
Colour carries most of the information. The context percentage is green above 50, yellow above 20, red below. The weekly limit goes yellow at 70 and red at 90. The cost is always red, which is the point. The whole line renders in about 0.15 seconds, which matters because it runs after every update.
What it took
Most of the hour went into one thing I should have done first: looking at the real input instead of guessing field names from memory. One echo "$input" > file line answered every question I had, including the one about the window size, and it also showed me the cost and rate limit fields I did not know existed. The rest was bash, jq and bc. Next time a tool hands me a JSON document, I dump it before I write a single line against it.

Related notes
My Claude Code sessions now say which project they are
Four Claude Code sessions, one Ping sound, no idea which one needed me. A small hook script now speaks a short word per project, queues the voices and has a mute switch for meetings.
Sending Ableton locators from Max for Live to a cloud API
How I sent song sections from a Max for Live device to a small FastAPI service on Cloud Run, stored them in PostgreSQL and showed them in the browser.



