Claude Code Login Failed: Fix OAuth and API Key Errors (2026)
When Claude Code login fails, don't just retry over and over. First figure out which authentication method you're using: browser authorization (OAuth, signing in with your Claude account) or an API key (a key from the Anthropic Console or a third-party endpoint). The failure points of the two methods barely overlap, and mixing them up while troubleshooting is the easiest way to go in circles.
The steps below follow the order "classify first, check status next, then rule out each layer." Commands and messages may change between versions, so rely on Anthropic's official documentation and the output of claude --help on your machine.
Which login method am I actually using?
Run claude in a terminal. On first launch it asks you to pick a login method. If you've already logged in, type /status inside a session to see where the current credentials come from. There are two broad categories:
| Method | Where credentials come from | Typical failure symptoms |
|---|---|---|
| Browser authorization (OAuth) | Your Claude account, needs a browser callback | Browser won't open, authorization page spins forever, terminal does nothing after authorizing, "no permission" account errors |
| API key | A key in an environment variable or config | 401, "invalid key," auth conflict warning, request timeout |
If you aren't sure, run /logout to clear the current state and log in again with one method. That's cleaner than piling changes onto stale state.
Check whether the service itself is down
Login depends on Anthropic's authentication service and API. If their side is failing, nothing you change locally will help.
- Open /en/status/anthropic to see cdnping's probes of the official endpoints from Cloudflare's edge, along with the synced official status page.
- Open /en/down/claude-code for an assessment based on status pages, probes, and user reports.
Keep in mind that these two pages show the server and edge point of view. They can't prove that the path from your machine to Anthropic is working. If the service looks healthy and you still can't log in, the problem is most likely your local network, browser, or configuration.
OAuth stuck? Work through these six steps
- Did the browser launch? The terminal normally prints an authorization link. If the browser doesn't open on its own, copy the link and open it manually, preferably in the same browser you normally use to sign in to Claude.
- Does the authorization page load? If the page spins forever or keeps showing a human-verification challenge, that's a web-side problem. See Claude human verification spins forever: browser and network checks.
- Not receiving the login email or verification code? This happens at the web login stage. See Claude login email not received: checking your mailbox and link.
- Authorization succeeded but the terminal does nothing. A common cause is that the terminal and the browser are in different network environments, for example when the terminal runs in WSL, on a remote server, or in a container and the callback can't reach your machine. For remote setups, follow the official documentation.
- Account-related errors. Examples are a restricted or disabled account or insufficient subscription permissions. These are account-state problems, not network problems. For how to tell them apart, see Can't log in to Claude? First tell network, verification code, and account state apart.
- Corporate network. A company proxy or certificate inspection may block the authorization domains. You'll need to investigate together with IT. See Claude access errors on a corporate network.
API key mode failing? How to check
API key mode doesn't go through browser authorization, so problems concentrate in the key, the endpoint URL, and environment variables.
# Show auth-related variables in the current shell (only whether they are set; the key is not printed)
env | grep -E '^ANTHROPIC_' | sed 's/=.*/=<set>/'
# Clear them temporarily and try again
unset ANTHROPIC_API_KEY ANTHROPIC_AUTH_TOKEN
claude
Check each item:
- Multiple credentials at the same time. If you're logged in with an account and also have
ANTHROPIC_API_KEYset, you'll get an auth conflict warning, or even a 401. For the fix, see Claude Code auth conflict warnings and 401 errors: how to fix. - Stray characters in the key. Copying in a space, newline, or quote mark is the most common cause of "invalid key."
- Wrong endpoint URL. When using a third-party or self-hosted endpoint,
ANTHROPIC_BASE_URLmust be correct. Whether the path includes/v1depends on that service's documentation. - Environment variable change not taking effect. After editing
~/.zshrcor~/.bashrc, reopen the terminal or runsourceon the file. The built-in terminal in an IDE sometimes requires restarting the IDE. - Choosing and switching between the two methods. See Claude Code: API key login or subscription login, and how to switch.
Login keeps timing out. Is it the proxy?
If the error is a timeout or a connection reset rather than a clear authentication error, it's usually a network-layer problem. First confirm that the terminal itself can reach your proxy: many people can browse fine, but their terminal doesn't inherit the proxy settings.
You can run curl -I https://api.anthropic.com to see whether you get a response. A 4xx still means the path works; only a timeout means it doesn't. To debug proxy variables, see Claude Code proxy settings not taking effect. For a more complete layer-by-layer check, see Claude Code timeouts and connection errors: a four-layer network checklist.
To look at your machine's egress environment, use /en/ip for DNS and WebRTC leak tests and egress detection. It can help you tell whether the terminal and the browser are using different egress paths. This is diagnostic information, not a fix.
What if official login doesn't work for me?
There are two directions, and both must follow the official rules:
- If your region isn't in Anthropic's supported list, or your account is restricted or disabled, follow Anthropic's terms of service and supported-regions policy, and handle account problems through the official appeal process. See Claude account restricted vs. disabled: what's the difference. Don't try to get around restrictions with multiple accounts or other workarounds. That violates the terms and may make things worse.
- If you only need to call models from Claude Code and don't have a Claude account, you can use an endpoint URL instead. See Can you use Claude Code without a Claude account? The endpoint URL approach.
One option worth mentioning: AGI Plan is a multi-provider LLM aggregation gateway sold as a monthly subscription, paid in RMB, with no overseas credit card needed. Tools such as Claude Code and Codex only need one endpoint URL changed, and you can switch between capability groups on the same quota. Using Claude Code this way doesn't require a Claude account. It is compatible with both the OpenAI and Anthropic API formats, and some models are marked "overseas only." Check the AGI Plan models page for specifics. The site also states plainly that it is not an officially authorized channel. AGI Plan is a commercial partner of cdnping. Setup steps are on the AGI Plan getting-started page.
What to do next
- Run
/logoutto clear the state, and decide whether you're going with OAuth or an API key. - Check /en/status/anthropic and /en/down/claude-code to rule out a server-side outage.
- For OAuth, check the browser, the callback, and the account state. For an API key, check environment variables, the key, and the endpoint URL.
- For timeout-type errors, go back to the network layer and verify each layer using the four-layer checklist.
- If all of that checks out and you still get account-related errors, contact Anthropic support to file an appeal or ask for help, and include the original error text and when it happened.