Skip to content

Persist usage data to disk for busy-mode display#20

Merged
himattm merged 2 commits intomainfrom
himattm/persist-usage-cache
Mar 1, 2026
Merged

Persist usage data to disk for busy-mode display#20
himattm merged 2 commits intomainfrom
himattm/persist-usage-cache

Conversation

@himattm
Copy link
Owner

@himattm himattm commented Feb 28, 2026

Summary

  • Usage plugin only fetches data from the API when idle, but each Prism render is a new process with an empty in-memory cache
  • During busy mode (Claude actively responding), usage data was lost and the plugin fell back to showing cost ($0.35) instead of usage limits (3h20m:55% 7d:6%)
  • Added disk-based caching (prism-usage-cache in temp dir) following the same pattern as UpdatePlugin, so last-known usage data persists across process invocations

Test plan

  • Unit tests for loadUsageCache/saveUsageCache round-trip
  • Unit test for missing cache file
  • Unit test for nil input
  • Full test suite passes (go test ./...)
  • Manual verification: idle render populates disk cache, busy render reads from disk cache and shows usage limits

🤖 Generated with Claude Code

Matt McKenna and others added 2 commits February 28, 2026 18:33
Each Prism status line render is a new process with an empty in-memory
cache. Usage data was only fetched when idle, so during active Claude
use it fell back to showing cost instead of usage limits. This adds
disk-based caching so the last-known usage data persists across
process invocations.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Reject cached usage data older than 5 minutes to prevent showing
stale limits after resets. Also improve test assertions and cleanup.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@himattm himattm merged commit 6a5b489 into main Mar 1, 2026
1 check passed
@himattm himattm deleted the himattm/persist-usage-cache branch March 1, 2026 01:18
@himattm himattm mentioned this pull request Mar 1, 2026
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