A small Rust binary (ccline) that renders a customizable statusline for Claude Code. Reads the session JSON from stdin, formats it using a Starship-style format string, and writes the result to stdout.
Basic template (single line β the baked-in default):
π€ Opus 5 (1M context) | π° $6.62 | π 17% [4h 21m] | π
22% [Tue 7:00PM] | π§ ββββββββββ 13% (130k/1000k) | πΏ main | π my-project
Extended template (two lines):
π€ Opus 5 (1M context) | π° $6.62 | β±οΈ 26m 51s | π 17% [4h 21m] | π
22% [Tue 7:00PM] | π§ Context: 13%
π Claude Code v2.1.276 | β¬οΈ Tokens In: 128,000 | β¬οΈ Tokens Out: 9,400 | β»οΈ Cache: 85% (118,000) | πΏ main | π my-project
- macOS, Linux, or Windows
- Rust stable (for building)
- Claude Code v2.x or later
Build dependencies: serde, serde_json, toml, anyhow, jiff (cross-platform timezone-aware date formatting), and dirs (cross-platform home directory resolution). No runtime dependencies β the binary reads .git/HEAD directly and formats dates in-process, so it does not shell out to git or date.
Clone and build:
git clone https://github.com/skydiver/claude-code-statusline.git
cd claude-code-statusline
make distmake dist runs cargo build --release and stages the binary at dist/ccline (~1.2 MB). Running make on its own lists the available targets instead of building. If you prefer Cargo directly, cargo build --release produces the same binary at target/release/ccline.
Add the binary path to ~/.claude/settings.json:
{
"statusLine": {
"type": "command",
"command": "/absolute/path/to/dist/ccline",
"padding": 0
}
}Restart Claude Code. No environment variable is needed to pick a template β use the config file instead.
ccline reads an optional TOML file from (in order of precedence):
$CCLINE_CONFIG, if set to a non-empty path. Lets you pointcclineat any file β handy for switching between layouts without moving files around.$XDG_CONFIG_HOME/claude-code-statusline/config.toml, ifXDG_CONFIG_HOMEis set.$HOME/.config/claude-code-statusline/config.tomlotherwise.
If the file is missing the baked-in default (equivalent to the basic template) is used. If the file is present but malformed, ccline logs the parse error to stderr and still renders the default line β the statusline must never break Claude Code. When CCLINE_CONFIG points at a missing or unreadable file, the read error is also logged to stderr so a typo'd path doesn't fail silently.
CCLINE_CONFIG is handy for keeping multiple layouts side-by-side (e.g. one for work, one for personal) and pointing ccline at whichever one you want via your shell environment or launcher config.
Set CCLINE_INPUT_DUMP to a writable path and ccline will save a pretty-printed JSON snapshot of the stdin payload to that path on every render. Useful when another tool (a menubar app, a dashboard, a watcher script) wants the current Claude Code session state without re-implementing a statusline reader.
export CCLINE_INPUT_DUMP="$HOME/.cache/ccline/input.json"Writes are atomic β the JSON goes to <path>.tmp first and is then renamed onto the target. A reader either sees the previous snapshot or the new one, never a half-written file. The dump preserves every field Claude Code sent (including ones ccline itself doesn't render), so it stays forward-compatible with new payload fields. An empty value is treated as unset; a write failure is logged to stderr but never breaks the statusline.
format = "π€ $model | π° $cost | π§ $context_bar ( | πΏ $git_branch )"The (...) wrapping around | πΏ $git_branch is a conditional group: if any $module inside renders empty, the entire group disappears β separator, emoji, and all. Outside a git repo you get just π€ $model | π° $cost | π§ $context_bar with no awkward trailing | πΏ. See Conditional Groups below.
format = """
π€ $model | π° $cost | β±οΈ $duration
π Claude Code $version | πΏ $git_branch\
"""The trailing \ before the closing """ strips the final newline so you don't get an empty line under the statusline. Two ready-to-copy presets live in examples/basic.toml and examples/extended.toml.
Each placeholder is a Starship-style $module_name reference. Everything else in the format string is literal text (including emojis, separators, and newlines).
| Placeholder | Description | Example |
|---|---|---|
$model |
Current model display name | Opus 5 (1M context) |
$cost |
Session cost in USD | $6.62 |
$duration |
Session duration | 26m 51s |
$session |
5-hour utilization, colored by usage (N/A if missing) |
17% |
$session_reset |
Countdown to the 5-hour reset | 4h 21m |
$weekly |
7-day utilization, colored by pace (N/A if missing) |
22% |
$weekly_reset |
Weekly reset weekday + time | Tue 7:00PM |
$context |
Context window usage percentage | 13% |
$context_bar |
10-cell β/β bar + percent + used_k/total_k tokens | ββββββββββ 13% (130k/1000k) |
$tokens_in |
Total input tokens (comma-separated) | 128,000 |
$tokens_out |
Total output tokens (comma-separated) | 9,400 |
$cache |
Cache hit rate + cache-read count | 85% (118,000) |
$version |
Claude Code version | v2.1.276 |
$project |
Project directory basename | my-project |
$git_branch |
Raw branch name (empty outside a repo) | main |
Four placeholders wrap themselves in ANSI color when they cross a threshold. Everything else renders plain, so the format string stays in charge of the rest of the styling.
$context and $context_bar color on absolute context pressure:
| Context used | Color |
|---|---|
| 0β64% | default |
| 65β74% | yellow |
| 75%+ | red |
$session also colors on absolute usage, on its own thresholds:
| 5-hour used | Color |
|---|---|
| 0β64% | default |
| 65β84% | yellow |
| 85%+ | red |
It is deliberately not pace-based. A five-hour window is meant to be spent, so burning it near-linearly is ordinary work, not a warning β pace coloring would sit yellow through most of any focused session and train you to ignore it. Only proximity to the cutoff is worth flagging, and $session_reset already tells you when that cutoff lands.
$weekly colors on burn pace instead, because a raw weekly percentage says nothing on its own β 40% is comfortable on day 5 and alarming on day 1. Spending the full allowance evenly across the seven days works out to 14.29%/day, so the budget at any moment is simply the share of the window already elapsed:
budget = elapsed_fraction_of_the_7_day_window Γ 100
pace = weekly_used_percentage Γ· budget
| Pace | Color | Meaning |
|---|---|---|
| below 1.0x | default | on track to reach the reset with room to spare |
| 1.0x β 1.49x | yellow | on track to run out before the reset |
| 1.5x and above | red | on track to run out well before the reset |
Two guards keep that ratio honest:
- Below 5% used, never colored. Minutes into a fresh window the elapsed fraction is near zero, so any usage at all computes to a wild pace. That's arithmetic, not a warning.
- At 90% used, always red. Late in the window a near-exhausted allowance can still be technically "under budget" β 92% on day 6.5 is a 0.99x pace and one session from the wall. This band needs no reset timestamp, so it warns even on an older payload that omits one.
When resets_at is missing or the window start lands in the future (clock skew), the pace can't be computed and $weekly renders plain.
Anything you wrap in (...) is a conditional group: the group renders only if every $module inside it produces a non-empty value. If any one module is missing, the whole group β including its literal separators, emoji, and spaces β disappears.
format = "π§ $context_bar ( | πΏ $git_branch ) | π $project"- Inside a git repo β
π§ ββββββββββ 17% | πΏ master | π my-project - Outside a git repo β
π§ ββββββββββ 17% | π my-project(no dangling| πΏ)
Whitespace directly adjacent to ( or ) is treated as cosmetic padding β a space before ( is absorbed into the group (so it disappears along with the group when suppressed) and any whitespace immediately inside (...) is stripped. That means all three of these parse to the same thing and render identically:
format = "$context_bar ( | πΏ $git_branch )" # symmetric, recommended
format = "$context_bar (| πΏ $git_branch)" # tight
format = "$context_bar( | πΏ $git_branch)" # legacy, no outer spaceGroups can nest. An inner group's emptiness does not bubble up to its parent β each group decides independently. Unmatched ( extends silently to end-of-string; a stray ) is treated as literal text.
- Reads the Claude Code session JSON from stdin into a typed
Inputstruct (all fields optional for forward compat). - Loads the TOML config file, falling back to the baked-in default.
- Parses the
formatstring into a sequence of literal and$moduletokens. - Dispatches each
$moduleto its renderer and writes the concatenated result to stdout.
Parse errors for either the JSON or the config file are logged to stderr. stdout always receives a valid line.
The Makefile wraps the common Cargo workflows. Running make with no target lists them all:
ccline β available targets:
all Alias for `make dist`
clean Remove build artifacts (cargo clean plus dist/)
dev Run via cargo (prints a usage banner without piped stdin)
dist Build the release binary and copy it into dist/
help List the available targets
preview Render the statusline across a scenario matrix, in real color
test Run the full unit suite
That listing is generated from the ## comments on the targets themselves, so it can't drift out of sync.
| Target | What it does |
|---|---|
make |
Alias for make help β lists the targets without building |
make all |
Alias for make dist |
make dist |
cargo build --release, copy the binary into dist/ccline, and print its size |
make dev |
cargo run β running without piped stdin prints a usage banner (see below) |
make test |
cargo test β runs the full unit suite |
make preview |
Build, then render a scenario matrix in real color (see below) |
make clean |
cargo clean plus rm -rf dist |
The unit suite asserts escape sequences as strings, which proves the color bands are correct but never shows you what they look like. make preview does the opposite β it feeds synthetic payloads to the built binary and prints the real output, grouped by scenario:
WEEKLY PACE (budget = elapsed share of the 7-day window)
day 1.0 10% 0.70x π
10% [Thu 9:25AM]
day 1.0 15% 1.05x π
15% [Thu 9:25AM] β yellow
day 1.0 22% 1.54x π
22% [Thu 9:25AM] β red
day 6.5 88% 0.95x π
88% [Fri 9:25PM]
It covers the weekly pace bands, both guards, every degradation path, the context pressure thresholds, and empty/partial payloads. The β yellow / β red annotations are read back out of the rendered bytes rather than hardcoded, so moving a threshold moves the annotation with it. Each section pins its own format, so your personal config never skews the output.
Scenario values sit just inside their bands rather than exactly on 1.00x / 1.50x: the binary reads its own clock a few milliseconds after the script does, which is enough to tip an exact boundary. The boundaries themselves are pinned by unit tests, which inject now.
ccline expects the Claude Code session JSON on stdin. If you run it in an interactive terminal (e.g. make dev or ./dist/ccline), it detects the TTY, prints a short usage banner, and exits cleanly instead of blocking on stdin forever.
To smoke-test the render pipeline locally, pipe the bundled fixture:
cat tests/fixtures/sample_input.json | ./dist/cclineThe fixture carries fixed timestamps, so $session_reset counts down against your current clock and reads 0h 0m once that moment has passed. Everything else renders exactly as shown in Output Examples, give or take your own git branch.
MIT