Claude Code error
Claude Code: Please run /login · API Error: 401 OAuth token has expired
Please run /login · API Error: 401 OAuth token has expiredStatus: WorkaroundLast verified 4 documented fixes3 sources
What it means
Your saved login is no longer valid. A revoked token means you signed out everywhere or an admin removed access; an expired token means the automatic refresh failed mid-session. The revoked variant reads OAuth token revoked · Please run /login. In -p mode and the Agent SDK it reads Failed to authenticate. API Error: 401 OAuth token has expired.
Causes
- Signing out everywhere or an admin removing access
- Automatic token refresh failing mid-session
- An expired or revoked long-lived token in CLAUDE_CODE_OAUTH_TOKEN
- An inaccurate system clock (token validation depends on correct timestamps)
How to fix it
- Fix 1.
Run /login at the Claude Code prompt to sign in again.
Slash command/login - Fix 2.
For automation that cannot sign in interactively, authenticate with ANTHROPIC_API_KEY or generate a long-lived token.
Terminalclaude setup-token - Fix 3.
If you use CLAUDE_CODE_OAUTH_TOKEN, generate a fresh token with claude setup-token and restart with it, or unset the variable and run /login.
- Fix 4.
If prompted to log in repeatedly, check your system clock; on macOS run claude doctor and unlock the login Keychain if it reports macOS Keychain is not writable.
Snippetsecurity unlock-keychain ~/Library/Keychains/login.keychain-db
More Claude Code errors
All 18 Claude Code errorsAPI Error: 500 Internal server error. This is a server-side issue, usually temporaryStatus: WorkaroundAPI Error: Repeated 529 Overloaded errors. The API is at capacityStatus: WorkaroundAPI Error: 400 {"type":"error","error":{"type":"invalid_request_error","message":"messages.5: `tool_use` ids were found without `tool_result` blocks immediately after: toolu_01FRvEykWmCgrgJ22mvBbKhV. Each `tool_use` block must have a corresponding `tool_result` block in the next message."}}Status: OpenUnable to connect to API. Check your internet connectionStatus: WorkaroundUnable to connect to API: SSL certificate verification failed (UNABLE_TO_GET_ISSUER_CERT_LOCALLY).Status: WorkaroundOAuth error: timeout of 15000ms exceededStatus: OpenPrompt is too longStatus: WorkaroundYou've hit your session limit · resets 3:45pmStatus: By design
Related reading
- Agent Harness Lessons From a 500B-Token Decompile: Give Agents a PASS/FAIL OracleAgent harness lessons from a 500B+ token decompile: a byte-matching PASS/FAIL oracle beat the reviewer agent. How agents cheated it and what to copy.
- Claude Code Sends 33k Tokens Before Your Prompt - OpenCode Sends 7kClaude Code sends about 33k tokens before your prompt, OpenCode about 7k. The methodology, cache economics and the HN debate over whether the overhead pays off.
- Image Token Compression Is a Real Agent Cost LeverImage token compression cuts agent costs by rendering bulky context as images, but it is lossy. Where to use it, the byte-safety rule, and the evals it needs.
- Claude Code Token Burn Is an Observability ProblemClaude Code token burn is an observability problem. Why coding agents need cache-hit telemetry, spend ceilings and repro-grade usage logs, not a quota bar.
- Codeburn: The First TUI That Actually Shows Where Your Claude Max Subscription Is GoingCodeburn is a terminal dashboard for Claude Code and Cursor token spend. What it shows, where the data comes from, and how it ties into over-editing.
- Progressive Disclosure: How Claude Code Cut Token Usage by 98%Progressive disclosure lets agents load tools only when needed. How Cloudflare, Anthropic and Cursor cut token usage, and how to do it in Claude Code.
FAQ
What does "Please run /login · API Error: 401 OAuth token has expired" mean in Claude Code?
Your saved login is no longer valid. A revoked token means you signed out everywhere or an admin removed access; an expired token means the automatic refresh failed mid-session. The revoked variant reads OAuth token revoked · Please run /login. In -p mode and the Agent SDK it reads Failed to authenticate. API Error: 401 OAuth token has expired.
How do I fix "Please run /login · API Error: 401 OAuth token has expired"?
There are 4 documented fixes. Start with the first: Run /login at the Claude Code prompt to sign in again.
Is this Claude Code error fixed?
Status: Workaround. No release removes the cause. The documented fixes work around it. Affected versions: All versions. Before v2.1.211, waking from sleep could revoke the saved login across sessions; before v2.1.225, CLAUDE_CODE_OAUTH_TOKEN could be replaced mid-session by a short-lived token; v2.1.126 fixed a race that could clear a valid refresh token.
Sources
Last verified against 3 sources: official docs, maintainer replies and release notes.
Newsletter
Fixes for the tools you use, weekly
One email per week. New coding agent releases, what broke, and how developers are working around it.