Skip to content

About

My Claude Code statusline script

Resources

Stars

1 star

Watchers

0 watching

Forks

Latest commit

 

History

4 Commits

Folders and files

Repository files navigation

Claude Code statusline

A two-line statusline for Claude Code. Runs on macOS, Linux and Windows (Git Bash). starship is optional.

Two-line statusline: model and reasoning effort, a context-window gauge, the session cost, then the 5-hour, 7-day and per-model weekly usage meters with their reset times; the second line shows repository, worktree and branch with file counts

Shown with --spend, which adds the 💳 segment — it is off by default.

Segment Meaning
🤖 Model, and reasoning effort when the model supports it
🧠 Context window used, 10-cell gauge — green → yellow at 60% → red at 80%
💰 Session cost — always yellow, since on a subscription it is a hypothetical. Hide with --no-cost
⏱️ Usage meters: 5-hour, 7-day, and one per model-scoped weekly window. → marks the reset time; windows that reset together share one clause
📁 Repository name (the main checkout, even from a worktree)
🌳 Worktree name, or no worktree
💳 Extra-usage credits spent against your monthly limit — opt-in, see below
🌿 Branch, with +staged and ~modified file counts

About the 💰 figure

It is an estimate, not a bill. Claude Code derives it from the session's token usage at API list prices (or your organisation's contracted rates when modelPricing is set). On a Pro/Max/Team subscription you are not billed per token, so the number is hypothetical: what this session would have cost on API billing.

That makes it genuinely useful for sizing up what a workload would cost through the API, and meaningless as a measure of money actually spent. The ⏱️ meters are the ones tracking real subscription usage.

To hide it, pass --no-cost (or set STATUSLINE_NO_COST=1). That works on both trio paths: the built-in renderer omits the segment, and on the starship path .cost is removed from the payload starship sees, which makes claude_cost omit itself — so you do not have to edit your starship config to match.

Install

Clone it anywhere. The script never references its own path, so its location does not matter:

git clone https://github.com/cheets/claude-code-statusline.git ~/projects/claude-code-statusline

Then merge the statusLine key into ~/.claude/settings.json — do not replace the file, you almost certainly have other settings in it:

{
  "statusLine": {
    "type": "command",
    "command": "sh ~/projects/claude-code-statusline/statusline.sh",
    "padding": 0
  }
}

Smoke-test it without restarting Claude Code:

printf '%s' '{"model":{"display_name":"Opus 5"},"workspace":{"current_dir":"."},"context_window":{"used_percentage":25},"cost":{"total_cost_usd":1.5}}' | sh statusline.sh

Requirements

  • jq — required (brew install jq / apt install jq / winget install jqlang.jq). Without it the statusline prints a one-line install hint instead of rendering.
  • git, curl, starship — all optional. Each segment simply disappears when its tool is missing.
  • Claude Code 2.1.98 or newer for every segment. The newest payload field it reads is workspace.git_worktree (added in 2.1.98); on older versions the 🌳 segment only fills in for --worktree sessions. Nothing breaks either way — every field is read with a fallback.

Optional: render the trio with starship

If you already use starship, merge starship.toml.example into ~/.config/starship.toml and starship will render the model/context/cost trio instead. The output is byte-identical either way, so this is only worth doing if you want prompt styling to live in one place.

The profile must be named claude-code. The script checks starship print-config for that exact name and uses its own renderer when it is absent — starship with no matching profile falls back to its own default module formats, which do not match this layout.

$effort is rendered natively only by starship builds carrying starship#7614, unreleased as of starship 1.26.0. Version numbers cannot detect this (starship's master still reports the last release), so the script probes the binary once and caches the verdict against the mtimes of starship and its config. On an older build it folds effort into the model name instead; on a newer one it lets starship do it. Never both.

The per-model weekly meters

Claude Code's statusline JSON exposes only rate_limits.five_hour, rate_limits.seven_day and rate_limits.spend_limit (verified against Claude Code 2.1.263 — the payload builder allowlists exactly those three). Model-scoped weekly windows — the Fable meter above — exist in the CLI but are surfaced only through /usage, so this script reads them from the same OAuth usage endpoint /usage uses.

The token is looked up in the order Claude Code itself prefers:

  1. $CLAUDE_CODE_OAUTH_TOKEN
  2. macOS Keychain (Claude Code-credentials)
  3. ~/.claude/.credentials.json — the plaintext store used on Linux and Windows

Responses are cached for 60 seconds, and a failed fetch keeps the stale cache rather than blanking the meter, which matters when offline. Nothing is logged or sent anywhere else.

This is the only part that reads a credential or touches the network. To turn it off, set STATUSLINE_NO_MODEL_METERS=1. On API-key, Bedrock or Vertex sessions there are no subscription limits to show, so the ⏱️ segment disappears on its own.

Drop this section whenever the statusline JSON grows a model-scoped field — at that point the fetch becomes dead weight.

Why the weekly meters share one reset clause

The plan's weekly window and every model-scoped weekly window reset at the same instant, so repeating → Thu 11:00 for each of them wasted about 17 columns on a line that is already long. They render as one block:

7d ░░░░░░░░░░ 8% · Fable ░░░░░░░░░░ 7% → Thu 11:00

The shared clause is coloured by the worst percentage in the group, so a model window near its limit still reads as urgent even when the all-models window is comfortable.

The two figures come from different sources — rate_limits.seven_day in the statusline payload versus the usage endpoint — so they could in principle drift apart. A window whose reset does not match the 7d one is emitted as its own segment with its own clause, which is also what happens when the payload carries no seven_day at all.

Extra-usage credits (opt-in)

