Skip to content

fix: usage page OAuth token refresh and keychain access - #42

Merged
zhnd merged 2 commits into
mainfrom
fix/usage-oauth-refresh
Apr 12, 2026
Merged

fix: usage page OAuth token refresh and keychain access#42
zhnd merged 2 commits into
mainfrom
fix/usage-oauth-refresh

Conversation

@zhnd

@zhnd zhnd commented Apr 11, 2026

Copy link
Copy Markdown
Owner

Summary

  • Fix usage page showing "Claude Code login required" in release builds by switching macOS Keychain access from security CLI subprocess to native security-framework crate (with CLI fallback for account name compatibility)
  • Implement OAuth token refresh via platform.claude.com using the stored refresh token, with 5-min pre-expiry buffer and enhanced retry strategy (reload from file/keychain on auth failure to pick up externally refreshed tokens)
  • Add CLI fallback (claude /usage) when the OAuth API probe fails, with ANSI-stripping text parser
  • Add in-memory credential cache (5-min TTL) to avoid repeated Keychain/file I/O
  • Preserve original Keychain account name on save to avoid creating duplicate entries
  • Add subscription type badge (MAX/PRO/API) displayed as a gradient banner on the usage page

Test plan

  • pnpm tauri:dev — usage page loads with refreshed token and shows subscription banner
  • pnpm tauri build — release .app prompts for Keychain access on first launch, then usage works
  • Verify CLI fallback: disconnect network, confirm claude /usage output is parsed
  • Verify token refresh: wait for token to expire, confirm auto-refresh and credential persistence

🤖 Generated with Claude Code

zhnd and others added 2 commits April 11, 2026 20:48
The usage page showed "Claude Code login required" in release builds due
to multiple issues: the macOS Keychain couldn't be accessed from the app
bundle, and the OAuth access token expired without being refreshed.

Key changes:
- Switch Keychain access from `security` CLI subprocess to native
  `security-framework` crate with CLI fallback for account compatibility
- Implement OAuth token refresh via platform.claude.com using the stored
  refresh token (5-min pre-expiry buffer, same as ClaudeBar)
- Add CLI fallback (`claude /usage`) when the API probe fails
- Add in-memory credential cache (5-min TTL) to avoid repeated I/O
- Enhanced retry: reload from file/keychain on auth failure (picks up
  tokens refreshed externally by Claude Code CLI)
- Preserve original Keychain account name on save to avoid duplicate
  entries
- Add subscription type badge (MAX/PRO/API) to the usage page UI
- Display subscription tier as a gradient banner in the main content

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
…inux

Add cfg_attr guards for KEYCHAIN_SERVICE, Keychain variant, and
keychain_account field that are only used in #[cfg(target_os = "macos")]
blocks but flagged as dead code on Linux CI.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@zhnd
zhnd merged commit b5ded19 into main Apr 12, 2026
2 checks passed
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