Claude Code Login Failed? Fix OAuth and Terminal Auth

Marcus
Marcus
Proxy Network Analyst

Claude Code authentication can fail before the browser opens, after browser approval, while a login code is being returned to the terminal, or only after the CLI starts making authenticated requests. Those failures look similar from the outside, but they belong to different layers.

Keep the first reproduction small: one terminal, one Claude Code process, one browser authorization flow, and the intended account. Save the exact terminal error, CLI version, and authentication status, but never paste an OAuth URL, login code, cookie, callback value, API key, or saved credential into a public ticket.

Quick Answer

When Claude Code login fails, first confirm that the CLI itself is current and identify the active authentication method. Then separate the browser OAuth handoff from the terminal callback. In WSL2, SSH sessions, and containers, a browser may display a login code instead of redirecting back automatically; paste that code into the terminal prompt. If login succeeds but requests return 403, check subscription or Console role, credential precedence, and any corporate proxy before changing accounts or network routes.

Key Takeaways
  • Use Claude Code-specific evidence: CLI version, auth status, terminal error, callback behavior, and environment.
  • Browser approval and terminal authentication completion are separate events.
  • WSL2, SSH, and containers often require copying the OAuth URL or pasting a login code back into the terminal.
  • An old or unrelated ANTHROPIC_API_KEY can take precedence over subscription OAuth and cause confusing authorization failures.
  • A Claude web-login problem and a Claude Code terminal-login problem should remain separate troubleshooting paths.
  • Network and proxy tests are useful only after account, OAuth, and credential-state checks are controlled.

Identify the Failing Handoff

The last successful event determines the next test. If the shell cannot resolve claude, the problem is installation or PATH, not OAuth. If the CLI starts but no browser opens, the browser-launch handoff is the first failure. If the browser approves access but the terminal keeps waiting, focus on the callback or login-code return instead of repeating account login.

If claude.ai itself cannot sign in before Claude Code authorization begins, stop the CLI diagnosis and use IPWeb's Claude web login troubleshooting guide. If Claude Code shows App unavailable in region or an explicit country-availability message, handle that separately with the Claude country availability guide. Keeping those branches separate prevents a browser-session problem or regional availability result from being mistaken for a terminal OAuth failure.

Last observed event Most relevant layer First evidence to collect
claude is not foundInstallation / PATHclaude --version, resolved binary path, shell
CLI starts but browser does not openBrowser-launch handoffLocal vs remote host, terminal type, OAuth URL behavior
Browser approves but terminal waitsOAuth callback / login-code returnWSL2, SSH, container, callback prompt
OAuth error: Invalid codeExpired or truncated login codeRetry timing, full URL/code copy
403 appears after loginSubscription, role, credential or networkAccount type, /status, proxy state
Login expiredStored OAuth credential/status, system clock, re-auth result
Table 1: Claude Code login errors are easier to isolate when the last successful handoff is known.

Verify the CLI and Current Auth State

Start with the installed CLI rather than assuming the account is the problem. Anthropic's current Claude Code CLI reference includes direct authentication commands such as claude auth login, claude auth logout, and claude auth status. Inside an interactive Claude Code session, /login, /logout, and /status remain useful for account switching and authentication checks.

Claude Code terminal showing login method options for a Claude subscription account and Anthropic Console account
Figure 1: Claude Code separates subscription sign-in from Anthropic Console API usage.
claude --version
claude auth status --text

If the command is missing or resolves to an unexpected installation, fix that before OAuth. Anthropic's installation and login troubleshooting documents PATH checks and conflicting-installation checks for macOS, Linux, Windows, and WSL. Multiple Claude Code installations can make an old binary appear to have an authentication problem when the shell is simply launching a different version.

Note: Run authentication and environment checks in the same shell session you use to launch Claude Code. Variables set temporarily in that shell are inherited by processes started from it, while a new terminal may have different values unless those variables are configured persistently. This is especially important when comparing ANTHROPIC_API_KEY, HTTP_PROXY, HTTPS_PROXY, or PATH-related behavior.

Complete the Browser OAuth Handoff

On first launch, claude normally opens a browser for authentication. Anthropic's current Claude Code authentication guide says that if the browser does not open automatically, press c at the login prompt to copy the OAuth URL and open it manually.

Claude Code browser authorization page asking permission to connect to a Claude chat account
Figure 2: Claude Code browser authorization must be completed before the terminal can finish the OAuth flow.

WSL2, SSH sessions, and containers need special attention. The browser often runs on a different host, so its redirect cannot reach Claude Code's local callback server. In that case, the browser can show a login code instead of redirecting back. Paste that code into the terminal at the Paste code here if prompted prompt. This is a normal fallback for remote or isolated environments, not proof that the account is broken.

claude auth login

Keep only one login attempt active. Starting several terminal auth flows at once creates multiple OAuth URLs and makes it harder to know which browser approval belongs to which process.

