Skip to content

fix: refresh quota when the Claude account is switched (#45) - #47

Merged
Carl723000 merged 1 commit into
mainfrom
fix/account-switch-quota
Jun 30, 2026
Merged

Carl723000 merged 1 commit into
mainfrom
fix/account-switch-quota

Conversation

@Carl723000

Copy link
Copy Markdown
Collaborator

What

Fixes #45 — after switching Claude accounts the status bar stayed on the previous account's quota until a Developer: Reload Window.

Root cause

ClaudeApiClient.getValidCredentials() cached the OAuth credentials in memory and only re-read them from disk when the token expired. A switched-in account has a valid (non-expired) token, so that path never fired — the client kept calling /usage with the old account's token.

Fix

  • Re-read credentials on every quota fetch (file or macOS Keychain), falling back to the cached copy only if the fresh read transiently fails.
  • Watch ~/.claude/.credentials.json and expire the cached quota on change, so the switch is reflected within a refresh tick instead of after a full cache interval (≤120 s). Keychain-stored credentials (macOS) have no file to watch — those self-correct on the next tick.

Local usage token counts come from a shared local folder and were never affected — this only touches the account-level quota panel.

Notes

  • No new dependencies; follows the existing fs.watch pattern (projects-dir watcher) with disposal in dispose().
  • The api client's own 429 cool-down still protects the /usage endpoint when the cache is force-expired.
  • tsc clean; node --test green (11/11).

🤖 Generated with Claude Code

The OAuth credentials were cached in memory and only re-read when the token
expired. A switched-in account has a *valid* token, so that path never fired
and the quota stayed on the previous account's numbers until a window reload.

Re-read the credentials (file or macOS Keychain) on every quota fetch, and
watch ~/.claude/.credentials.json so the switch is reflected promptly rather
than after a full cache interval. The status-bar usage token counts come from
a shared local folder and were never affected.

Closes #45

Co-Authored-By: Claude <noreply@anthropic.com>
@Carl723000
Carl723000 requested a review from jack21 as a code owner June 30, 2026 11:54
@Carl723000
Carl723000 merged commit dbe2be7 into main Jun 30, 2026
1 check passed
Carl723000 added a commit to henrique-carvalho-dev/ClaudeCodeUsage that referenced this pull request Jun 30, 2026
Brings in ClaudeCodeUsage#43 (session actions + clean quota), ClaudeCodeUsage#46 (pricing), ClaudeCodeUsage#47
(account-switch fix). Adds the pt-BR translations for the session-row
action strings ClaudeCodeUsage#43 introduced (copy id / copy path / resume / delete +
filters) so the pt-BR locale stays complete.

Co-Authored-By: Claude <noreply@anthropic.com>
@Carl723000
Carl723000 deleted the fix/account-switch-quota branch June 30, 2026 18:17
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.

Extension doesn't update when switching accounts — stuck on previous account's data

1 participant