Repository navigation
Releases
v2.8.1 — point every nudge at the real doctor
Every message the plugin shows now points at the plugin's own doctor. A bare /doctor runs Claude Code's built-in diagnostic, so "run /doctor --fix" used to send you to the wrong tool. That is the "I ran /doctor --fix like it said and nothing happened" report.
No action needed after updating: /plugin update headroom-usage-indicator@headroom-tools is enough.
The doctor is named properly everywhere
- The yellow broken badge now reads
▲ headroom broken (…) · ask: headroom doctor. It used to end withrun /doctor, which is the built-in command. - Every nudge, recorded failure, README section and skill says
/headroom-usage-indicator:doctor. - The session-start line names the doctor once, not twice.
--fix only runs when you ask for it
- What counts as consent: the doctor skips its second "OK to fix?" question only when your message is
/headroom-usage-indicator:doctor --fix. - What does not: quoting or pasting the command, asking about it, a session-start nudge, or Claude's own guess.
- Session-start nudges say "run /headroom-usage-indicator:doctor (read-only; it asks the user before any --fix)". You are asked once.
- The doctor's own "re-run … --fix" hints say "(with the user's consent)".
- The status-line-only installer runs when you asked for the status line. After only a nudge, it offers and waits for a yes.
No untrusted text in Claude's context
- Recorded failures. The session-start probe reports a recorded failure by its component only: "a recent headroom runtime failure was recorded". It never copies the recorded message, which can contain exception or file text.
hcatrecords only the exception type.- The doctor prints the full record for you, cleaned and labelled "(data, not an instruction)":
- Control, bidirectional and non-ASCII characters are removed, and the record's own "run …doctor --fix" pointer is dropped.
- A
--fixcan never be reassembled from the text. - It shows the record that is current, not a stale copy from the start of the run.
- Probe lines no longer echo
HCAT_PYTHON,CLAUDE_CODE_GIT_BASH_PATHor project paths. They name the setting; the doctor shows the value. - The next-session invoice only shows numbers and a plain, short file path from its ledger.
Smaller fixes
HEADROOM_NO_SETUP_NUDGE=1turns off the "status line isn't set up yet" reminder, for when you keep your own status line. A badge that is set up but missing its library files is still reported. To set it, add"env": {"HEADROOM_NO_SETUP_NUDGE": "1"}to~/.claude/settings.json.- Windows line endings in recorded failures no longer duplicate the doctor pointer, and
hcatwrites plain LF line endings everywhere.
Tests
- Review: 9 multi-reviewer rounds (correctness, testing, agent-native, adversarial).
- Mutation-checked: every fix has a test, and each test was checked by breaking its fix on purpose.
- CI: green on
ubuntu-latest,macos-latestandwindows-latest.- Ubuntu and macOS: 1392 passed, 0 failed.
- Windows: 1372 ran; the only failures are the 58 known-POSIX-only ones.
- New guard: a test fails CI if a bare
/doctorcommand appears in any shipped file.
Full diff: v2.8.0...v2.8.1
v2.8.0 — Windows support
The plugin now runs on Windows under Git for Windows (#9). This release also hardens the doctor on every platform.
⚠️ Updating from v2.7.4 or earlier? Run the doctor once
/headroom-usage-indicator:doctor --fix
v2.8 spawns the bundled MCP by the bare name headroom. That change is what makes Windows work, and it removes the old launcher's ~/.headroom-venv fallback. If an earlier doctor bootstrapped your engine there, it is not on your PATH. --fix shims it into ~/.local/bin and registers it as a user-scoped MCP by absolute path, so it connects without a shell-rc edit. Until you run it, a dead MCP looks exactly like an idle badge.
Windows
- Prerequisite: Git for Windows (Git Bash). Claude Code runs hooks and the status line through it.
- One engine resolver (
scripts/lib/engine-resolve.sh) finds the engine in theScripts\venv layout,uv tooltrampolines, and pip'sheadroom.exelaunchers. The doctor, the hooks,hcatand the session probe all use it, so they always agree on which engine they mean. - The doctor:
- Bootstraps a venv with
py -3/python. - Shims
headroom.exeinto%USERPROFILE%\.local\bin. - Writes the status line through
Git\bin\bash.exe. - Tells you the one Path entry to add.
- On Windows on ARM, detects the wheel-tag mismatch and points you to the x64 Python.
- Bootstraps a venv with
hcat: output is UTF-8 on every platform, and piping it intoheadno longer prints aBrokenPipeError.- Known caveat: Windows resolves a bare command name from the project directory before
PATH. So aheadroom.execommitted to a repo you open would be spawned by the bundled entry. The doctor and the session probe flag such a file, and--fixadds an absolute-path registration next to the bundled one.
The doctor won't persist a project's own headroom
The shim and the user-scoped MCP registration outlive the project the doctor runs in. --fix now refuses a headroom that resolves inside the current project or through a relative path, which is where a repo's own HCAT_PYTHON, UV_TOOL_DIR or PATH settings would steer it. It names the setting that pointed there. An existing registration that already works is judged first, by actually starting it, and left alone.
Other fixes
- Windows-syntax status lines are no longer mangled. A custom status line written for a native spawner (
node C:\...\sl.js,..\tools\sl.cmd,%APPDATA%\sl.js) is no longer chained into the bash badge, where bash would strip its backslashes. The doctor refuses the merge, leavessettings.jsonuntouched, and tells you how to rewrite it. Bash-legal backslashes still pass:printf '\n',date +%H, jq/awk escapes,grep 1\.2\.3, single-quoted regexes. - Fixable-forever message gone. After a successful
--fix, a plain/doctorno longer reports "1 fixable" forever. - Working
uvx-style MCP accepted. SessionStart no longer flags a workinguvx-style MCP registration as broken. - Gate and
hcatagree. The Read gate askshcat --toon-checkwhether it will really compress a file, so it never denies a Read thathcatwould then refuse. hcattime limit.hcat's default time limit is now 90s. The old 120s never fired, because the Bash tool's own 120s kill always won.
How it was tested
- Review: 42 review rounds (8 reviewers each for the last ten). Every fix has a regression test, and each test was checked by removing its fix and confirming the test then fails.
- CI:
ubuntu-latest,macos-latestandwindows-latest, each with a real engine installed.- Ubuntu and macOS: 1215 tests pass, 0 fail.
- Windows: the runner exercises the resolver against genuine venv,
uv tooland pip layouts,doctor --fixend to end, and a shell-less bare-name MCP spawn. Windows failures are ratcheted by name against.github/windows-known-failures.txt, so the list can only shrink. - Fixture floors fail the build if coverage silently drops.
- Mac end-to-end: a sandboxed install and a live Claude Code session, including a real
headroom_compresscall.
Still unverified: Claude Code itself on a real Windows machine (hooks firing, the status-line spawn, the /plugin connected mark). CI runs the scripts on a Windows runner, but it cannot run Claude Code itself. If the badge doesn't render for you on Windows, please paste your statusLine.command into #9.
Tests: 556 → 1215 pass / 0 fail (POSIX), shellcheck clean.
Full diff: v2.7.4...v2.8.0
v2.7.4 — the badge counts what the gate actually compressed
A correctness fix for the number the badge shows you. v2.7.3's badge could report the opposite of what happened.
The gate's own compressions were scored as misses
The PreToolUse gate rewrites a raw cat <big file> into an hcat run. Claude Code executes the rewritten command — the compression really happens, a real receipt lands — but it records the original cat … in the session transcript.
The badge and the session ledger attribute receipts by reading that recorded command, so every auto-rewritten compression banked zero savings and, being a large output, was then counted as a missed opportunity. The plugin's headline v2.7 feature compressed your file and got blamed for not compressing it.
Caught on a clean v2.7.3 install, on a 98 KB JSON the gate compressed 47.4% (~35409 → ~18627 tok):
before: ○ headroom idle · 36 big blobs uncompressed
after: ○ headroom idle · ~16.8k tok · $0.17 · 1× · 36 missed
If your badge has been sitting at "N big blobs uncompressed" while hcat receipts were clearly landing, this was why. Update and the numbers correct themselves — nothing to re-run.
The rewrite turns out to be recoverable from the transcript: Claude Code logs a hook_success attachment keyed by toolUseID carrying the gate's own stdout. Attribution now reads the command the gate announced and applies the same structural test to it — so a hook that merely mentions hcat in prose still counts as nothing, and output that quotes a receipt still can't inflate your savings.
dangi-hook needed no change: it reads its PostToolUse payload, which carries the post-rewrite command, so it had been getting these right all along.
A large passthrough is a miss, not a free pass
A receipt proves an hcat run, not a compression. When content is incompressible hcat emits a "passthrough" receipt with no ~B tok → ~A tok arrow — and those raw bytes really did enter the context window. Savings accounting already required the arrow, but the missed-opportunity counter exempted any receipt, so a large passthrough scored as neither a save nor a miss and the nudge went quiet on output that genuinely flooded the window.
The miss counter now requires an actual compression. This was never specific to gate rewrites, so it is fixed for model-invoked hcat too.
Hardening from the review of the fix
- A crash. jq's
test()throws on non-strings and an uncaught throw aborts the whole program — blank badge, dropped ledger, for the rest of the session. The new path reads a command out of any PreToolUse hook's stdout, so a third-party hook emitting{"command": 42}was one step from disabling attribution. Hardened at the predicate, covering the pre-existing call site too. - Scope. The attachment path had dropped the Bash-only invariant the command path holds implicitly; restored, plus a 64 KB bound on the JSON parse that runs each render.
- Tests that could not fail. Mutation testing showed the structural filters were entirely unpinned, and each negative was a bare absence-check on a poison-only transcript — passing vacuously whenever the pass aborted, which is exactly the crash above. Every negative now pairs its poison with a genuine compression and asserts the genuine numbers still render.
All five regressions are mutation-verified, each caught by exactly the test written for it.
Tests: 519 → 556 pass / 0 fail, shellcheck clean.
Full diff: v2.7.3...v2.7.4
v2.7.3 — the bundled MCP server actually connects
Two shipped bugs, both of the same shape: something reported healthy while the real thing was broken.
The bundled MCP server never connected (v2.5 → v2.7.2)
.mcp.json registered the launcher as "${CLAUDE_PLUGIN_ROOT}"/scripts/mcp-launcher.sh. Claude Code expands the variable and then spawns the result directly — posix_spawn, no shell — so the literal quotes became part of the filename. Every connection attempt died in a few milliseconds with ENOENT, /plugin showed a ✗ beside headroom, and the mcp__headroom__* tools were simply absent.
It went unnoticed for two minor versions because anyone carrying a pre-plugin manual registration in ~/.claude.json still got the tools from there — and because doctor check 4b stripped the quotes before its own -x test, greening the exact string that was failing at spawn. It judged the mechanism, not the outcome.
.mcp.jsondrops the quotes.hooks/hooks.jsondeliberately keeps its quoting — hook commands do run through a shell. The asymmetry is now pinned by tests in both directions.- Check 4b judges the launcher exactly as spawned; a quoted-but-otherwise-correct command is
fixable, and--fixunquotes an installed.mcp.jsonin place (timestamped.bak, idempotent), so existing broken installs self-heal instead of waiting for a fresh one.
Upgrading: run /headroom-usage-indicator:doctor --fix once.
The status line could be "wired" and still never render
A ~ inside quotes is never expanded by any shell — and earlier READMEs showed exactly that form for hand-wiring (bash "~/.claude/headroom-statusline.sh"). Such an entry can never resolve, so the badge silently never appeared. The doctor now detects it in either quote style, reports it, and --fix rewrites the entry to an absolute path. An unquoted bash ~/.claude/… was always fine and is left alone.
The doctor stops lying to itself
The original issue (#2) was check 7c only looking under ~/.claude/lib/ for the badge's runtime deps, so a healthy legacy flat install was reported broken — and the spurious fixable blocked the ambient-health all-clear from ever restoring the badge. 7c now resolves each dep exactly as statusline.sh does at runtime (existence-first, lib/ then flat sibling) and currency-checks only the file that would actually load.
Fixing that surfaced a family of related silent passes, each closed in turn:
statusLine wiredwas a bare substring match — it never confirmed the script was on disk, and 7b/7c thenskipped on the same absent file while block 9 cleared the recorded failure.- Respelled paths (quoted tilde, foreign-home) bypassed the new guard.
- Custom, hand-wired install paths were trusted by check 7 but never inspected by 7b/7c, so their staleness went undetected forever.
- An unanchored path-token match could verify the wrong file, or false-
FAILa perfectly healthy install. - In a multi-token command, one present path masked another that was missing.
Data safety: every backup-then-destructive-rewrite site — .mcp.json, settings.json, settings.local.json, project settings — now refuses to overwrite when its own backup fails, instead of swallowing the failure and claiming a backup that was never written. Load-bearing dependency copies likewise gate the fixed they report.
Tests: 435 → 519 pass / 0 fail, shellcheck clean.
Full diff: v2.7.2...v2.7.3
v2.7.2 — it tells you the one setup step
Small UX follow-up to v2.7.1. Wiring the status line is the one setup step a plugin can't do for you — Claude Code has no plugin field for statusLine, so it takes an explicit /doctor --fix. Until then a fresh install shows no badge, which reads as "is it broken?".
The SessionStart probe now says so: when everything else is healthy but the status line isn't wired, it emits one line —
🤖 headroom setup: status line badge isn't set up yet — run /headroom-usage-indicator:doctor --fix to show it
- Reminder, not a breakage: never writes
last-error, never flips the badge yellow. - Lowest priority: defers to any real problem, sits above the invoice.
- Self-resolving: silent the moment the status line is wired.
- Also fires when the status line is wired but its
lib/deps are missing (the #2 shape — badge would read zero).
Tests: unwired→nudge, wired-but-missing-deps→nudge, wired+deps→silent, no last-error written. 433 pass / 0 fail, shellcheck clean.
Full diff: v2.7.1...v2.7.2
v2.7.1 — the badge finally leaves idle
Patch release. Fixes a fresh-install bug where the status-line badge was permanently stuck at ○ headroom idle (not compressing yet), showing zero savings forever even while hcat/headroom_compress were actively working — with no error and a clean /doctor.
The bug (#2)
statusline.sh resolves its attribution.jq + headroom-state.sh deps from a lib/ dir next to the installed copy. Without them compute() silently returns 0 on every render. But neither doctor.sh --fix nor the primary SKILL.md installer ever copied scripts/lib/ alongside the copy — only the legacy fallback installer did — so the badge read zero on every plugin/marketplace install. Check 7b only cmp'd the script itself, so /doctor reported all-ok while the badge was structurally broken.
Fixed
doctor.shnow provisions~/.claude/lib/{attribution.jq,headroom-state.sh}in both the initial-wire and refresh paths, and a new check 7c verifies + repairs them under--fix— so existing broken installs self-heal on the next/doctorrun.- The primary Python installer in
SKILL.mdprovisions the deps too. marketplace.jsonsynced to2.7.1(it had been stranded at2.6.0).
Tests
Fresh-install --fix now asserts lib provisioning; a new F7e fixture reproduces the exact "current copy, missing lib deps" shape the old doctor passed silently. 427 pass / 0 fail, shellcheck clean.
Upgrade
Update the plugin, then ask Claude to run /headroom-usage-indicator:doctor --fix once — it installs the missing deps and the badge starts reporting real savings.
Credit
Root-caused with a full write-up, suggested fix, and confirmed workaround by @wandering-tales. Thank you! 🙏
Full diff: v2.7.0...v2.7.1
v2.6.0 — data-driven prices, smarter Dangi, demo GIF
Three quick wins on top of v2.5's self-contained install.
Prices as data (not code)
- New
data/model-prices.json— an ordered{match, usd_per_mtok}list (first substring match wins). Adding a model is a one-line data edit shipped with the plugin; no script change. - The badge reads it when present (authoritative); the built-in
price_per_mtok()table remains a zero-regression offline fallback when the file is absent or invalid.HEADROOM_PRICES_FILEoverrides the path. - The doctor validates the bundled file and copies it beside the statusline copy (
~/.claude/headroom-model-prices.json), so copied/plugin installs are data-driven too.
Smarter, file-aware Dangi nudge
- When a Bash command reveals the source file (
cat/headof.json/.jsonl/.ndjson/.csv/.tsv/.log), the nudge now names it —hcat "/path/to/file.json"— instead of a generic<path>. High-precision; falls back to the placeholder when uncertain. - Big outputs suppressed during the 60s cooldown are counted, and the next nudge reports how many were missed in the gap (batched, not one-per-blob). Added
DANGI_NOWas a deterministic clock test seam.
Demo GIF
docs/demo-badge.gif— the badge's three real states (red idle → green active → grey decayed), rendered from actual script output. README embeds it in place of the placeholder.
Tests: 285 passed, 0 failed (+17 checks), shellcheck clean at warning severity. Version 2.6.0.
v2.5.0 — self-contained install
Highlights
Setup went from ~a dozen manual steps to two commands + one doctor run.
- Plugin-native hooks — Dangi (PostToolUse) and the hcat gate (PreToolUse) register themselves via
hooks/hooks.jsonthe moment the plugin is enabled. Nosettings.jsonhook surgery. hcaton PATH — shipped inbin/, added to Claude's Bash PATH automatically.- Bundled MCP registration —
.mcp.json→scripts/mcp-launcher.shresolves your engine and execsheadroom mcp serveoffline. No manualclaude mcp add. - Doctor (
scripts/doctor.sh+/doctorskill) — read-only diagnosis of the whole chain (jq, engine, MCP, hooks, status line), then with consent: bootstraps the engine venv, writes the one thing a plugin can't self-register (thestatusLine, merge-aware), removes legacy double-firing installs, and refreshes stale copies. Hardened against symlinked/corrupt settings, brokenHCAT_PYTHON, and Debian venv dead-ends. All fixes idempotent.
Portability
- Linux
notify-sendfallback for Dangi notifications (osascript preferred on macOS). hcatSIGPIPE handling; GNU/BSDstat/date/awk-locale sweep.
Correctness & docs
- Receipt attribution is now structural on both the badge and Dangi — a quoted receipt line no longer counts as a compression.
- Test harness:
check_eqexact-match assertions for exit codes/counts; shellcheck runs at warning severity across all five scripts (now incl.doctor.shandmcp-launcher.sh). - README + skills synced to as-built behavior.
Full test suite: 268 passed, 0 failed.
v2.4.1 — Dangi recognizes hcat receipts
The badge (since v2.4.0) already knew that an hcat receipt is a compression — but Dangi, the real-time nudge hook, didn't: it kept nudging Claude about hcat's own output. Now an output carrying the ── hcat: header is never a nudge target.
Covers all three shapes the receipt arrives in:
- at the start of the output,
- buried after a persisted-output preview banner,
- JSON-escaped inside an object-form
tool_response.
A big output that merely mentions hcat mid-line still nudges — the match is on the distinctive header marker, not the word.
99/99 checks green. Manifests bumped to 2.4.1.
v2.4.0 — the badge finally sees hcat
Statusline counts hcat (the v2.4 headline)
Every hcat run leaves a receipt in the transcript (── hcat: … ~18899 tok → ~9351 tok (50.5% saved)). The badge now parses those receipts and folds them into the token count, the dollar figure, the N× counter, the 60s green flash, and the all-time total. Before this, a session that saved everything via hcat still read "idle (not compressing yet)".
- Receipts are matched at any line start — persisted big outputs bury the header after a preview banner, and those count too (negative-control tested).
- Passthrough receipts (no
→, hcat couldn't shrink the file) count as nothing. - A big receipt is never a "missed" blob — it is the compression.
compute()consolidated from 4 jq passes to 1: ~47ms cold on a 548K transcript.
Dangi hardening
- Ignores
WebFetch/WebSearch(prose) and image tool_responses (base64, not compressible text). - Sizes outputs in bytes, not codepoints — multibyte content no longer undercounts.
- Best-effort
mkdirlock so parallel tool batches don't double-nudge (stale locks stolen after 5s; never blocks).
Gate hardening
- Also catches a bare single-file
cat <path>via Bash (pipes, redirects, and boundedhead/tailpeeks still pass — those are real processing).
95/95 checks green. Manifests bumped to 2.4.0.