Fix it
- See which credential is active. Inside Claude Code run
/status. It shows whether you are on your claude.ai login, anANTHROPIC_API_KEY, or aCLAUDE_CODE_OAUTH_TOKEN. - If an API key is active and you meant to use your subscription, remove it. Once approved, a key in your environment wins over
/login, and inclaude -pit is always used when present.
Then delete the# macOS / Linux unset ANTHROPIC_API_KEY # Windows PowerShell Remove-Item Env:ANTHROPIC_API_KEYexport ANTHROPIC_API_KEY=...line from~/.zshrc,~/.bashrcor~/.profile(on Windows: your$PROFILEand User environment variables), and startclaudeagain. - Reset the login: run
/logout, close Claude Code, startclaudeand sign in again. - For
API Error: 403 Request not allowed: Pro/Max/Ultra users, check the subscription is active at claude.ai/settings. Console users need the "Claude Code" or "Developer" role, which an admin sets on the Console's Members page. Behind a corporate proxy, set up the proxy as in Claude Code's network configuration docs. - For scripts and CI, don't depend on a browser login: use
ANTHROPIC_API_KEY, or generate a long-lived token withclaude setup-tokenand pass it asCLAUDE_CODE_OAUTH_TOKEN.
Which message, which cause
| You see | Cause | Fix |
|---|---|---|
OAuth token revoked · Please run /loginFailed to authenticate: OAuth token revoked. Please log in again or contact your administrator. | You signed out everywhere, or an admin removed access | /login |
Please run /login · API Error: 401 OAuth token has expired | The automatic token refresh failed mid-session | /login |
Login expired · Please run /loginFailed to authenticate: OAuth session expired and could not be refreshed | The stored refresh token was rejected, so the saved login was cleared | /login |
Please run /login · API Error: 401 Invalid authentication credentials | Credential recently revoked, or the organization or account is no longer active | /status first: rotate or unset the key if one is active, else /login once; if it returns, ask your admin |
Invalid API key · Fix external API key | The key in ANTHROPIC_API_KEY or from apiKeyHelper was rejected | Check it in the Console, or unset it and /login |
Your ANTHROPIC_API_KEY belongs to a disabled organization | A stale key from an old employer or project | Unset it (step 2) |
API Error: 403 Request not allowed | Inactive subscription, missing Console role, or a proxy | Step 4 |
Claude Code access has not been granted for this account | Claude Enterprise: your role is Custom and no custom role grants Claude Code | An organization Owner must grant it; nothing in Claude Code fixes this |
In claude -p and the Agent SDK these show as Failed to authenticate: ... with the structured error code authentication_failed.
How to check which cause you have
- Run
env | grep ANTHROPIC(PowerShell:Get-ChildItem Env:ANTHROPIC*) in the same shell you startclaudefrom. Tools such as direnv, dotenv shell plugins and IDE terminals can load a stale key from a project.envfile without you noticing. - If
ANTHROPIC_BASE_URLpoints at an LLM gateway, the text after401is the gateway's message, and/loginwon't change it: fix the credential the gateway expects. - If you are asked to log in again and again, check your system clock: token validation depends on correct timestamps.
The browser login itself fails
- Browser didn't open: press
cat the login prompt to copy the URL and open it yourself. - WSL2, SSH or containers: open the copied URL in your local browser, sign in, then paste the code it shows at the
Paste code hereprompt. If pasting does nothing, runclaude auth login, which reads the code from standard input. OAuth error: Invalid code: the code expired or was cut off when copied. Retry and paste the whole code quickly.
Still at the install stage? See Install Claude Code on Windows.
Running Claude Code, Codex or Cursor on real repos, or shipping an AI agent? A Quick Review ($149 / ₹13,900, 1 working day) checks one repo, config or setup for leaked keys, risky agent permissions and MCP servers. Request a Quick Review
FAQ
Why does Claude Code use my API key instead of my Pro or Max subscription?
When ANTHROPIC_API_KEY is set and approved, Claude Code uses it instead of your subscription login, and in claude -p it is always used when present. Unset the variable and remove it from your shell profile.
What does 'API Error: 403 Request not allowed' mean in Claude Code?
Anthropic's docs list three causes: an inactive Pro/Max/Ultra subscription, a Console account without the Claude Code or Developer role, or a corporate proxy interfering with requests.
How do I log in to Claude Code over SSH or in WSL2?
Copy the login URL (press c), open it in a browser on your own machine, sign in, and paste the code it shows into the terminal. claude auth login reads the code from standard input if pasting fails.
How do I authenticate Claude Code in CI?
Use ANTHROPIC_API_KEY, or create a long-lived token with claude setup-token and pass it as CLAUDE_CODE_OAUTH_TOKEN.
Related errors
- Claude Code not working in VS Code
- Claude API error 529 overloaded_error
- MCP error -32000: Connection closed
Sources
Read 29 Nov 2026. These tools change often: if a step no longer matches, the linked page wins.
- Claude Code docs: Error reference: code.claude.com/docs/en/errors
- Claude Code docs: Troubleshoot installation and login: code.claude.com/docs/en/troubleshoot-install
- Exposed API key checker: find API keys committed to a repo or shipped to the browser
- CLAUDE.md security check: find risky instructions in agent rules files
- Install Claude Code on Windows: commands and install error fixes