[BUG] Stale ~/.claude/.credentials.json causes "OAuth token has expired" even when a valid CLAUDE_CODE_OAUTH_TOKEN env var is set
Preflight Checklist
- [x] I have searched existing issues and this hasn't been reported yet
- [x] This is a single bug report (please file separate reports for different bugs)
- [x] I am using the latest version of Claude Code
What's Wrong?
Bug Description
Documentation states that CLAUDE_CODE_OAUTH_TOKEN (from claude setup-token) should take precedence over ~/.claude/.credentials.json. In practice, with both present, Claude Code reported "OAuth token has expired. Please run /login" — even though CLAUDE_CODE_OAUTH_TOKEN was valid and set correctly in the environment. Deleting ~/.claude/.credentials.json (leaving the env var untouched) immediately resolved the issue with no other changes.
Expected behavior
Per docs, CLAUDE_CODE_OAUTH_TOKEN should be used whenever set, regardless of what's in .credentials.json — the file's contents (fresh or stale) shouldn't affect whether the env-var token is accepted.
Actual behavior
Presence of a stale .credentials.json appears to cause the CLI to report an expired token even when a separately-supplied env var token is valid.
rm ~/.claude/.credentials.json, run claude again with no other changes — works immediately.
What Should Happen?
Expected behavior
Per docs, CLAUDE_CODE_OAUTH_TOKEN should be used whenever set, regardless of what's in .credentials.json — the file's contents (fresh or stale) shouldn't affect whether the env-var token is accepted.
Actual behavior
Presence of a stale .credentials.json appears to cause the CLI to report an expired token even when a separately-supplied env var token is valid.
Error Messages/Logs
something like this:
OAUTH token expired. please /login to reauthenticate
Steps to Reproduce
Generate a long-lived token via claude setup-token, export it as CLAUDE_CODE_OAUTH_TOKEN.
Have a pre-existing ~/.claude/.credentials.json on the same machine (e.g. from an earlier /login session, possibly expired/stale).
Run claude — it reports the OAuth token as expired and prompts for /login, despite the env var being valid.
rm ~/.claude/.credentials.json, run claude again with no other changes — works immediately.
Claude Model
None
Is this a regression?
Yes, this worked in a previous version
Last Working Version
_No response_
Claude Code Version
2.1.220 (Claude Code)
Platform
Anthropic API
Operating System
Ubuntu/Debian Linux
Terminal/Shell
Other
Additional Information
Auth method: CLAUDE_CODE_OAUTH_TOKEN via setup-token, Max plan