claude: statusline cleanup
980b84f10c67660e6a4f52bc88b0ce2d4a285b61
Oliver Krylow <o.krylow@isp-insoft.de> ·
unsigned
- Parent 1: 489a2eedc669
wezterm: win32 cleanup
bugabingas dorkfiles
980b84f10c67660e6a4f52bc88b0ce2d4a285b61
Oliver Krylow <o.krylow@isp-insoft.de> ·
unsigned
wezterm: win32 cleanup
+294 / −99 text lines · 1 binary (striped old/new sizes in 64-byte units, not churn) · lines and sizes scale separately
+18 / −0 text lines
new file mode 100644+141 / −0 text lines
# Claude Code StatuslineEine einzeilige, Statusline für Claude Code.Reines Node (stdlib), ein Renderer + ein Hook. Cross-Plattform (win/mac/linux).Beispielausgabe:``` RD-1950 · Opus 4.8 · xhigh · RD-1950 · 5h ██▋░░░░░ 33%·2h44m · 7d █▏░░░░░░ 14% · 🔥$26.68/hr · $0.499 $136.54Σ $486.13☾ · caveman:full```Segmente (v.l.n.r.): Verzeichnis · Modell · Effort · Git/JJ-Branch · 5h-Limit ·7d-Limit · Burn-Rate ($/h) · Kosten (Turn / Session Σ / Monat ☾) · Caveman-Badge.---## Voraussetzungen| Dep | Pflicht | Zweck ||-----|---------|-------|| **Node ≥ 18** | ✅ | Laufzeit. Nur stdlib (`fs/os/path/crypto/child_process`), keine npm-Pakete. || **Claude Code** | ✅ | Liefert den JSON-Payload (inkl. Kosten) via stdin. || **git** oder **jj** | ➖ | Branch-Segment. Muss im `PATH` sein. Ohne → Segment entfällt. || **Nerd Font** | ➖ (empfohlen) | Glyphen ``, Balken `█▏░`, Icons. Ohne → Tofu (`□`). || **caveman-Plugin** | ➖ | Caveman-Badge. Ohne → Badge entfällt. |---## Dateien| Datei | Rolle ||-------|-------|| [`statusline.js`](./statusline.js) | Renderer. Liest stdin-JSON, gibt eine Zeile aus. || [`cc-statusline-hook.js`](./cc-statusline-hook.js) | Hook. Setzt Turn-Marker + Workflow-Badge. |Beide nach `~/.claude/` kopieren oder symlinken:```bashln -s "$PWD/statusline.js" ~/.claude/statusline.jsln -s "$PWD/cc-statusline-hook.js" ~/.claude/cc-statusline-hook.js```---## Installation1. Node ≥ 18 installieren, im `PATH`.2. Beide Dateien nach `~/.claude/` (s.o.).3. `~/.claude/settings.json` ergänzen (Auszug unten).4. Nerd Font im Terminal aktivieren (sonst Tofu statt Glyphen).5. Claude Code neu starten.### settings.json (Auszug)```jsonc{ "statusLine": { "type": "command", "command": "node ~/.claude/statusline.js" }, "hooks": { // Turn-Marker: Basis für die "Turn"-Kosten (Δ seit letztem Prompt) "UserPromptSubmit": [ { "hooks": [ { "type": "command", "command": "node ~/.claude/cc-statusline-hook.js" } ] } ], // Workflow-Badge: NUR beim Workflow-Tool feuern (matcher scoped!) "PreToolUse": [ { "matcher": "Workflow", "hooks": [ { "type": "command", "command": "node ~/.claude/cc-statusline-hook.js" } ] } ] }}```Der Hook ist **ein** Skript für beide Events; es verzweigt über `hook_event_name`.---## Funktionsweise- Claude Code spawnt `statusline.js` **pro Render** (frischer Prozess, Payload via stdin, 300 ms Debounce, event-getriggert: neue Assistant-Nachricht, `/compact`, Permission-/Vim-Mode-Wechsel). Per-Render-Spawn ist von der API erzwungen.- Renderer baut Segmente, jeweils eigener `try/catch` (ein Crash darf die Zeile nicht leeren), und schreibt **ohne** Trailing-Newline.- **Turn-Kosten**: Der Hook legt bei `UserPromptSubmit` eine Marker-Datei `~/.claude/.cc-turn-<session>` an. Der nächste Render liest sie, rebaselined den Turn-Start und löscht den Marker.- **Workflow-Badge**: Bei `PreToolUse(Workflow)` schreibt der Hook eine selbst- ablaufende Zeile nach `~/.claude/.cc-statusline-extra` (TTL 120 s), die der Renderer rendert.- **Kosten-Ledger** `~/.claude/.cc-cost-ledger.json`: Turn / Session / Monat (monats- übergreifend kumuliert). Idle-Renders (keine Kostenänderung) schreiben nicht. Selbst-GC räumt alte `.cc-*.tmp` / `.cc-turn-*` (> 1 Tag) auf.---## AnpassungTunables stehen oben in `statusline.js` im `CONFIG`-Block:| Schlüssel | Default | Bedeutung ||-----------|---------|-----------|| `sep` | `" · "` | Trenner zwischen Segmenten. || `barWidth` | `8` | Zellen pro Usage-Balken. || `costStyle` | `"icon"` | `"icon"` = helle `$Zahl` + gedämpftes Glyph; `"slash"` = `$x/turn`. || `gitCacheTtlMs` | `8000` | Cache für `git status` (Spawn ist ~400 ms kalt auf win32). || `contextWarnPct`/`CritPct` | `70`/`90` | Schwellen Kontext-Balken (gelb/rot). || `usageWarnPct`/`CritPct` | `50`/`80` | Schwellen Rate-Limit-Balken. || `burnWindowMs` | `10 min` | Fenster für die Burn-Rate ($/h). |---## Performance (win32)- Harte Untergrenze ist **nicht** das Skript, sondern der Node-Kaltstart: `node -e 0` ≈ **120 ms** (Prozess-Spawn + V8-Init). Nicht durch Flags reduzierbar.- **< 100 ms ist mit Node unmöglich.** Nur ein kompiliertes Binary (Go/Rust ~10–20 ms) unterbietet das — kostet aber Cross-Plattform (per-OS-Builds) + zweite Codebase. Bun (win32) und Deno sind langsamer als Node; LLRT kann kein stdin lesen. → Node.- Die Bar ist asynchron und blockiert keine Eingabe; ~120–140 ms sind unsichtbar.---## Troubleshooting| Symptom | Ursache / Fix ||---------|---------------|| `□`/Tofu statt Glyphen | Nerd Font nicht aktiv im Terminal. || Keine Kosten | Alte Claude-Code-Version ohne `cost` im Payload. || Kein Branch-Segment | `git`/`jj` nicht im `PATH`, oder nicht in einem Repo. || Keine Turn-Kosten | Hook nicht in `UserPromptSubmit` registriert. || Statusline leer | `statusline.js` wirft beim Start — manuell testen: `echo '{}' \| node ~/.claude/statusline.js`. |+56 / −25 text lines
sep: " · ", // segment padding sep: " · ", // segment padding (single-space around the dot — tight) if (d?.model?.display_name) push(c.magenta(d.model.display_name)); push(on ? col(`⚡${lvl}`) : c.dim(`⚡${lvl}`)); push(on ? col(lvl) : c.dim(lvl)); // no ⚡ glyph — level word alone // icon: semantic glyph (⟳ turn / Σ session / ☾ month). slash: <num>/<type>. const fmt = (n, type, icon, color) => CONFIG.costStyle === "icon" ? color(`${icon}$${money(n)}`) : color(`$${money(n)}/${type}`); // icon style: bright $number (emphasis) + dim trailing glyph (muted icon). // turn has no glyph (bare $num); session Σ / month ☾. slash: $num/type. const fmt = (n, type, icon) => CONFIG.costStyle === "icon" ? c.white(`$${money(n)}`) + (icon ? c.dim(icon) : "") : c.white(`$${money(n)}/${type}`); let dirty = false; // persist (disk write) only when something material changed dirty = true; dirty = true; if (delta > 0) L.monthTotal = (L.monthTotal || 0) + delta; s.samples.push([now, total]); if (delta > 0) { s.total = total; s.ts = now; s.samples.push([now, total]); if (s.samples.length > CONFIG.burnMaxSamples) s.samples = s.samples.slice(-CONFIG.burnMaxSamples); } // Prune the window in-memory every render (cheap, no disk) so even an idle // render shows a current-window rate rather than a stale one. if (s.samples.length > CONFIG.burnMaxSamples) s.samples = s.samples.slice(-CONFIG.burnMaxSamples); try { const tmp = `${file}.${process.pid}.tmp`; fs.writeFileSync(tmp, JSON.stringify(L)); fs.renameSync(tmp, file); } catch {} // Persist only when something changed — skips stringify+write+rename (the bulk // of this function's cost) on the common idle re-render path. if (dirty) { try { const tmp = `${file}.${process.pid}.tmp`; fs.writeFileSync(tmp, JSON.stringify(L)); fs.renameSync(tmp, file); } catch {} // Opportunistic GC (write-path only, so throttled to active turns): cancelled // renders leave `.cc-*.tmp` atomic-write orphans; ended sessions leave // `.cc-turn-*` markers. Sweep our own debris older than a day. try { const stale = now - 864e5; for (const f of fs.readdirSync(claudeDir)) { if (!((f.startsWith(".cc-") && f.endsWith(".tmp")) || f.startsWith(".cc-turn-"))) continue; const fp = path.join(claudeDir, f); try { if (fs.statSync(fp).mtimeMs < stale) fs.unlinkSync(fp); } catch {} } } catch {} } let s = col(`⎇${branch}`); let s = col(` ${branch}`); // U+E0A0 powerline branch glyph (Nerd Font)+48 / −0 text lines
[windows]sandbox = "elevated"[notice]hide_full_access_warning = true[tui]theme = "inspired-github"status_line = ["model-with-reasoning", "current-dir", "project-name", "git-branch", "pull-request-number", "branch-changes", "context-used", "five-hour-limit", "weekly-limit", "context-window-size", "fast-mode", "thread-title", "task-progress"]status_line_use_colors = truesession_picker_view = "comfortable"pet = "disabled"[tui.model_availability_nux]"gpt-5.5" = 4[projects.'c:\users\okr']trust_level = "trusted"[projects.'c:\users\okr\.codex']trust_level = "trusted"[projects.'c:\users\okr\workspace']trust_level = "trusted"[projects.'c:\users\okr\workspace\dotfiles']trust_level = "trusted"[projects.'c:\users\okr\workspace\isp-insoft-cloud']trust_level = "trusted"[projects.'c:\users\okr\workspace\kkg']trust_level = "trusted"[projects.'c:\users\okr\workspace\kkg-cloud']trust_level = "trusted"[projects.'c:\users\okr\workspace\kkg5']trust_level = "trusted"deleted file mode 100644Binary size (old → new): 2573 → 0 bytes.
+2 / −8 text lines
deleted file mode 100644+0 / −49 text lines
local wez = require 'wezterm'local function append_all(dst, src) for _, value in ipairs(src) do table.insert(dst, value) endendlocal function scoped_domain(name, label, properties) return wez.exec_domain(name, function(cmd) local args = cmd.args or { 'nu', '--login' } local env = cmd.set_environment_variables or {} env.WEZTERM_EXEC_DOMAIN = name cmd.set_environment_variables = env local unit = 'wezterm-' .. name:gsub('[^%w_.-]', '-') .. '-' .. tostring(env.WEZTERM_PANE or os.time()) local wrapped = { 'systemd-run', '--user', '--scope', '--same-dir', '--collect', '--quiet', '--unit=' .. unit, '--description=WezTerm ' .. name, } for _, property in ipairs(properties) do table.insert(wrapped, '-p') table.insert(wrapped, property) end append_all(wrapped, args) cmd.args = wrapped return cmd end, label)endreturn function(cfg) if not wez.target_triple:find( 'linux', 1, true ) then return end cfg.exec_domains = { scoped_domain('scope:build', 'scope:build CPU 25% MEM max 256M', { 'CPUQuota=25%', 'MemoryMax=256M', 'MemorySwapMax=0', 'OOMPolicy=stop', }), }end+2 / −1 text lines
+10 / −11 text lines
if triple:find( 'windows', 1, true ) then return 'WIN', wez.nerdfonts.dev_windows or '□', palette.warning end if triple:find( 'darwin', 1, true ) then return 'MAC', wez.nerdfonts.dev_apple or '□', palette.ui.important_local end if triple:find( 'linux', 1, true ) then return 'LIN', wez.nerdfonts.dev_linux or '□', palette.ui.important_local end if triple:find( 'bsd', 1, true ) then return 'BSD', wez.nerdfonts.dev_freebsd or '□', palette.ui.important_local end return 'LOC', wez.nerdfonts.cod_terminal or '□', palette.ui.important_local if triple:find( 'windows', 1, true ) then return 'WIN', wez.nerdfonts.dev_windows or ' ', palette.warning end if triple:find( 'darwin', 1, true ) then return 'MAC', wez.nerdfonts.dev_apple or ' ', palette.ui.important_local end if triple:find( 'linux', 1, true ) then return 'LIN', wez.nerdfonts.dev_linux or ' ', palette.ui.important_local end if triple:find( 'bsd', 1, true ) then return 'BSD', wez.nerdfonts.dev_freebsd or ' ', palette.ui.important_local end return 'LOC', wez.nerdfonts.cod_terminal or ' ', palette.ui.important_local if domain == 'unix' then return 'MUX', wez.nerdfonts.cod_server or wez.nerdfonts.cod_terminal or '□', palette.info end if domain == 'unix' then return 'MUX', wez.nerdfonts.cod_server or wez.nerdfonts.cod_terminal or ' ', palette.info end if domain:find( '^WSL:', 1, false ) then return 'WSL', wez.nerdfonts.dev_linux or '□', palette.ui.important_local end if domain:find( '^scope:', 1, false ) then return 'EXE', wez.nerdfonts.cod_gear or '□', palette.warning end return ( domain:upper():gsub( '[^%w]', '' ):sub( 1, 3 ) .. 'LOC' ):sub( 1, 3 ), wez.nerdfonts.cod_terminal or '□', palette.ui.important_local if domain:find( '^WSL:', 1, false ) then return 'WSL', wez.nerdfonts.dev_linux or ' ', palette.ui.important_local end if domain:find( '^scope:', 1, false ) then return 'EXE', wez.nerdfonts.cod_gear or ' ', palette.warning end return ( domain:upper():gsub( '[^%w]', '' ):sub( 1, 3 ) .. 'LOC' ):sub( 1, 3 ), wez.nerdfonts.cod_terminal or ' ', palette.ui.important_local cfg.status_update_interval = 1000+2 / −2 text lines
+15 / −2 text lines
+0 / −1 text lines