Claude Code terminal showing a successful browser login and Login successful message
Figure 3: A successful Claude Code OAuth flow returns authentication to the terminal.

Fix Common Claude Code Login Errors

OAuth error: Invalid code

If the terminal shows OAuth error: Invalid code, Anthropic says the login code may have expired or been truncated during copy and paste. Retry promptly, use c to copy the full OAuth URL when needed, and in SSH or remote sessions open that URL in the browser on the machine you actually use for web authentication.

Claude Code terminal showing OAuth error Invalid code and prompting the user to retry
Figure 4: Claude Code can reject an OAuth code when the code is expired, incomplete, or copied incorrectly.

403 Forbidden after login

A 403 after successful login belongs to authorization or request context, not necessarily the browser handoff. Anthropic currently recommends that Pro or Max users verify that the subscription is active, while Console users should confirm that the account has the required Claude Code or Developer role. A corporate proxy can also interfere with requests after authentication.

Claude Code terminal showing OAuth error Request failed with status code 403
Figure 5: A Claude Code OAuth request can return HTTP 403 even after the browser flow starts.

Reset a login that is stuck or expired

When the cause is unclear, Anthropic's documented reset sequence is to sign out completely, close Claude Code, restart it, and authenticate again. If Claude Code reports an expired login, re-authenticate and check that the system clock is accurate because OAuth token validation depends on correct timestamps.

claude auth logout
claude auth login
claude auth status --text

Check Credential Precedence

Claude Code can have more than one credential source available at the same time. This matters because a saved subscription login does not always win. Anthropic documents that an approved ANTHROPIC_API_KEY can take precedence over subscription OAuth. If that API key belongs to a disabled, expired, or unintended organization, Claude Code may fail even though the Claude subscription itself is valid.

Use /status or claude auth status --text to confirm which account and authentication method are active. If the goal is to use the Claude subscription and an unintended API key is present, remove the variable from the current shell and then start Claude Code again.

macOS / Linux / WSL

unset ANTHROPIC_API_KEY
claude

Windows PowerShell

Remove-Item Env:ANTHROPIC_API_KEY
claude

Do not replace OAuth with an API key simply because the error message is short. Claude Pro, Max, Team, and Enterprise subscription OAuth, Claude Console credentials, cloud-provider credentials, and CI tokens serve different environments and can have different precedence.

Check Managed Network and Proxy Settings

Move to network diagnosis only after the CLI, OAuth flow, account, and active credential source are understood. Claude Code's enterprise network configuration supports standard HTTP_PROXY, HTTPS_PROXY, and NO_PROXY variables for corporate proxy environments. Claude Code does not support SOCKS proxies through this documented proxy configuration, so use an HTTP(S) endpoint for this specific test.

From the same shell that runs Claude Code, test whether Anthropic endpoints are reachable. On Windows PowerShell, use curl.exe rather than the curl alias when you need standard curl flags.

curl -I https://api.anthropic.com
curl -sI https://downloads.claude.ai/claude-code-releases/latest

If a proxy is already configured and you are unsure whether the terminal is actually using the expected route, first verify the route with IPWeb's proxy testing guide. Keep the same shell, endpoint, and test conditions while checking the visible IP, country, ISP or ASN, and connection result.

For approved egress QA that specifically needs one stable residential HTTP(S) endpoint across repeated tests, IPWeb Static Residential Proxies can provide a fixed comparison route. Use that only as a network variable: a stable proxy cannot activate a Claude subscription, create a Console role, repair an expired OAuth code, change Anthropic's country availability, or override an employer's security policy.

Frequently Asked Questions

Why does the browser say Claude Code login succeeded but the terminal is still waiting?

The browser approval and terminal completion are separate steps. In WSL2, SSH sessions, or containers, the redirect may not reach Claude Code's local callback server. If the browser shows a login code, paste it into the terminal prompt instead of starting another login flow.

How do I fix “OAuth error: Invalid code” in Claude Code?

Retry the login promptly because the code may have expired. Make sure the full OAuth URL or login code was copied. In a remote SSH environment, open the terminal-provided URL in your local browser and return the displayed code to the terminal if prompted.

Why do I get 403 Forbidden after Claude Code login?

Check the active subscription or Console role first, then confirm which credential source Claude Code is using. An unintended API key or a corporate proxy can also affect requests after the OAuth flow itself has succeeded.

Can ANTHROPIC_API_KEY break Claude Code subscription login?

It can change which credential Claude Code uses. Anthropic documents that an approved ANTHROPIC_API_KEY can take precedence over subscription OAuth. Use /status or claude auth status --text to confirm the active method before changing credentials.

Why does Claude Code OAuth fail in WSL2, SSH, or a container?

The browser and Claude Code process may be on different hosts, so the browser redirect cannot reach the CLI's local callback server. Copy the OAuth URL into a browser you can use, then paste the returned login code into the terminal when prompted.

