Skip to content

fix: render extra usage segment + adopt clone-based install#27

Merged
daniel3303 merged 2 commits into
mainfrom
fix/extra-usage-rendering
Apr 23, 2026
Merged

fix: render extra usage segment + adopt clone-based install#27
daniel3303 merged 2 commits into
mainfrom
fix/extra-usage-rendering

Conversation

@daniel3303
Copy link
Copy Markdown
Owner

Summary

  • Fixes the extra segment never rendering once Claude Code began supplying rate_limits in the statusline stdin JSON (the common path).
  • Makes the OAuth usage-API cache resilient to failed fetches so a transient error does not suppress retries for a full 60s window.
  • Updates the install story: leads with "clone the repo, let Claude configure it", adds INSTALL.md so Claude has an authoritative step-by-step; paste-install stays as a fallback.

Code changes

statusline.sh + statusline.ps1

  • Removed the effective_builtin gate on the usage-API fetch. Claude Code's stdin rate_limits only exposes five_hour / seven_dayextra_usage still has to come from https://api.anthropic.com/api/oauth/usage.
  • Extracted extra-usage rendering into a helper (render_extra_usage / Format-ExtraUsage) used by both the builtin and API-fallback branches.
  • Preserved .extra_usage inside the builtin branch's cache snapshot so a freshly fetched value is not clobbered on the next tick.
  • Cleaned up the empty stampede-sentinel cache file on failed fetch.
  • PowerShell helper is now try/catch-wrapped since the builtin branch has no outer catch.

README.md

  • Install section leads with the clone-and-let-Claude-configure flow; paste-install kept as an alternative.
  • Added an "Updating" section showing the single git pull path.
  • Cache paths updated to reflect the per-config-dir hash suffix.

INSTALL.md (new)

  • OS detection, clone target, per-shell settings.json snippets, restart, update, uninstall, requirements.
  • Structured to be executed top-to-bottom by Claude Code when a user asks "clone this repo and use it as my status bar".

How to test

Fix verification (macOS / Linux)

  1. Wipe the usage cache: rm -f /tmp/claude/statusline-usage-cache-*.json
  2. Seed a cache entry with extra_usage.is_enabled=true to simulate a Pro/Max account with extra credits enabled:
    HASH=$(echo -n "$HOME/.claude" | shasum -a 256 | cut -c1-8)
    echo '{"five_hour":{"utilization":50,"resets_at":"2026-04-30T20:00:00Z"},"seven_day":{"utilization":30,"resets_at":"2026-05-07T20:00:00Z"},"extra_usage":{"is_enabled":true,"utilization":25,"used_credits":1234,"monthly_limit":10000}}' > "/tmp/claude/statusline-usage-cache-${HASH}.json"
  3. Run the script with stdin that includes rate_limits (the builtin path):
    echo '{"model":{"display_name":"Claude"},"rate_limits":{"five_hour":{"used_percentage":42,"resets_at":1777777777},"seven_day":{"used_percentage":18,"resets_at":1778888888}}}' | bash statusline.sh
  4. Expect a trailing | extra $12.34/$100.00 segment. Before this PR, the segment was silently dropped.

Empty-sentinel cleanup

  1. rm -f /tmp/claude/statusline-usage-cache-*.json
  2. Run with an invalid token: CLAUDE_CODE_OAUTH_TOKEN=nope echo '{"model":{"display_name":"C"}}' | bash statusline.sh
  3. Cache file should not exist afterwards (so the next invocation can retry immediately).

Install docs

  • Open INSTALL.md and confirm the settings.json snippets match the shell the user is running Claude Code in.
  • Dry-run the clone command with --dry-run style check: git ls-remote https://github.com/daniel3303/ClaudeCodeStatusLine should respond.

Notes

  • Users on Pro/Max without extra usage enabled will now make one call to /api/oauth/usage per minute per CLAUDE_CONFIG_DIR (previously zero). The endpoint is designed for this cadence and the cache is shared across tmux panes via mtime-based stampede locking.
  • VERSION constant left at 1.3.0 — bump and tag a release separately when you want users to see the update-available banner.

@daniel3303 daniel3303 merged commit dc241cc into main Apr 23, 2026
@daniel3303 daniel3303 deleted the fix/extra-usage-rendering branch April 23, 2026 16:01
Claude Code's statusline JSON input exposes five_hour and seven_day rate
limits but never extra_usage. The previous logic gated the OAuth usage API
fetch behind !effective_builtin, so once Claude Code began supplying
rate_limits (common case) the API was never called and the extra segment
never rendered.

- Always refresh the API cache when stale (still 60s-throttled); builtin
  rate_limits take precedence for 5h/7d rendering.
- Share extra_usage rendering across builtin and API-fallback branches via
  render_extra_usage / Format-ExtraUsage helpers.
- Preserve extra_usage inside the builtin branch's cache snapshot so a
  freshly fetched value is not clobbered on the next tick.
- Clean up the empty stampede-sentinel cache file on failed fetch so a
  transient API error does not suppress retries for a full cache window.
- Wrap the PowerShell helper in try/catch since it is now also called
  from the builtin branch, which has no outer catch.
Paste-install leaves users stranded on whatever version they pasted and
makes updates a manual chore. Leading with a git-clone of the repo turns
updates into a single `git pull` and gives users a stable, authoritative
source.

- New INSTALL.md: step-by-step install guide written for Claude Code to
  execute when the user says "clone this repo and use it as my status bar",
  covering OS detection, clone location, settings.json per shell, restart,
  update, and uninstall.
- README: install section now leads with the clone flow and links to
  INSTALL.md for details; paste-install kept as a fallback for
  environments without git.
- README: updated cache path to reflect the per-config-dir hash suffix
  and noted that update notifications also cache for 24h.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant