Fix Claude Code Login Auth Redirect Loop (2026)
The Error
Waiting for authentication...
Opening browser: https://console.anthropic.com/oauth/authorize?...
Error: Authentication callback not received. Timed out after 120 seconds.
Retrying... (attempt 3/3)
Error: Failed to authenticate. Please try again.
This error occurs when Claude Code's browser-based OAuth flow loops without completing. The browser opens, you authenticate, but the callback never reaches Claude Code.
TL;DR — Quick Fix
Clear the auth cache and re-login:
rm -rf ~/.claude/auth.json ~/.claude/.credentials && claude login
The Fix
Step 1: Clear the auth cache
rm -rf ~/.claude/auth.json
rm -rf ~/.claude/.credentials
Step 2: Kill any existing Claude Code processes
pkill -f "claude" 2>/dev/null
Step 3: Re-authenticate
claude login
If the browser does not open, manually copy the URL from the terminal and paste it in your browser.
Why This Happens
The OAuth flow starts a temporary local HTTP server to receive the callback. The loop occurs when:
- A firewall blocks localhost connections
- Another process occupies the callback port
- The browser redirects to an incorrect callback URL
- Stale auth tokens confuse the handshake
- Corporate SSO configurations interfere with the OAuth redirect chain
If That Does Not Work
Use API key authentication instead
export ANTHROPIC_API_KEY="sk-ant-api03-your-key"
claude "test"
Try a different callback port
claude login --port 9876
Check if localhost is resolving correctly
curl -s http://localhost:9876 2>&1
# Should show "connection refused" (port not in use), not a timeout
Disable VPN
Some VPNs intercept localhost traffic. Temporarily disable your VPN, run claude login, then re-enable it after authentication completes.
Prevention
Add this to your CLAUDE.md:
# Authentication
- Prefer API key auth (ANTHROPIC_API_KEY) over OAuth for CI/CD and headless.
- If OAuth loops, clear ~/.claude/auth.json and retry.
- Ensure no firewall rules block localhost on ports 9000-9999.
FAQ
Why does the OAuth login time out after 120 seconds?
Claude Code starts a local HTTP server and waits for the browser to redirect back after authentication. If the redirect cannot reach the local server (firewall, VPN, port conflict), the callback never arrives and Claude Code times out. Clear the auth cache with rm -rf ~/.claude/auth.json and ensure nothing is blocking localhost connections.
Can I skip browser-based login entirely?
Yes. Set the ANTHROPIC_API_KEY environment variable with your API key and Claude Code will use it directly without OAuth. This is the recommended approach for CI/CD pipelines, headless servers, and environments where browser access is restricted. Get your API key from console.anthropic.com.
Does corporate SSO cause the redirect loop?
Yes, corporate SSO and proxy configurations are a common cause. The SSO flow may add extra redirects that break the OAuth callback chain. Solutions: (1) use API key auth instead, (2) whitelist localhost:9000-9999 in your proxy configuration, or (3) temporarily bypass the corporate proxy for the authentication step.
I got stuck in auth loops for 30 minutes before I set up API key auth in my CLAUDE.md. Now authentication just works, everywhere, every time.
I run 5 Claude Max subs, 16 Chrome extensions serving 50K users, and bill $500K+ on Upwork. These CLAUDE.md templates are what I actually use.