From 7ec125937e45f53243bd365f3cb235dcb4880559 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Folt=C3=A1n?= Date: Mon, 23 Feb 2026 12:19:19 +0100 Subject: [PATCH] Add invert option for usage_5hour and usage_weekly segments Adds `invert=0/1` segment option that shows used % instead of remaining %. Default is 0 (no change in behavior). Usage: `usage_5hour:invert=1 usage_weekly:invert=1` --- CLAUDE.md | 2 +- README.md | 5 +++++ claude-code-status-line.py | 7 ++++--- 3 files changed, 10 insertions(+), 4 deletions(-) diff --git a/CLAUDE.md b/CLAUDE.md index 47b0752..390e4be 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -62,7 +62,7 @@ Key sections in `claude-code-status-line.py` (~2,200 lines): - **Bayesian shrinkage**: the observed burn rate is blended toward the on-track rate using a hyperbolic trust curve `f = elapsed / (halftrust + elapsed)`, so early-window noise is dampened. Config: `usage_burndown:halftrust=16` (default 16h — at 16h elapsed, 50/50 blend). - **Relevance filter**: burndown is suppressed when the predicted "sooner" gap is too small relative to remaining time, using a power curve `days_remaining^coeff` (in hours) divided by the trust factor `f`. The `/f` scaling makes the threshold inversely proportional to data confidence — early-window signals need proportionally larger gaps to display. Config: `usage_burndown:coeff=1.4` (default). - Config: `usage_burndown:verbosity=short:coeff=1.4:halftrust=16`. Short uses compact compound durations (`5d2h30m`), `~` instead of `about`, `->` instead of `then`, drops `usage`, `out ~` instead of `may run out about`; `git_status` shows working directory state using symbols: `+` staged, `!` modified, `x` deleted, `r` renamed, `?` untracked, `=` conflicted, `$` stashed, `>` ahead, `<` behind, `<>` diverged; `added_dirs` shows directories added via `/add-dir` (from `workspace.added_dirs` JSON field), sorted alphabetically, joined by separator. Config: `added_dirs:basename_only=1:separator=,` (defaults: full path with `~` home shortening, ` • ` separator). Theme color: `text_added_dirs` (dark: Nord3 muted gray `#4C566A`, light: medium gray `#7B8394`); `worktree` shows worktree info when `worktree` field is present in JSON input (from `--worktree` sessions). Displays in curly braces `{name}`. Config: `worktree:show=name` (default), supports `name`, `branch`, `path`, `origin` or comma-separated combo like `show=name,branch`. `path` and `origin` apply `~` home shortening. `origin` maps to JSON `original` field. Theme color: `text_worktree` (dark: Nord15 purple `#B48EAD`, light: muted purple `#8B6B85`). `model` segment supports `effort` option to show reasoning effort level inside the badge: `model:effort=short` (L/M/H/A) or `model:effort=full` (low/medium/high/auto). Reads from settings files (not in statusline JSON). Precedence: `CLAUDE_CODE_EFFORT_LEVEL` env var → `.claude/settings.local.json` → `.claude/settings.json` → `~/.claude/settings.json`. `max` cannot be detected (session-only). -- **Configuration**: global settings via `SL_THEME`, `SL_USAGE_CACHE_DURATION`, `SL_UPDATE_CACHE_DURATION`, `SL_UPDATE_RETRY_DURATION`, `SL_UPDATE_CUSTOM_RETRY_DURATION`, `SL_UPDATE_VERSION_CMD`, `SL_UPDATE_VERSION_SOURCE`, `SL_SHOW_STATUSLINE_UPDATE`, `SL_THEME_FILE`, `SL_DUMP`. All per-segment config (bar width, gauge style, hide default branch, basename-only directory) via colon-separated options in `SL_SEGMENTS`. +- **Configuration**: global settings via `SL_THEME`, `SL_USAGE_CACHE_DURATION`, `SL_UPDATE_CACHE_DURATION`, `SL_UPDATE_RETRY_DURATION`, `SL_UPDATE_CUSTOM_RETRY_DURATION`, `SL_UPDATE_VERSION_CMD`, `SL_UPDATE_VERSION_SOURCE`, `SL_SHOW_STATUSLINE_UPDATE`, `SL_THEME_FILE`, `SL_DUMP`. All per-segment config (bar width, gauge style, hide default branch, basename-only directory, invert usage display) via colon-separated options in `SL_SEGMENTS`. - **Dump mode**: `SL_DUMP=1` appends every stdin JSON input (with ISO timestamp) as JSONL to `/tmp/claude-statusline-dump.jsonl`. Normal rendering continues. Useful for inspecting what Claude Code sends. Auto-cleaned on reboot. - **Update checker**: fetches latest version from npm registry (`@anthropic-ai/claude-code`) or custom command (`SL_UPDATE_VERSION_CMD`), compares with `claude --version` output. Custom command retries 3 times with 1s delay, then falls back to npm. Returns `(version, source)` tuple where source is `npm`, `custom`, or `npm_fallback`. Cached to `~/.claude/.update_cache.json` — success cached for `UPDATE_CACHE_DURATION` (1h), custom source failures retry after `UPDATE_CUSTOM_RETRY_DURATION` (2min), total failures retry after `UPDATE_RETRY_DURATION` (10min). Falls back to stale cache when offline. - **Self-update**: `--self-update` flag downloads latest version from GitHub and replaces the script atomically. Status line update notifications appear on a separate line below the main output with the update command. Controlled by `SL_SHOW_STATUSLINE_UPDATE` (default on). diff --git a/README.md b/README.md index a2a755c..b093d25 100644 --- a/README.md +++ b/README.md @@ -133,8 +133,10 @@ Each token is `segment_name` optionally followed by `:key=value` pairs. Unknown | `git_branch` | `hide_default` | `0`/`1` | `1` | Hide branch on `main`/`master` | | `usage_5hour` | `gauge` | `vertical`/`blocks`/`none` | `blocks` | Gauge style | | `usage_5hour` | `width` | even integer >= 2 | `4` | Gauge width (invalid values reset to 4) | +| `usage_5hour` | `invert` | `0`/`1` | `0` | Show used % instead of remaining % | | `usage_weekly` | `gauge` | `vertical`/`blocks`/`none` | `blocks` | Gauge style | | `usage_weekly` | `width` | even integer >= 2 | `4` | Gauge width (invalid values reset to 4) | +| `usage_weekly` | `invert` | `0`/`1` | `0` | Show used % instead of remaining % | | `usage_burndown` | `verbosity` | `default`/`short` | `default` | Message style (see burndown section) | | `usage_burndown` | `coeff` | float | `1.4` | Relevance filter power curve exponent (see burndown section) | | `usage_burndown` | `halftrust` | float (hours) | `16` | Bayesian shrinkage half-trust point (see burndown section) | @@ -160,6 +162,9 @@ SL_SEGMENTS='model progress_bar percentage tokens directory:basename_only=1 git_ # Show git branch even on main/master SL_SEGMENTS='model progress_bar percentage tokens directory git_branch:hide_default=0' +# Show used % instead of remaining % for usage limits +SL_SEGMENTS='model progress_bar percentage tokens directory usage_5hour:invert=1 usage_weekly:invert=1' + # Multi-line layout: model and progress on first line, directory on second SL_SEGMENTS='model progress_bar percentage new_line directory git_branch' diff --git a/claude-code-status-line.py b/claude-code-status-line.py index c44d2b1..a1e774f 100755 --- a/claude-code-status-line.py +++ b/claude-code-status-line.py @@ -82,8 +82,8 @@ def _env_int(key, default): "directory": {"basename_only": "0"}, "added_dirs": {"basename_only": "0", "separator": " • "}, "git_branch": {"hide_default": "1"}, - "usage_5hour": {"gauge": "blocks", "width": "4"}, - "usage_weekly": {"gauge": "blocks", "width": "4"}, + "usage_5hour": {"gauge": "blocks", "width": "4", "invert": "0"}, + "usage_weekly": {"gauge": "blocks", "width": "4", "invert": "0"}, "worktree": {"show": "name"}, "usage_burndown": {"coeff": "1.4"}, } @@ -1351,6 +1351,7 @@ def format_usage_indicators(usage_data): now = datetime.now(timezone.utc) remaining_pct = max(0, int(100 - utilization_pct)) + display_pct = min(100, int(utilization_pct)) if opts.get("invert") == "1" else remaining_pct reset_label = reset_dt.astimezone().strftime(time_fmt) # Calculate time elapsed in window @@ -1436,7 +1437,7 @@ def format_usage_indicators(usage_data): gauge = get_usage_gauge(ratio) gauge_part = f"{gauge}\u00a0" if gauge else "" results[segment_name] = ( - f" {gauge_part}{color}{remaining_pct}\u00a0%\u00a0→\u00a0{reset_label}" + f" {gauge_part}{color}{display_pct}\u00a0%\u00a0→\u00a0{reset_label}" ) for seg in ("usage_5hour", "usage_weekly"):