OAuth token expired immediately after fresh login - cannot use Claude Code (blocking)

Resolved 💬 19 comments Opened Jan 18, 2026 by michaelhdmd Closed Apr 24, 2026

Preflight Checklist

  • [x] I have searched existing issues and this hasn't been reported yet
  • [x] This is a single bug report (please file separate reports for different bugs)
  • [x] I am using the latest version of Claude Code

What's Wrong?

Environment:

Claude Code v2.1.12
macOS (M1, MacBook Pro 2022)
Claude Max subscription

Issue:
Cannot use Claude Code at all. Two failure modes observed:

Token pre-expired: Fresh OAuth login completes successfully (browser shows "You're all set up for Claude Code"), welcome screen displays, but the very first API call fails with 401: "OAuth token has expired."
Login callback failure: /login command fails with ECONNREFUSED or "Was there a typo in the url or port?" - even though the browser successfully completes auth on Anthropic's side.

Steps to reproduce:

Exit Claude Code
rm -rf ~/.claude (clear all credentials)
Run claude
Run /login
Either: login callback fails with ECONNREFUSED, OR login succeeds but first prompt returns 401 "token expired"

Key difference from #17716:
This is not a mid-session expiration - the token is invalid immediately upon issuance. No prompts can be sent at all. This is a complete blocker, not a UX friction issue.
Additional context:

Occurred Jan 17 and Jan 18, 2026, same time of day (~3pm EST)
Spontaneously resolved after several hours on Jan 17
Credential reset does not fix the issue
No VPN, firewall disabled, Pi-hole disabled during testing

What Should Happen?

After completing the browser OAuth flow, Claude Code should receive a valid token and successfully execute API calls. Users should be able to send prompts immediately after login.

Error Messages/Logs

API Error: 401 {"type":"error","error":{"type":"authentication_error","message":"OAuth token has expired. Please obtain a new token or refresh your existing token."},"request_id":"req_011CXFRbLKkrH6cs3PmDt3b1"} · Please run /login
OAuth error: ECONNREFUSED
Press Enter to retry.
OAuth error: Was there a typo in the url or port?
Press Enter to retry.

Steps to Reproduce

Run claude in terminal
Enter any prompt (e.g., 1x)
Receive 401 "OAuth token has expired" error
Run /login
Either:

Login callback fails with ECONNREFUSED, OR
Browser completes successfully but CLI reports "Was there a typo in the url or port?"

If login appears to succeed, first prompt still returns 401 "token expired"

Workaround attempted (unsuccessful):

Exit Claude Code
rm -rf ~/.claude (clear all credentials)
Run claude
Run /login
Same failure occurs

Claude Model

Opus

Is this a regression?

I don't know

Last Working Version

_No response_

Claude Code Version

2.1.12

Platform

Anthropic API

Operating System

macOS

Terminal/Shell

Terminal.app (macOS)

Additional Information

<img width="535" height="565" alt="Image" src="https://github.com/user-attachments/assets/92978a37-2f88-4803-9842-c4bc94b06c60" />

View original on GitHub ↗

19 Comments

michaelhdmd · 5 months ago

And now we are back.

<img width="1112" height="768" alt="Image" src="https://github.com/user-attachments/assets/55ccde77-43a9-45fc-b24a-e88b3f18cbbd" />

jacoporicare · 5 months ago

I am experiencing the same since Friday. The token expires in 3 hours or so.

michaelhdmd · 5 months ago

After working last night (EST), OAuth token has expired.

jacoporicare · 5 months ago

