Claude Code · Sign-in
OAuth token has expired / OAuth token revoked
Fix “OAuth token has expired” and “OAuth token revoked” in Claude Code: sign in again, refresh setup tokens and keep automation running.
Message
The exact error
Please run /login · API Error: 401 OAuth token has expired ...Also appears as:
- Revoked
- OAuth token revoked · Please run /login
- Non-interactive mode (-p) and the Agent SDK
- Failed to authenticate. API Error: 401 OAuth token has expired ...
- Revoked, in -p and the Agent SDK
- Failed to authenticate: OAuth token revoked. Please log in again or contact your administrator.
- Revoked, in -p and the Agent SDK before v2.1.287
- Your account does not have access to Claude. Please login again or contact your administrator.
Meaning
What does “OAuth token has expired” mean?
Claude Code signs in with OAuth and refreshes the token automatically. “Expired” means a refresh failed mid-session; “revoked” means you signed out everywhere or an admin removed access. Either way the saved login is no longer accepted. Both messages report a rejection the API returned for a request; in -p mode and the Agent SDK the structured error code is authentication_failed.
Causes
Why does my Claude Code token expire or get revoked?
- A refresh failure, for example after the computer slept or the network dropped
- Signing out of all devices, or an admin revoking access
- An expired or revoked long-lived token in
CLAUDE_CODE_OAUTH_TOKEN
Fix
How do I fix an expired or revoked OAuth token?
Sign in again
Run
/loginat the Claude Code prompt.For -p commands and SDK programs
Run
claudein the same environment and complete/login, then rerun your command. For automation, use an API key or generate a long-lived token withclaude setup-token.If you use CLAUDE_CODE_OAUTH_TOKEN
Claude Code keeps sending the value you set, so a fresh
/logindoesn’t replace it in new sessions./statusshows this credential as anAuth tokenrow readingCLAUDE_CODE_OAUTH_TOKEN. Generate a fresh token withclaude setup-tokenand restart with it, or remove the variable from your shell profile or settingsenvblock and use/login.If it keeps happening
Check that your system clock is set automatically. See Not logged in for the macOS Keychain fix.
Explained
Is “Login expired · Please run /login” the same thing?
Close, but not the same state. Login expired · Please run /login (in -p mode, Failed to authenticate: OAuth session expired and could not be refreshed) is Claude Code’s own message: it already tried to renew your saved login, the renewal was rejected, and it cleared the stored credentials, so it sends no request until you sign in. The fix is the same: run /login. In this state /status shows a Login row marked as expired, with the organisation and email of the old login.
Explained
Why does my token expire during long or unattended runs?
A login from /login lasts a limited time, and Claude Code warns at startup when it is within three days of expiring: Your login expires in 3 days · run /login to renew. A background session or Remote Control session that outlives the login stops making progress until you sign in again, so renew before leaving long jobs running.
For CI and scripts, don’t rely on an interactive login: use ANTHROPIC_API_KEY, or run claude setup-token to get a one-year token and set it as CLAUDE_CODE_OAUTH_TOKEN. On versions before v2.1.211, waking the machine from sleep could make two sessions renew with the same token, which revoked the saved login in every open session; updating Claude Code fixes that.
FAQ
Questions people ask
Do Claude Code OAuth tokens expire?
Yes. Claude Code refreshes your login automatically, and you only see an error when that refresh fails, for example after sleep or a network drop, or when the login was revoked. Claude Code warns three days before a saved login expires. For unattended jobs, use ANTHROPIC_API_KEY or a one-year token from claude setup-token instead of an interactive login.
What is the difference between “OAuth token has expired” and “Login expired”?
“OAuth token has expired” and “OAuth token revoked” report a rejection the API returned for a request. “Login expired · Please run /login” is Claude Code’s own message after the renewal of your saved login was rejected and it cleared the stored credentials, so it sends no request until you run /login. The fix for both is to sign in again.
Why does /login not fix the 401 OAuth token error?
If CLAUDE_CODE_OAUTH_TOKEN is set, Claude Code keeps sending that value, and new sessions read it again even after a fresh /login. Run /status: an Auth token row reading CLAUDE_CODE_OAUTH_TOKEN confirms it. Generate a new token with claude setup-token, or remove the variable from your shell profile and log in. Also check your system clock is set automatically.
Related
Related errors
Keep exploring