Skip to content

fix: stop rewriting usage cache on every render - #54

Open
saveli wants to merge 1 commit into
daniel3303:mainfrom
saveli:fix/usage-cache-refresh
Open

saveli wants to merge 1 commit into
daniel3303:mainfrom
saveli:fix/usage-cache-refresh

Conversation

@saveli

@saveli saveli commented Sep 23, 2026

Copy link
Copy Markdown
Contributor

Fixes #50.

Problem

When Claude Code provides rate_limits on stdin (the normal case), the builtin branch rewrote the usage cache with a minimal synthesized JSON on every render. This refreshed the cache file's mtime each time, so the 60s staleness check never fired again. As a result, /api/oauth/usage was only fetched once per cache lifetime:

  • extra_usage froze at its first value and only updated after restarting the session, which is exactly what extra usage stat is not working #50 describes
  • every other field of the API response was dropped from the cache

Fix

Remove the per-render cache write in the builtin branch (statusline.sh and statusline.ps1). The API refresh already runs regardless of builtin data (it exists precisely because extra_usage is only available from the API) and keeps the cache current. The all-zero fallback from b3abb7c keeps working: it now reads the real API cache, which is at most 60s old.

Testing

statusline.sh on macOS: with the patch, the cache mtime stays unchanged across renders and the API is refetched after 60s. On main, every render bumps the mtime. I could not test statusline.ps1 because I don't have PowerShell available; that change is the same deletion of the equivalent block.

The builtin rate_limits branch rewrote the usage cache with a minimal JSON
on every render. That refreshed the cache mtime each time, so the 60s
staleness check never fired and /api/oauth/usage was never fetched again
after the first call. extra_usage stayed frozen until the session was
restarted, and all other fields of the API response were dropped.

The API refresh already runs regardless of builtin data and keeps the
cache current, so the cache write is removed. The fallback path for
all-zero builtin data keeps working with the real API cache.

Fixes daniel3303#50
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.

extra usage stat is not working

1 participant