← Blog · 2026-10-23
Claude Code Login Not Working? 12 Causes and Fixes
30-second test: run
/statusinside Claude Code, orclaude auth status --textfrom your shell (it exits 0 when you're logged in, 1 when you're not). If it shows anAPI key,apiKeyHelperorAuth tokensource you didn't expect, jump to causes 5, 8 and 12. If it shows no credential at all, start at cause 1.
Claude Code can authenticate with several credentials at once: a claude.ai subscription login, a Claude Console login, an ANTHROPIC_API_KEY, an apiKeyHelper script, a long-lived CLAUDE_CODE_OAUTH_TOKEN or a cloud provider. Most "login not working" problems are either the browser sign-in failing to get back to the terminal, or the login working fine while a different credential quietly wins.
First: which credential is Claude Code using?
When several credentials are present, Claude Code picks one in this order: cloud provider (when CLAUDE_CODE_USE_BEDROCK, CLAUDE_CODE_USE_VERTEX or CLAUDE_CODE_USE_FOUNDRY is set), then ANTHROPIC_AUTH_TOKEN, then ANTHROPIC_API_KEY, then apiKeyHelper, then CLAUDE_CODE_OAUTH_TOKEN, then Anthropic profile and federation credentials, and last the subscription login you made with /login. So your /login is the credential that loses to everything else. /status shows the one in use and, when a login and an API key are both configured, marks the one that isn't. The JSON from claude auth status has an authMethod field: none, claude.ai, oauth_token, api_key, api_key_helper or third_party.
- The browser sign-in never completes: causes 1 to 4.
- You signed in, but requests fail with 401, 400 or 403: causes 5 to 9.
- It keeps asking you to log in again, or works only interactively: causes 10 to 12.
When the cause isn't clear, a clean reset fixes most cases: run /logout, close Claude Code, start claude again and complete the login.
The browser sign-in never completes: 4 causes
- The browser didn't open, or the link can't be clicked. Press
cat the login prompt to copy the login URL and paste it into a browser yourself. This also works when the URL wraps across lines in a narrow or SSH terminal.claude auth loginprints the URL too. When it finishes, the terminal showsLogin successfuland asks you to pressEnter. - You're on WSL2, SSH or in a container. The browser opens on a different machine, so its redirect can't reach Claude Code's local callback server. After you sign in, the browser shows a code instead of redirecting back: paste it into the terminal at the
Paste code here if promptedprompt. If no browser opens from WSL2 at all, setBROWSERto your Windows browser, for exampleexport BROWSER="/mnt/c/Program Files/Google/Chrome/Application/chrome.exe". If pasting does nothing, your terminal's paste shortcut isn't reaching the prompt: try right-click or Shift+Insert in Windows Terminal, or runclaude auth login, which reads the pasted code from standard input. - "OAuth error: Invalid code. Please make sure the full code was copied". The code expired or was cut off when you copied it. Press Enter to retry and finish quickly after the browser opens. On a remote or SSH session, the browser may have opened on the wrong machine; copy the URL from the terminal and open it in your local browser.
- Claude Code can't listen on 127.0.0.1. The sign-in returns through a local port. If a sandbox or security software blocks it, you see
The browser can't return the sign-in to Claude Code automatically: just open the URL shown, sign in and paste the code atPaste code here >. If you seeCouldn't start the local listener that receives the browser sign-in, run the command again, and if it stops the same way, use a token or API key instead (see cause 12). Piping input intoclaude auth logincauses this too; run it in a real terminal. Before v2.1.305 this failed withFailed to start OAuth callback server, so update.
Signed in, but requests fail: 5 causes
- An old
ANTHROPIC_API_KEYis overriding your subscription. This is the classic one.API Error: 400 ... "This organization has been disabled"while your subscription is active usually means a key from an old job or project is still exported.Please run /login · API Error: 401 Invalid authentication credentialscan be the same thing: if/statusshows anAPI keyrow that isn't marked as not in use, the key is what's being rejected. In interactive mode Claude Code asks once whether to use the key and remembers your answer; with-pit always uses the key when present./logindoesn't replace an approved key. Fix:unset ANTHROPIC_API_KEY(PowerShell:Remove-Item Env:ANTHROPIC_API_KEY), then remove theexportline from~/.zshrc,~/.bashrcor~/.profile(on Windows, your$PROFILEand User environment variables). Runenv | grep ANTHROPICtoo: direnv, dotenv shell plugins and IDE terminals can load a stale key from a project.envfile. The Use custom API key toggle in/configchanges your earlier approval while the variable is set. API Error: 403 Request not allowedafter login. For Pro or Max, check that your subscription is active at claude.ai/settings. For Console accounts, your account needs the "Claude Code" or "Developer" role, which an admin assigns on the Console Members page. Behind a corporate proxy, the proxy may be interfering; see Anthropic's network configuration page.- "Claude Code access has not been granted for this account". If the sign-in page shows this after you log in, your Claude Enterprise organization gave you the Custom role and none of your groups' custom roles includes Claude Code. Nothing in Claude Code fixes it: ask an Owner of your organization to grant a role with Claude Code access, then run
claudeand log in again. - An
apiKeyHelperscript is failing. If your settings name anapiKeyHelper, its output outranks your saved login for as long as the setting exists, so/logindoesn't help.Your apiKeyHelper script is failingappears within three attempts when the command errors, times out, prints nothing or prints something other than the key. Fix: run the command yourself in a shell; it must print only the key to stdout and exit 0. If it reports an expired session, sign in to your SSO or vault again./statusshows anapiKeyHelperrow readingFailingwith the error output. To find which settings file defines it, our free settings precedence checker shows which file wins. - Your organization restricts the login. An admin can set
forceLoginMethod("claudeai"or"console") andforceLoginOrgUUIDin managed settings. Then a login from another organization is reported as an error, the login prompt can reappear even after an earlier sign-in, and with"claudeai"an API key from an earlier Console login doesn't count as signed in (and the reverse with"console"). Environment credentials such asANTHROPIC_API_KEY,ANTHROPIC_AUTH_TOKENandapiKeyHelperare blocked at startup under these keys. Fix: log in with the account type and organization the policy names, or ask your admin to add you.
It keeps asking you to log in: 3 causes
- The login expired.
Login expired · Please run /loginmeans Claude Code tried to renew your saved claude.ai login, the refresh was rejected and the credentials were cleared;OAuth token revokedor401 OAuth token has expiredmeans the API rejected it. Run/login. Claude Code warns three days ahead withYour login expires in 3 days · run /login to renew, and/statusshows aLoginrow readingExpired — log in again. If it happens often, check that your system clock is accurate, since token validation depends on it.Could not refresh your login because another Claude Code process is refreshing itisn't a rejection: wait a minute, close other Claude Code windows, or run/login. - The macOS Keychain won't save the login.
Couldn't save your login. If your Mac's keychain is locked, unlock it and log in again.means the login never completed. When the Keychain rejects a write, for example while locked in an SSH session, Claude Code falls back to~/.claude/.credentials.json. Runclaude doctor; amacOS Keychain is not writablewarning confirms it. Unlock it withsecurity unlock-keychain ~/Library/Keychains/login.keychain-db, or resync the Keychain password in Keychain Access, then/logoutand/login. Logging out removes all stored credentials, including MCP server logins and plugin secrets, so expect to re-enter those. - Scripts, CI and
-pruns don't have your login. A-pcommand or Agent SDK program that relies on a saved login needs you to runclaudein that same environment and complete/loginfirst. For automation without a browser, runclaude setup-token: it opens the same browser authorization and prints a one-year OAuth token (it doesn't save it). Set it asCLAUDE_CODE_OAUTH_TOKENwherever the script runs. It needs a Pro, Max, Team or Enterprise plan and can only make model requests.--baremode doesn't readCLAUDE_CODE_OAUTH_TOKEN, so bare scripts needANTHROPIC_API_KEYor anapiKeyHelper. And if a 401 keeps coming back while this variable is set, Claude Code keeps sending its value: generate a fresh token, or unset it and run/login.
Two special cases
- Work and personal accounts. Give each account its own configuration directory, for example
alias claude-work='CLAUDE_CONFIG_DIR=~/.claude-work claude'. Each directory keeps its own settings, history and login, and the first run walks you through login again. Two Console sign-ins without an API key aren't kept apart this way, because that kind of sign-in is stored outside the configuration directory. - Bedrock, Google Cloud's Agent Platform or Microsoft Foundry. No browser login is involved.
Could not load credentials from any providers(Bedrock),Could not load the default credentials(Agent Platform) orChainedTokenCredential authentication failed(Foundry) means the cloud CLI isn't signed in in that shell: checkaws sts get-caller-identity,gcloud auth application-default loginoraz login. If it works in your terminal but not in the VS Code or JetBrains extension, the IDE didn't inherit your shell's environment; see our IDE not connecting guide for the IDE side.
Still stuck?
If the problem is that claude isn't found at all, see Claude Code command not found. Run claude doctor for an automated report, and check /status again after each change. If the problem is the account rather than the install, such as a login loop, a subscription that isn't recognized or a disabled organization, contact Anthropic support from claude.ai (Console users: platform.claude.com) via your initials, then Get help. If a key in your env block or settings file seems to do nothing, settings not applying explains which file each key belongs in.
Facts on this page come from Anthropic's Claude Code docs on authentication, troubleshooting installation and login, errors and the CLI reference. This guide isn't affiliated with Anthropic.