Skip to content

fix: remove Anthropic OAuth token refreshes to protect Claude Code auth#531

Open
Pizzaface wants to merge 1 commit into
mainfrom
fix/remove-anthropic-token-refreshes
Open

fix: remove Anthropic OAuth token refreshes to protect Claude Code auth#531
Pizzaface wants to merge 1 commit into
mainfrom
fix/remove-anthropic-token-refreshes

Conversation

@Pizzaface
Copy link
Copy Markdown
Owner

PizzaPi was calling getApiKey('anthropic') which triggers OAuth token refresh, rotating the access/refresh token pair. This breaks Claude Code's own auth because its stored tokens become stale.

Changes

  • usage-auth.ts — Removed getRefreshedOAuthToken() entirely; only raw token reads remain
  • runner-usage-cache.ts — Replaced getRefreshedOAuthToken with getOAuthAccessToken for Anthropic and Codex
  • index.tspizzapi usage command now reads raw token instead of calling getApiKey()
  • worker.ts — Removed syncKeychainToAuthStorage() call that injected Claude Code's Keychain credentials
  • daemon.ts — Removed 2-minute periodic syncKeychainToAuthJsonFile sync loop
  • keychain-auth.ts — Removed sync/write functions; read-only functions remain

Why

When getApiKey(anthropic) runs, it uses the refresh token to get a new access token from Anthropic's OAuth endpoint. This rotates the token pair, invalidating the refresh token Claude Code itself holds. Claude Code's subsequent API calls fail because its stored token is now stale.

Verification

  • TypeScript: clean
  • Tests: 989 pass, 0 fail

PizzaPi was calling getApiKey('anthropic') which triggers OAuth token
refresh, rotating the access/refresh token pair. This breaks Claude Code's
own auth because its stored tokens become stale.

Changes:
- Removed getRefreshedOAuthToken entirely — raw token reads only
- Removed keychain credential sync (syncKeychainToAuthStorage,
  syncKeychainToAuthJsonFile) from worker and daemon
- Replaced getApiKey calls with getOAuthAccessToken in usage cache and CLI
- Updated tests accordingly
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