Claude Code "Failed to Authenticate" (401 and 403): How to Fix It
Claude Code error failed to authenticate (401 or 403)? Usually an expired login or a stale ANTHROPIC_API_KEY overriding your subscription. How to fix it.
"Failed to authenticate" in Claude Code means the API rejected the credential Claude Code sent. The two most common causes are an expired or revoked login (fix: run /login) and an old ANTHROPIC_API_KEY in your environment quietly overriding your Claude subscription (fix: unset ANTHROPIC_API_KEY, then restart). Run /status first: it tells you which credential is actually in use, and that decides which fix applies.
Error messages and behaviour below are from Anthropic's authentication docs, error reference and login troubleshooting as of November 2026.
Step one: run /status
Inside Claude Code, type:
/status
Look at the login rows. You'll see whether you're signed in with a claude.ai account (Pro, Max, Team, Enterprise), a Claude Console account, an API key, or something else. When both a login and an API key are configured, /status marks the one that isn't being used.
If you can't start a session at all, check your environment from the shell instead:
env | grep ANTHROPIC
On Windows PowerShell: Get-ChildItem Env:ANTHROPIC*.
The messages you might see
The wording depends on the cause and on whether you're in an interactive session or running claude -p. These are the ones the docs list:
| Message | Most likely cause |
|---|---|
Not logged in · Please run /login |
No credential at all |
Login expired · Please run /login |
Saved login couldn't be refreshed |
OAuth token revoked · Please run /login |
You signed out everywhere, or an admin removed access |
Please run /login · API Error: 401 OAuth token has expired |
Refresh failed mid-session |
Failed to authenticate: OAuth token revoked... |
Same as above, in -p mode or the Agent SDK |
Please run /login · API Error: 401 Invalid authentication credentials |
Credential revoked, or the account/org is disabled |
Invalid API key · Fix external API key |
The key in ANTHROPIC_API_KEY (or apiKeyHelper) was rejected |
Your ANTHROPIC_API_KEY belongs to a disabled organization |
A stale key is overriding your subscription |
API Error: 403 Request not allowed |
Subscription, role or proxy problem |
Cause 1: your login expired or was revoked
A claude.ai login refreshes itself in the background. If the refresh fails, or you signed out on another device, or an admin removed you, requests start failing with 401.
Fix:
/login
If that doesn't stick, do a clean reset, which is the docs' recommended first move when the cause is unclear:
- Run
/logout - Quit Claude Code
- Start
claudeagain and sign in
Note that /logout removes all stored credentials, including saved MCP server logins, so you may have to re-authorize those afterwards.
If you're asked to log in over and over, check that your system clock is correct. Token validation depends on accurate timestamps, and a drifting clock on a VM or dual-boot machine is a classic cause.
Claude Code also warns you in advance: when a claude.ai login is within three days of expiring, you get Your login expires in 3 days · run /login to renew at startup.
Cause 2: ANTHROPIC_API_KEY is overriding your subscription
This one catches a lot of people. Claude Code picks a credential in a fixed order, and an ANTHROPIC_API_KEY environment variable (once you've approved it) ranks above your /login subscription. The order, from the docs:
- Cloud provider credentials (Bedrock, Vertex, Foundry), when enabled
ANTHROPIC_AUTH_TOKENANTHROPIC_API_KEYapiKeyHelperscript outputCLAUDE_CODE_OAUTH_TOKEN(fromclaude setup-token)- Anthropic profile and federation credentials
- Your
/loginsubscription
So if an old key from a previous job, a side project or a .env file is still exported, Claude Code uses it instead of your Pro or Max plan. If that key is revoked, or belongs to an organization that's been disabled, every request fails, and running /login doesn't help because the key still wins. In non-interactive mode (claude -p), the key is always used when present, without asking.
Fix:
unset ANTHROPIC_API_KEY
claude
PowerShell: Remove-Item Env:ANTHROPIC_API_KEY.
Then make it permanent. Look for export ANTHROPIC_API_KEY=... in ~/.zshrc, ~/.bashrc or ~/.profile (on Windows, your $PROFILE and User environment variables) and remove it. Also check for tools that load it automatically: the docs call out direnv, dotenv shell plugins and IDE terminals reading a .env file in your project. Open a new terminal and run /status to confirm the subscription is active.
If you do want to use an API key, create a new one in the Claude Console and replace the old value. How to get a Claude API key walks through it. If you approved a key once and want to change your mind, the "Use custom API key" toggle in /config controls it (it only appears while the variable is set).
Cause 3: the API key itself is invalid
Invalid API key means the key was rejected, or Claude Code blocked it before sending. Check for:
- Typos and copy-paste damage. A key copied with a line break or trailing space gets refused. The docs show a variant of the message that says exactly which character is the problem.
- A revoked key. Check the Console's API keys page. If you revoked it because it leaked, good; see leaked API key: what to do if you haven't.
- An
apiKeyHelperscript printing something other than a key. Run the script yourself and look at its output.
Cause 4: organization and role restrictions (often 403)
API Error: 403 Request not allowed after a successful login usually means you're authenticated but not allowed. The docs list:
- Pro, Max or Ultra: the subscription has lapsed. Check claude.ai/settings.
- Claude Console accounts: your user needs the "Claude Code" or "Developer" role, assigned by an admin on the Console's Members page.
- Team and Enterprise: an admin may not have granted you Claude Code access. Some orgs disable subscription logins for Claude Code, or disable API keys. Those show their own messages, such as
Your organization has disabled API key authentication, and can't be overridden locally. Ask your admin.
If the same 401 Invalid authentication credentials returns right after a fresh /login, the account or organization behind it is no longer active. That's an admin or support question, not something to fix on your machine.
Cause 5: proxies, VPNs and corporate networks
A corporate proxy or TLS-inspecting firewall can block or alter requests to Anthropic's API, which can show up as a 403 or a connection or certificate error instead of a clean auth failure.
Check:
curl -I https://api.anthropic.com
If that fails, the problem is the network, not your login.
- Proxy required: set
HTTPS_PROXYbefore startingclaude. - Certificate errors (
SSL certificate verification failed,unable to get local issuer certificate): point Claude Code at your company's CA bundle withNODE_EXTRA_CA_CERTS=/path/to/ca-bundle.pem. Don't setNODE_TLS_REJECT_UNAUTHORIZED=0; the docs specifically warn against it because it turns off certificate checking entirely. - Leftover
ANTHROPIC_BASE_URL: if it points to a gateway or local proxy that's no longer running, requests go there instead of Anthropic. If it points to a working gateway, a 401 comes from the gateway, and/loginwon't change it.
Cause 6: region availability
If you see a 403 or App unavailable in region during install or login, Claude Code may not be available in your country. Anthropic keeps a supported countries list. A 403 with no explanation can also come from a corporate firewall, so rule that out first.
Logging in on a remote server, WSL or a container
If the browser opens on the wrong machine or ends on a localhost error, you don't need to fix the redirect. At the login prompt, press c to copy the login URL, open it in a browser on your own computer, and paste the code it shows back into the terminal. claude auth login does the same from the shell. For CI or scripts where no browser is available, claude setup-token generates a long-lived token you set as CLAUDE_CODE_OAUTH_TOKEN (it requires a Pro, Max, Ultra, Team or Enterprise plan).
For other startup problems, see Claude Code not working. For choosing between a plan and API billing, see Claude Pro vs Max vs API.
EasySpawn runs Claude Code on a cloud server using your own Anthropic API key (subscription logins aren't supported on servers), so there's one credential to manage and no stale shell exports to fight. See how it works or join the waitlist.
Related: How to Get a Claude API Key (and Keep It Safe) · I Leaked an API Key. What Now? A Step-by-Step Response · Claude Code Not Working? Fixes for the Most Common Problems · Claude Pro vs Max vs API Key for Claude Code: Which Should You Pay For?
Keep reading
Claude Code "Error Editing File": Why Edits Fail and How to Fix Them
Claude Code error editing file or writing file? The Edit tool needs an exact, unique match against the current file. The usual causes and how to fix them.
Claude Code "Prompt Is Too Long": Why It Happens and How to Fix It
"Prompt is too long" and "Context limit reached" mean the conversation no longer fits in the model's context window. What fills it up, how to see what's using space with /context, and the fixes: /compact, /clear, smaller reads, fewer MCP tools and better session habits.