Can a corporate proxy cause Claude Code login or API errors?

Yes. A corporate proxy can affect DNS, TLS inspection, downloads, authentication endpoints, or API requests. Claude Code supports documented HTTP(S) proxy environment variables, so confirm the approved proxy configuration and CA trust with your network administrator.

Should I use a residential proxy to fix Claude Code login?

No. A proxy is not a general authentication fix. A stable route can help with an authorized network comparison after account and OAuth checks are complete, but it cannot grant account access, change a role, repair credentials, or override Anthropic availability rules.

What should I do if multiple Claude Code versions are installed on my machine?

Check every Claude Code binary your shell can find before troubleshooting authentication. On macOS, Linux, or WSL, run which -a claude; on Windows, run where.exe claude. If multiple installations are present, keep one supported installation and remove redundant or legacy copies so the shell consistently launches the expected Claude Code version. Anthropic currently recommends the native install at ~/.local/bin/claude on macOS/Linux or %USERPROFILE%\.local\bin\claude.exe on Windows.

What if Claude Code says the app is unavailable in my region?

Treat that as a regional availability result rather than an OAuth callback problem. Check Anthropic's supported-country information and use the separate Claude country-availability troubleshooting path instead of repeatedly retrying terminal login.

Final Thoughts

Claude Code login failures are easiest to solve when each handoff is tested in order: CLI availability, current credential state, browser OAuth, terminal callback, account authorization, and finally network reachability. That sequence keeps a missing role, expired code, remote-session callback, API-key override, and corporate proxy from being mixed into one generic “login failed” diagnosis.

If claude.ai web login itself is failing, move to the web-login troubleshooting path. If the error is explicitly regional, move to the country-availability path. Keep this page focused on Claude Code CLI authentication so each problem has one clear diagnosis.

About the author
View all articles
Marcus
Marcus
Proxy Network Analyst

Marcus is a network infrastructure analyst specializing in proxy configuration, IP routing, browser connectivity, and network troubleshooting. His work focuses on diagnosing HTTP/SOCKS proxy connections, authentication failures, DNS behavior, firewall rules, and IP routing across browser and automation environments.

Service areas
Proxy Testing , IP Diagnostics,Network Troubleshooting & Reliability

You may be interested in

Perplexity not available in your country cover showing a region unavailable message and checks for account, service status, and network evidence

Why Perplexity Says It Is Not Available in Your Country

A Perplexity country or region warning looks like a network problem, but the wording alone does not tell you whether the entire service, one feature, one account context, or one network path is responsible. The useful question is not “Which IP should I try next?” It is “What exactly failed, on which Perplexity surface, and what changed immediately before the failure?” That distinction matters because Perplexity Search, mobile apps, organization accounts, the API Console, and individual features can have different access conditions. A route test can reveal a network difference, but it cannot prove what Perplexity’s internal eligibility logic is...

Marcus

Marcus

Proxy Network Analyst

Google Search Operators for Better SERP Checks

Google Search Operators for Better SERP Checks

Google search engine syntax includes operators and query patterns that make a search more specific, such as quotation marks for exact phrases, site: for a domain or URL prefix, minus signs for exclusions, before: and after: for date limits, and filetype: for document types. Used well, these operators help SEO teams, analysts, and developers answer a narrower search question before they compare Google results or move to a structured SERP workflow. The important distinction is that search operators control the query, not the entire result environment. They can make a manual check clearer and easier to document, but they do...

Ryan

Ryan

IP Proxy Research Team

Claude Code Proxy Setup guide showing HTTPS_PROXY, HTTP_PROXY, NO_PROXY, TLS, OAuth, and a secure proxy connection workflow

How to Set Up a Proxy for Claude Code

Claude Code does not automatically inherit a browser extension or browser-only proxy. The CLI reads its own network configuration, while browser authorization can run in a different process or even on a different host. A reliable setup therefore starts with the terminal process itself, then verifies DNS, TLS, and OAuth behavior separately. Use one stable endpoint for the first test and keep credentials out of reusable commands, screenshots, and support tickets. Once the terminal path is confirmed, you can compare another approved route without mixing proxy setup with account, region, or OAuth problems. Quick Answer Set HTTPS_PROXY or HTTP_PROXY before...

Clark

Clark

IPWeb Technical Researcher

Ready to scale your data operations?
Join 10,000+ teams using IPWeb to power their web data collection. Start free today.

Strictly anti-abuse

Fraud, automated operation, and unauthorized use are prohibited.

Enterprise-level services

For legitimate commercial and technical use cases only

Risk control and restrictions

Abnormal behavior may trigger service restrictions or termination.

Compliance data use

Data acquisition and use must comply with relevant regulations.

Privacy protection first

The collection or misuse of sensitive personal information is strictly prohibited.

All services are subject to《the Usage Policy》