All Agent Engineering

Spec file

Claude Code status line: display context percentage from stdin JSON

Treat the status-line script as a data interface and handle missing values before configuration; offline checks are not a product run.

AI Nav CityWritten / Updated

The status line receives session JSON and displays a script stdout. Write an original Node.js script showing model name and context percentage, then inspect missing-value handling using synthetic input. You need Node.js and Claude Code with statusLine support. No real status line was configured.

Verified
· Not tested by us
Applies to
  • Claude Code Applies to local Claude Code; the page gives no unified version floor. Use the 2026-11-04 check and actual interface.[1]

File locations

PathScopeHow it is read
~/.claude/settings.json → statusLineStatus-line command configuration; reference your own local script path.Claude Code sends session JSON to command stdin and displays stdout.[1]

When to use

  • You need model and context information and can review the script.[1]

When not to use

  • You need the bar to prove task success, settled billing or exact remaining quota.[1]

Input and display are separate interfaces

The docs describe a statusLine command receiving stdin JSON and rendering stdout, configured with type: command and command. This exercise reads only model.display_name and context_window.used_percentage, without credentials or network access. Missing values display unknown, avoiding an unverified zero usage claim.[1]

Original script and local calculation

Save the script below as an .mjs file in your own directory. Synthetic display_name: demo-model and used_percentage: 25 should produce demo-model | context 25%; missing fields produce unknown. The script does not execute input text. Still inspect the configured command and every dependency before real use.[1]

Example: original sample; product not executed
import fs from "node:fs";
const data = JSON.parse(fs.readFileSync(0, "utf8"));
const name = data.model?.display_name ?? "unknown";
const used = data.context_window?.used_percentage;
const pct = typeof used === "number" ? `${used}%` : "unknown";
console.log(`${name} | context ${pct}`);

[1]

Inspect commands and dependencies before configuration

Confirm Node.js is available and the script path is correct before setting statusLine.command. The docs also offer /statusline to generate a script and modify settings, which involves file edits and model usage. This page uses a reviewable manual sample and explains placement only; it did not run generation or write settings.[1]

Verify display and stop conditions

Offline calculation checked complete input, missing input and script syntax. After real enablement, inspect the rendered bar and errors separately. Disable the command for diagnosis when parsing, paths or values are wrong. A session context percentage does not directly establish subscription quota or settled cost. No Claude Code status line or model call was run here.[1]

Sources

All links are official pages; verification dates are listed per source, and links point to the version checked.

  1. Anthropic · Customize your status line

Found an error? Tell us →