Skip to content

Claude "Avoid Keychain prompts": account switch leaves ~/.claude/.credentials.json missing → "OAuth credentials not found" while Keychain token is valid #1975

Description

@mcp10

TL;DR: With "Avoid Keychain prompts" enabled (debugDisableKeychainAccess = true), CodexBar reads Claude OAuth from the plaintext ~/.claude/.credentials.json instead of the Keychain. But after switching Claude accounts, Claude Code sometimes writes the new token only to the Keychain and not to ~/.claude/.credentials.json — the file goes missing entirely. CodexBar then shows "Claude OAuth credentials not found. Run claude to authenticate." even though a valid, non-expired token with the right scopes is sitting in the Keychain.

Every existing keychain/credentials issue I found is about the Keychain item being wrong or absent (#1844, #1823, #1161). This one is the opposite: the Keychain is fine; the file the avoid-keychain path depends on is the thing that disappears on account switch.

Environment

  • CodexBar 0.40.0 (build 99)
  • macOS 26.5.2 (25F84)
  • Claude Code CLI 2.1.197, Claude Max, logged in and working
  • Claude provider setting: Avoid Keychain prompts = ON (defaults read com.steipete.codexbar debugDisableKeychainAccess1)

Repro

  1. Enable Avoid Keychain prompts for the Claude provider (so CodexBar reads source=credentialsFile). Confirm usage loads.
  2. Switch Claude accounts in Claude Code (e.g. /login as a different account).
  3. Observe the Claude tab shows "Claude OAuth credentials not found. Run claude to authenticate."

Smoking gun

At the point of failure:

$ ls -la ~/.claude/.credentials.json
ls: /Users/…/.claude/.credentials.json: No such file or directory     # file is GONE

$ security find-generic-password -s "Claude Code-credentials" -a "$USER" -w | python3 -c '...'
has accessToken: True
scopes: ['user:file_upload', 'user:inference', 'user:mcp_servers', 'user:profile', 'user:sessions:claude_code']
expiresAt: 1783487829153 -> expired? False                            # Keychain token is VALID

So the Keychain has a healthy claudeAiOauth token; the plaintext file simply does not exist. Because keychain access is disabled, CodexBar has nothing to read and fails closed with "credentials not found."

codexbar usage --provider claude -v after recreating the file confirms the same token reads fine:

allowKeychainPrompt=false … hasUserProfileScope=true isExpired=false … source=memoryCache … credentials loaded for usage

Manual recovery (workaround)

Regenerate the file from the Keychain, then Refresh (⌘R):

security find-generic-password -s "Claude Code-credentials" -a "$USER" -w > ~/.claude/.credentials.json && chmod 600 ~/.claude/.credentials.json

Suggested fix

When Avoid Keychain prompts is enabled and ~/.claude/.credentials.json is missing/unreadable, fall back to a non-interactive Keychain read (the Security.framework no-UI policy from #1877) before surfacing "credentials not found" — i.e. read-only, never prompting. That would make the avoid-keychain path resilient to Claude Code writing the token to only one of the two stores after an account switch, without reintroducing prompts.

(Reported via a debugging session; happy to grab additional logs.)

Metadata

Metadata

Assignees

No one assigned

    Labels

    P2Normal priority bug or improvement with limited blast radius.clawsweeper:fix-shape-clearClawSweeper found a clear likely implementation shape for this issue.clawsweeper:needs-maintainer-reviewClawSweeper marked this issue as needing maintainer review before automation.clawsweeper:needs-product-decisionClawSweeper marked this issue as needing a product or behavior decision.clawsweeper:needs-security-reviewClawSweeper marked this issue as needing security-sensitive review.clawsweeper:no-new-fix-prClawSweeper does not recommend queueing a new automated fix PR for this issue.clawsweeper:source-reproClawSweeper found a high-confidence source-level issue reproduction.impact:auth-providerThis issue is about auth, provider routing, model choice, or SecretRef resolution.impact:securityThis issue is about security boundaries, credentials, authz, sandboxing, or sensitive data.impact:ux-frictionUser-facing flow adds avoidable confusion or support burden without fully blocking progress.issue-rating: 🦞 diamond lobsterVery strong issue quality with high-confidence source-level or clear reproduction.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions