Shipping an AI app or agent? Security review in 1 working day: $149 / ₹13,900. Request a review →
AI Review Ready
Home / Error fixes / Failed to authenticate / 403
Fix · Claude Code · login

Claude Code: Failed to authenticate and 403 errors

These errors mean Claude Code can't prove who you are to the API, or the account it used isn't allowed in. Usually a saved login expired, or an old ANTHROPIC_API_KEY is being used instead of your subscription.

Fix it

  1. See which credential is active. Inside Claude Code run /status. It shows whether you are on your claude.ai login, an ANTHROPIC_API_KEY, or a CLAUDE_CODE_OAUTH_TOKEN.
  2. 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 in claude -p it is always used when present.
    # macOS / Linux
    unset ANTHROPIC_API_KEY
    # Windows PowerShell
    Remove-Item Env:ANTHROPIC_API_KEY
    Then delete the export ANTHROPIC_API_KEY=... line from ~/.zshrc, ~/.bashrc or ~/.profile (on Windows: your $PROFILE and User environment variables), and start claude again.
  3. Reset the login: run /logout, close Claude Code, start claude and sign in again.
  4. 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.
  5. For scripts and CI, don't depend on a browser login: use ANTHROPIC_API_KEY, or generate a long-lived token with claude setup-token and pass it as CLAUDE_CODE_OAUTH_TOKEN.

Which message, which cause

You seeCauseFix
OAuth token revoked · Please run /login
Failed 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 expiredThe automatic token refresh failed mid-session/login
Login expired · Please run /login
Failed 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 credentialsCredential 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 keyThe key in ANTHROPIC_API_KEY or from apiKeyHelper was rejectedCheck it in the Console, or unset it and /login
Your ANTHROPIC_API_KEY belongs to a disabled organizationA stale key from an old employer or projectUnset it (step 2)
API Error: 403 Request not allowedInactive subscription, missing Console role, or a proxyStep 4
Claude Code access has not been granted for this accountClaude Enterprise: your role is Custom and no custom role grants Claude CodeAn 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 start claude from. Tools such as direnv, dotenv shell plugins and IDE terminals can load a stale key from a project .env file without you noticing.
  • If ANTHROPIC_BASE_URL points at an LLM gateway, the text after 401 is the gateway's message, and /login won'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 c at 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 here prompt. If pasting does nothing, run claude 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

Sources

Read 29 Nov 2026. These tools change often: if a step no longer matches, the linked page wins.

Related free tools