Telling Technology · Learning in public
All episodes
EP.10 — FUEL GAUGE
A Claude Code workflow, on screen

My terminal now shows how much brain my AI has left

Long sessions die silently. Context fills up, the model quietly starts forgetting — and you don't notice until it loses the thread. So I had Claude Code build its own fuel gauge: model, effort, and two live bars, on one row.

Custom Claude Code status line: Opus 4.8 [high], a context fuel bar, a session-token fuel bar, and an auto-mode line below it
⌁ live status line · one row · reads Claude Code's statusline JSON
It starts at 0% — then watch the bars climb
01 The silent death

You never see the tank emptying

If you run Claude Code all day, you know the moment: an hour deep into a build, the model starts forgetting things it said ten minutes ago. The context window filled up and nothing warned you. The default status line tells you almost nothing — so you fly blind until the AI loses the plot, mid-task, with no fuel light on the dash.

claude code — desktop
> wait — why did you forget the function we wrote earlier?
You're right, I lost it. The earlier context dropped out of my window. I should have flagged that I was running low — but nothing on screen showed it. 0 warning · 0 gauge
The default Claude Code status line — a single plain path string with no context or token information
before
the default strip — no fuel light anywhere
02 The build

One prompt, one cockpit strip

Claude Code hands a small statusline JSON to a script on every refresh — model, effort, context used, session tokens, last prompt. I asked the AI to read that and render a cockpit row: Opus 4.8 [high] [███░░░]13% contxt [██░░░░]13% sess.token. Two ASCII fuel bars. It wrote, tested, and installed the whole thing in one pass.

claude code — desktop
> build me a status line that reads your statusline JSON and shows model, effort, and two fuel bars — context % and session tokens — on one row
Done. Wrote ~/.claude/statusline.sh, wired it into settings.json, rendered two bars from context_used_pct and session tokens. Reload — your dash is live.
Zoom on the two fuel bars mid-session — context bar partly filled, session-token bar filling behind it
two bars
context fuel · session-token fuel — both live
03 How it works

It's just JSON in, one line out

No magic. Claude Code pipes a tiny JSON object to your script's stdin; whatever the script prints becomes the status line. Read the fields, do the math, draw the bars. Here's the shape of the data the script reads on every redraw — the raw "how it works" layer.

statusline JSON — piped to stdin
{ "model": { "display_name": "Opus 4.8" }, "output_style": "high", "context": { "used_pct": 13 }, "session": { "total_tokens": 24180, "max": 200000 }, "last_prompt": "build me a status line..." }
Script reads it, divides, draws two ten-cell bars, prints one line. Refreshes on every turn.
A snippet of the statusline shell script: reading the JSON, computing percentages, drawing the ASCII bars
~40 lines
the whole script — read, divide, draw
⚠️

The honest caveat

The bars are an estimate, not a fuel-injection readout. context_used_pct tracks the window; the session-token bar is cumulative spend against a cap you set. Treat them as a dashboard light, not a lab instrument — when context crosses ~80%, that's your cue to /compact or start fresh, not a hard cliff.

04 The gauge through a session

Watch the tank fill

From a fresh 0% start to the ~80% "time to compact" zone, plus the raw data behind it. Tap any image to enlarge it and read the exact prompt that drew it.

RECREATED FROM A REAL SESSION

Now I know exactly when to pull up

The bars climb as I work. When context crosses the line, I /compact on purpose instead of getting caught out. The AI built its own fuel gauge — and now it tells me when its own tank is running low.

The cockpit status line mid-session with both fuel bars climbing, the moment before a /compact
one row · two bars · the difference between a clean session and a silent crash
06 Steal this

Put a fuel gauge in your own terminal

The whole status line is one small Node script and a three-line settings block. Copy both below, restart Claude Code, done. No repo, no sign-up.

script statusline.js config settings.json snippet needs Node 16+

1 Save as ~/.claude/statusline.js

// statusline.js - a Claude Code status line with two fuel bars.
// Output:  Opus 4.8 [high] [███░░░░░░░]13% contxt [██░░░░░░░░]13% sess.token
//
// Claude Code pipes a JSON object to this script's stdin on every refresh;
// whatever the script prints becomes the status line. Needs Node 16+.
'use strict';
const fs = require('fs');

let data = {};
try { data = JSON.parse(fs.readFileSync(0, 'utf8').replace(/^\uFEFF/, '')); } catch (_) {}

const get = (o, ...k) => k.reduce((c, key) => (c == null ? c : c[key]), o);
const clamp = (n) => Math.max(0, Math.min(100, Math.round(Number(n) || 0)));

const CYAN = '\x1b[36m', YELLOW = '\x1b[33m', DIM = '\x1b[90m', RESET = '\x1b[0m';
const bar = (pct) => {
  const filled = Math.round(pct / 10);
  return '[' + CYAN + '█'.repeat(filled) + DIM + '░'.repeat(10 - filled) + RESET + ']';
};

// model name, without the "Claude " prefix
const model = String(get(data, 'model', 'display_name') || 'Claude').replace(/^Claude\s+/i, '');
const effort = get(data, 'effort', 'level');

// bar 1: how full the context window is
const cw = data.context_window || {};
const size = Number(cw.context_window_size) || 200000;
const contxt = clamp(cw.used_percentage != null
  ? cw.used_percentage
  : (Number(cw.total_input_tokens) || 0) / size * 100);

// bar 2: plan usage in the 5-hour window (Pro/Max), else tokens vs window size
const fiveHour = get(data, 'rate_limits', 'five_hour', 'used_percentage');
const sess = clamp(fiveHour != null
  ? fiveHour
  : ((Number(cw.total_input_tokens) || 0) + (Number(cw.total_output_tokens) || 0)) / size * 100);

const parts = [YELLOW + model + RESET];
if (effort) parts.push('[' + effort + ']');
parts.push(bar(contxt) + contxt + '% contxt');
parts.push(bar(sess) + sess + '% sess.token');
console.log(parts.join(' '));

2 Add to ~/.claude/settings.json

{
  "statusLine": {
    "type": "command",
    "command": "node ~/.claude/statusline.js"
  }
}

3 Restart Claude Code. The bars refresh on every turn. Change the colours or the bar width and make it yours.

Next episode

Why my Telegram AI beats the official Claude app

Same fuel gauge, same control — but the terminal and a Telegram bot win on every real task. I stopped opening the desktop app. Here's why.

Darkened teaser — a phone showing a Telegram AI bot next to a terminal status line
Ep.19 is already live — read it now →