Add --spend to the statusline command to show a 💳 segment with what you have spent in extra-usage credits against your monthly limit:

"command": "sh ~/projects/claude-code-statusline/statusline.sh --spend"
⏱️ 5h ░░░░░░░░░░ 6% → 16:45 | 7d ░░░░░░░░░░ 8% · Fable ░░░░░░░░░░ 7% → Thu 11:00 | 💳 €21.27/50.00 43%

It colours on the same thresholds as the other meters (yellow at 70%, red at 90%) and drops the ratio when no limit is set. It costs no extra request — the figures ride along in the payload already fetched for the per-model meters.

Why it is off by default: this is personal billing information, and a statusline is visible in every screen-share and screenshot.

This exists because the number is otherwise hard for a member to see. An organisation admin sees per-person extra usage in the admin panel, but there is no documented API for it: the Usage and Cost API reports API token spend, and the Claude Code Analytics API reports per-user estimated cost computed from tokens — neither is the credits actually drawn against an extra-usage limit. The /api/oauth/usage endpoint used here does carry it, per user, for that user.

Same caveat as the per-model meters, and it applies double to money: this is an internal endpoint, not a published API. It can change shape without notice. Fine for a statusline; do not build billing reconciliation on it.

The minor-units trap

Both shapes report minor units — cents, not euros. extra_usage.used_credits is the one that catches people: it is named like a credit count and typed as a float, but 2127.0 with decimal_places: 2 means 21.27, not 2127. The newer spend object states it plainly as amount_minor with an exponent. minor_fmt() divides by 10^exponent; both code paths were tested against the same figures and render identically.

Options

Pass them on the statusline command; statusline.sh --help lists them.

Flag Effect
--spend Add the 💳 extra-usage credit segment (off by default)
--no-model-meters Skip the per-model weekly meters. No credential read, no network call
--no-cost Hide the 💰 session cost (shown by default)
--no-spend / --model-meters / --cost Negate the matching env var below

Each also reads an environment variable — STATUSLINE_SHOW_SPEND, STATUSLINE_NO_MODEL_METERS and STATUSLINE_NO_COST — which is convenient for a one-off STATUSLINE_SHOW_SPEND=1 claude. Flags win when both are present, in both directions: --cost overrides STATUSLINE_NO_COST=1.

Prefer the flags for anything permanent. Claude Code's statusLine setting has a closed schema (type, command, padding, refreshInterval, hideVimModeIndicator), so there is no custom-option slot to put this in, and an unrecognised key there trips Claude Code's settings validation. That leaves the command line, which is where the flags live. settings.json does also support a top-level env block, but that exports the variable to every subprocess Claude Code spawns — hooks, MCP servers, every Bash call — where a flag stays scoped to this script and is visible right next to the command it modifies.

These two are read from the environment only, since they are not this script's to own:

Variable Effect
STARSHIP_CONFIG Honoured when locating the starship config for the trio probe
CLAUDE_CONFIG_DIR Honoured when locating cache/ and .credentials.json

Notes for hacking on it

  • Everything is one jq pass. Fields are joined on US (0x1f) rather than a tab, because tab is IFS whitespace and read would collapse an empty field and shift every value after it.
  • Keep emoji inside printf format strings. "$var⏱️" is a trap: sh on macOS is bash 3.2, which absorbs the emoji's UTF-8 lead byte into the parameter name and expands the whole thing to nothing.
  • Every awk call runs under LC_ALL=C. awk's printf honours LC_NUMERIC, so in a comma-decimal locale (fi_FI, de_DE, fr_FR, …) the cost would render as $1,23 while starship, formatting in Rust, keeps $1.23. awk's %.0f also rounds half-to-even (2.5 → 2) where starship rounds half-up (2.5 → 3%), so rounding is done explicitly.
  • Resolve STARSHIP_CONFIG once, then export it. An empty value means two different things: ${STARSHIP_CONFIG:-default} resolves to the real config, while starship itself treats the empty string as "no config" and falls back to its own default module formats. Left unreconciled, the cached trio verdict describes a config starship never read, and the rendered trio silently loses its gauge and separators.
  • Snap every reset epoch to the nearest minute. The two reset sources describe the same instant in different shapes: the statusline payload carries an integer epoch floored to the second, while the usage endpoint returns that same reset as ...T07:59:59.6xx or ...T08:00:00.0xx. Since the meters can only share a reset clause if they agree on the minute, normalising just one side is worse than normalising neither — it made the weekly block split into → Thu 10:59 | → Thu 11:00, one clause per source, and left every payload-sourced reset displaying a minute early. minute_epoch() snaps both sources, so a window ending at :59:59 reads as the reset it actually is.
  • stat and date differ between BSD and GNU. Both are probed once at startup. The stat -c probe comes first on purpose: GNU's -f means --file-system and prints ? with exit 0 rather than failing, which would quietly poison the cache arithmetic.
  • git rev-parse --path-format=absolute --git-common-dir resolves the main checkout so 📁 names the repository while 🌳 names the worktree. Without --path-format (git < 2.31) git returns a path relative to the cwd — .git or ../../.git — and 📁 would show whatever subdirectory you happened to be in. Older git falls back to --show-toplevel.

Credits

The layout — two lines, the emoji segments and the order they appear in — comes from Daniel Mackay's custom statusline (danielmackay/claude-code-statusline), which is where this started.

The script itself has since been rewritten: single-pass jq parsing, the optional starship path, BSD/GNU portability probes, the rate-limit and per-model weekly meters, and the repo/worktree resolution are all new. The git counts also changed meaning — upstream shows lines added and removed, this shows staged and modified file counts.

License

MIT © Henri Koskenranta

About

My Claude Code statusline script

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages