# Claude Code Status Line: Context, Cost and Cache Live

> A status line is any shell script fed session JSON on stdin. Here are the fields worth rendering, the width trap, and why a slow script silently shows nothing.

URL: https://www.matthewswong.com/en/blog/claude-code-statusline-customization/

- Author: Matthews Wong (https://www.matthewswong.com/en/about/)
- Published: 2026-08-27
- Updated: 2026-08-27
- Category: Software Development

> **Key takeaway:** A Claude Code status line is any shell script you configure. Claude Code runs it with JSON session data on stdin and displays whatever it prints to stdout. It runs at session start and on message, compaction, permission-mode and vim-mode changes, debounced at 300 milliseconds, and a run still in flight when a new trigger arrives is cancelled rather than queued.

My first status line worked perfectly when I tested it by hand and showed nothing at all inside Claude Code. The script was fine. It shelled out to a git command that took about half a second, and every new assistant message cancelled the run before it finished — so the bar was permanently one render behind an update that never completed.

The status line is one of the cheapest customisations available and one of the easiest to get subtly wrong, because it fails silently in three different ways. This post covers the update model and the cancellation rule, the JSON fields actually worth rendering, the terminal-width trap, and the two organisation settings that can make a working status line vanish without a message.

## The update model, and the rule that bit me

There is nothing to install. You point a settings key at a command, and Claude Code runs it with JSON on standard input. It runs locally and consumes no API tokens, and it hides temporarily during autocomplete, the help menu and permission prompts.

The triggers are event-driven, which means they can go quiet exactly when you most want an update — while a coordinator waits on background subagents, for instance, nothing in that list fires. That is what the refresh interval is for: it re-runs the command on a fixed timer so time-based or externally-sourced segments stay current during idle periods.

## The fields worth rendering

The full field list is long and most of it is padding. These are the ones that answer a question you would otherwise have to interrupt yourself to ask.

> The context percentage is calculated from input tokens only — input plus cache creation plus cache read — and deliberately excludes output tokens. If you compute a percentage yourself from the usage object and include output tokens, your number will not match the one Claude Code shows elsewhere, and you will spend an afternoon deciding which is wrong. Use the same input-only formula.

## The width trap

This one costs everybody an hour once. Claude Code captures your script's output rather than attaching it to the terminal, so the usual ways of asking how wide the terminal is all fail from inside the script — the column-query command and every language-level width detection see no terminal. Claude Code sets two environment variables before each run, and reading those is the only reliable way to size your output.

> Test the script by piping mock JSON into it rather than by restarting Claude Code. A single echo of a minimal object exercises everything except the trigger logic, and it turns a five-minute edit-and-relaunch cycle into a one-second one. It is also the fastest way to find out that your JSON parsing chokes on a null field, which it will, because the usage object is null before the first API call and again right after compaction.

## Why a status line does not appear

Four causes, in the order they are worth checking:

- The script is not executable, or it writes to standard error rather than standard output. Both produce an empty bar with no complaint.
- The script is slow. A run still in flight when a new trigger arrives is cancelled, so anything that takes longer than the gap between messages may never finish. Cache expensive calls such as repository status rather than running them every tick.
- On Windows with Git Bash installed, backslashes in the command path get consumed as escape characters before the script runs. Use forward slashes.
- Run with the debug flag, which logs the exit code and standard error from the first invocation in a session — the single most useful diagnostic here.

## The organisation settings that make it disappear

Two settings can remove your status line without any message at all, and both are worth knowing before you conclude your script is broken. If the disable-all-hooks setting is true outside managed settings, Claude Code runs only a status line that came from managed settings — and with none there, you get no status line.

The other is the managed-hooks-only setting. When an organisation sets it, your custom status line disappears silently and the only status line you can have is one your administrator provides in managed settings. If yours vanished after a policy rollout rather than after an edit, that is almost certainly why, and it is a question for whoever owns your managed settings rather than a bug.

> There is a separate setting for subagent rows, which replaces the default name, description and token count with your own formatting. The command receives every visible subagent row as one JSON object and you write one line of JSON per row you want to override — including a per-task resolved model, its context window size and its effort level, so you can render a real per-agent context percentage in the agent panel.

## What to actually put on the bar

The temptation is to render everything available, and the result is a wall of numbers nobody reads. The useful test is whether a value would change what you do in the next minute.

| Segment | The decision it informs |
| --- | --- |
| Context percentage | Whether to compact now, at a task boundary, or let it fire mid-task later |
| Cache read against cache creation | Whether something is invalidating your prefix every turn |
| Model and effort | Whether you are still on the model you meant to be on an hour ago |
| Branch and worktree | Which of your parallel sessions this terminal actually is |

## Colours, links and multiple lines

Each print statement becomes a separate row, so a two-line bar needs no special configuration. Standard ANSI escape codes work wherever the terminal supports them, and the terminal-hyperlink escape sequence makes text clickable in terminals that support it — which is how you get a ticket ID in the bar that opens the ticket.

Worth knowing before you invest in a script: configuring a custom status line stops Claude Code showing most of the footer's keyboard hints, including the interrupt hint and the shortcuts fallback. If all you want is clickable badges when an identifier appears in the conversation, there is a separate settings key for that which costs you none of the hints.

Build the smallest bar that answers a question you keep interrupting yourself to ask, then stop. Mine is four segments wide and the one that has actually changed my behaviour is the cache ratio, because it turns an invisible cost into a number that moves while I watch. Test with piped JSON, cache anything slow, and read the width from the environment rather than asking the terminal — that is most of the way to a status line that keeps working.

## Sources & further reading

- Claude Code docs — Customize your status line
- Claude Code docs — Settings reference (statusLine, subagentStatusLine)
- Claude Code docs — Check cache performance
- Claude Code docs — Hooks and disableAllHooks
- Claude Code docs — Create custom subagents
- Claude Code docs — Manage costs
- Claude Code docs — Explore the context window
- GitHub — ccstatusline, a pre-built status line configuration

## Source links

- https://code.claude.com/docs/en/statusline
- https://code.claude.com/docs/en/settings-reference
- https://code.claude.com/docs/en/prompt-caching
- https://code.claude.com/docs/en/hooks
- https://code.claude.com/docs/en/sub-agents
- https://code.claude.com/docs/en/costs
- https://code.claude.com/docs/en/context-window
- https://github.com/sirmalloc/ccstatusline

## FAQ

### How do I add a status line to Claude Code?

Point the statusLine setting at a command in your settings file. Claude Code runs that script with JSON session data on stdin and displays whatever it prints to stdout. The script runs locally and consumes no API tokens. Make sure it is executable and writes to stdout rather than stderr.

### Why does my Claude Code status line show nothing?

Four common causes: the script is not executable, it writes to stderr instead of stdout, it is too slow — a run still in flight when a new trigger arrives is cancelled rather than queued — or on Windows with Git Bash, backslashes in the command path are consumed as escape characters. Run claude --debug to log the exit code and stderr.

### How do I get the terminal width inside a status line script?

Read the COLUMNS and LINES environment variables, which Claude Code sets before each run. Claude Code captures your script's output rather than attaching it to the terminal, so tput cols and language-level width detection cannot see the terminal size from inside the script.

### How is the Claude Code context percentage calculated?

From input tokens only: input_tokens plus cache_creation_input_tokens plus cache_read_input_tokens. It deliberately excludes output tokens. If you compute a percentage yourself from the current_usage object, use the same input-only formula or your number will not match the one Claude Code shows elsewhere.

### Can an organisation disable my custom Claude Code status line?

Yes, and silently. If disableAllHooks is true outside managed settings, only a statusLine from managed settings runs. If your organisation sets allowManagedHooksOnly, your custom status line disappears without warning and you can only get one from managed settings. Ask whoever owns your managed settings.

---

- HTML version: https://www.matthewswong.com/en/blog/claude-code-statusline-customization/
- Bahasa Indonesia: https://www.matthewswong.com/id/blog/claude-code-statusline-customization/
- Site index for agents: https://www.matthewswong.com/llms.txt
- Sitemap: https://www.matthewswong.com/sitemap.xml
- API description (OpenAPI): https://www.matthewswong.com/openapi.json