I maybe found the culprit - ps aux | grep claude showed me that multiple instances (older versions, one from each, probably after every update; also visible in Activity Monitor on macOS) of Claude Code was running in the background. I killed them all with pkill claude and fingers crossed that was the issue. It would make sense if Claude had refresh token rotation and other instances used the refresh token.
A side note: one of the instances in the background, (which I didn't background, it was stuck) was using 100% of CPU (one core) all the time. I was wondering why suddenly my MacBook Pro with M4 Pro is heating like crazy.

michaelhdmd · 5 months ago

@jacoporicare ok. I am still up as of 12:05 EST. If it goes down again today, I will give it a try and see if I get a similar result.

minetree2023 · 5 months ago

Today I encountered similiarly a same issue, both with WSL and Claude Desktop, MAX plan subscription. I am much confused.

minetree2023 · 5 months ago
Today I encountered similiarly a same issue, both with WSL and Claude Desktop, MAX plan subscription. I am much confused.

WSL replys: OAuth error: Failed to fetch user roles: Request failed with status code 403

minetree2023 · 5 months ago
> Today I encountered similiarly a same issue, both with WSL and Claude Desktop, MAX plan subscription. I am much confused. WSL replys: OAuth error: Failed to fetch user roles: Request failed with status code 403

API Error: 403 {"error":{"type":"forbidden","message":"Request not allowed"}} · Please run /login

michaelhdmd · 5 months ago

@ 2:31 PM (EST) I am ok and logged in.

minetree2023 · 5 months ago
@ 2:31 PM (EST) I am ok and logged in.

Good to hear that. Maybe temporary server errors. After about 5 hours, I get to be ok and logged in also

michaelhdmd · 5 months ago

1:10 PM EST: OAuth token has expired, yet again.

Additional diagnostic data:
Verified single Claude instance running during failure state:
ps aux | grep claude
mike 67920 0.7 1.9 485378640 322576 s000 S+ 1:22PM 0:08.26 claude
mike 68147 0.0 0.0 410724400 1408 s003 S+ 1:25PM 0:00.00 grep claude
Multiple-instance token conflict ruled out - only one Claude process active when error occurs.
Environment:

Claude Code v2.1.15
macOS (M1)
Claude Max subscription

Behavior pattern:

Occurs intermittently, often around early-mid afternoon EST
Resolves spontaneously after several hours with no user action
Persists through /login attempts
Persists through full credential wipe (rm -rf ~/.claude)
No VPN, no firewall, Pi-hole disabled during testing

This points to something server-side in token issuance/refresh rather than a local process conflict.

michaelhdmd · 5 months ago

Update. I did a reboot of macOS. When I tried again after the reboot, it was working. Not sure if that was the solution or just a matter of timing.

michaelhdmd · 5 months ago

Update. I was able to replicate the reboot today. Same OAuth token error, fixed after soft reboot.

anton-prepared · 5 months ago

I've suddenly started getting this problem. Previously I'd login once a month tops, now it's daily, from what I can tell the refresh mechanism isn't working to exchange the refresh_token for a new one.

craigmacmaster · 4 months ago

/mcp shows "✔ authenticated" but tool calls still return 401 even after pkill claude. Claude and I gave up.

ivanlukic-unitrade · 3 months ago

Seems to me as this is no duplicate. I am correctly redirected to the oauth page and claude code states "Login successful"
The error persists.

<img width="1049" height="326" alt="Image" src="https://github.com/user-attachments/assets/6e469356-7676-4524-a706-192282a36936" />

casoon · 3 months ago

I ran into the same issue (OAuth token expired immediately after login).

For context:

  • I’m using Claude Code inside Zed
  • I re-ran claude install after seeing a note that something changed in the setup

Tried the usual things:

  • /login multiple times
  • logout/login
  • checking docs

I also did NOT delete my local Claude directory (~/.claude), since I have MCP config and memory stored there, so that wasn’t really an option for me.

None of that worked.

What finally solved it for me was using claude setup-token.

This creates a long-lived auth token (requires a subscription), opens the browser for authentication, and gives you a token afterward.

I then exported that token in my shell (CLAUDE_API_KEY), and everything worked.

If you’re stuck in the login loop, I’d recommend trying setup-token directly.

github-actions[bot] · 2 months ago

Closing for now — inactive for too long. Please open a new issue if this is still relevant.

github-actions[bot] · 2 months ago

This issue has been automatically locked since it was closed and has not had any activity for 7 days. If you're experiencing a similar issue, please file a new issue and reference this one if it's relevant.