Skip to content

fix(claude): sync OAuth cache on keychain changes#305

Draft
ratulsarna wants to merge 3 commits intomainfrom
sync-claude-cache-keychain
Draft

fix(claude): sync OAuth cache on keychain changes#305
ratulsarna wants to merge 3 commits intomainfrom
sync-claude-cache-keychain

Conversation

@ratulsarna
Copy link
Collaborator

Addresses the Claude OAuth cache/keychain mismatch case by re-detecting Claude keychain changes non-interactively on cache hits and syncing CodexBar's cached OAuth credentials when the access token changed.

  • Adds a no-UI Claude keychain fingerprint + 60s throttle to avoid repeated keychain touches
  • Respects the existing keychain prompt cooldown gate in Auto mode
  • Syncs CodexBar's in-memory + keychain cache when Claude keychain token changes
  • Adds focused unit tests for sync/no-sync behavior

Repro this fixes: create a newer Claude Code-credentials item with a different token; CodexBar used to keep serving com.steipete.codexbar.cache until expiry; now it syncs.

Commands run:

  • swiftformat Sources Tests
  • swiftlint --strict
  • pnpm check
  • ./Scripts/compile_and_run.sh

Detect and sync Claude OAuth credentials when the macOS keychain entry changes. Adds a ClaudeKeychainFingerprint struct, non-interactive keychain fingerprinting and data loaders, SHA-256 prefix hashing, and throttling to avoid frequent prompts. Integrates a syncWithClaudeKeychainIfChanged path into the existing load flow so cached credentials are updated only when the keychain token actually changes (and avoids regressing to expired tokens). Provides debug/testing overrides and reset helpers, and adds unit tests covering fingerprint-change-driven sync and no-op when the fingerprint is unchanged.
Improve Claude OAuth keychain handling and avoid unwanted keychain prompts. Renamed the stored fingerprint key to V2 and proactively remove the legacy V1 entry (which contained the account string) to reduce identifying data. Removed the account field from the fingerprint struct and added logic to read a legacy keychain candidate when needed. Load logic now consults only the newest candidate (matching fingerprint semantics) and preserves silent-probe behavior by honoring a new respectKeychainPromptCooldown gate when callers request no prompts. Updated callers (UsageStore, Provider descriptor, UsageFetcher) to pass the cooldown flag for silent loads. Added tests to cover expired keychain vs cached credentials and to ensure the prompt-cooldown gate is respected. Also added helpers and test cleanup for legacy fingerprint handling.
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