[BUG] API Error: 401 Invalid authentication credentials
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?
OS: Windows
Error Message:
API Error: 401 Invalid authentication credentials
Subscription Status:
Pro (expires on June 30)
Troubleshooting Steps Already Attempted:
- Ran
claude logout - Ran
claude login - Deleted
%APPDATA%\Claude - Reinstalled Claude completely
None of the above steps resolved the issue.
What Should Happen?
claude login
●Please run /login · API Error: 401 Invalid authentication credentials
✻ Worked for 2s
Remove-Item -Recurse -Force "$env:APPDATA\Claude"
●Please run /login · API Error: 401 Invalid authentication credentials
✻ Churned for 2s
claude login
●Please run /login · API Error: 401 Invalid authentication credentials
✻ Sautéed for 2s
claude /login
●Please run /login · API Error: 401 Invalid authentication credentials
✻ Cogitated for 2s
接著作
●Please run /login · API Error: 401 Invalid authentication credentials
✻ Crunched for 2s
Error Messages/Logs
Steps to Reproduce
OS: Windows
Error Message:
API Error: 401 Invalid authentication credentials
Subscription Status:
Pro (expires on June 30)
Troubleshooting Steps Already Attempted:
- Ran
claude logout - Ran
claude login - Deleted
%APPDATA%\Claude - Reinstalled Claude completely
None of the above steps resolved the issue.
Claude Model
None
Is this a regression?
Yes, this worked in a previous version
Last Working Version
_No response_
Claude Code Version
Claude Code v2.1.183
Platform
Anthropic API
Operating System
Windows
Terminal/Shell
PowerShell
Additional Information
OS: Windows
Error Message:
API Error: 401 Invalid authentication credentials
Subscription Status:
Pro (expires on June 30)
Troubleshooting Steps Already Attempted:
- Ran
claude logout - Ran
claude login - Deleted
%APPDATA%\Claude - Reinstalled Claude completely
None of the above steps resolved the issue.
22 Comments
Found 3 possible duplicate issues:
This issue will be automatically closed as a duplicate in 3 days.
🤖 Generated with Claude Code
"This is not a duplicate — the linked issues are older and unresolved. Please escalate. I am unable to use Claude Code on Windows despite an active Pro subscription."
I ran into the same issue.
You can check your ~/.claude/.credentials.json file and see whether refreshToken is empty. In my case, it was set to an empty string, which caused Claude Code to return 401 Invalid authentication credentials.
As a temporary workaround, I copied a valid refreshToken from another machine where the same Claude account was still working, and Claude Code started working again immediately.
Same for me: using claude code v2.1.185 Sonnet 4.6 claude pro subscription on linux getting the same error 401. still the same error after nearly 24h. no response from anthropics. maybe this is "geoblocking" non us citizen??
I dont have any other machine, so i'm stuck?
any solution from anthropics??
Same problem on a Mac in the U.S.
Desktop access works though, same a/c.
Same problem here, running on debian based OS
Same issue on Claude Code v2.1.185, Pro subscription. UK based. Environment: GitHub Codespace (browser, on a Chromebook). Persistent 401 Invalid authentication credentials even after: deleting ~/.claude/.credentials.json, clearing ~/.config/claude and ~/.cache/claude, unsetting env vars, and generating a fresh setup-token. Fresh tokens still rejected. Pro plan active, weekly usage 5%, so not a quota issue. setup-token OAuth redirect goes to localhost which the cloud Codespace can't catch.
Same issue here it suddenly broke down today
Same, came in to work today and its not authenticating, which I've never had an issue with before
``
Please run /login · API Error: 401 Invalid authentication credentials``I'm based in the UK as well.
I submitted a support ticket but never received a response.
Since Claude Code was still working on the desktop version, it suggested switching to API mode. However, there was no clear warning that API usage is billed separately on a pay-as-you-go basis. As a result, I ended up spending quite a bit of money before realizing it.
Fortunately, I eventually solved the issue. When I asked Opus 4.8 on the desktop version, it gave me the following solution on June 20:
Using the above method solved my issue completely.
What frustrated me is that when I previously used Sonnet 4.6, the troubleshooting suggestions it provided were completely ineffective. I spent a lot of API credits following those recommendations and got nowhere.
If anyone else is experiencing the same problem, I highly recommend trying the solution above before spending more money on API usage.
same issue here
This worked for me. Thank you.
I don't get the opportunity to enter /login. it asks me to choose the text style then goes straight to method of log-in where i get 3 options: sub a/c, api or 3rd party. choosing sub a/c takes me to a web page that says i must upgrade to max. i'm on max now but choosing it as a plan takes me to payment. if i cancel the existing plan, i am still paying for 2 plans through my renewal date, JUly 8. so i'm waiting until june 7. i may try a pro plan and see if that works until then.
Same bro. Me and two friends were sharing the account like you, and all of us got disconnected at the same time. Maybe Claude doesn't allow multiple people to use the same account anymore.
if you have any solution pls tell me, I need my claude max 20x back :(
Still not resolved
Same issue. Windows 11, Max valid (org admin), env vars all empty, clean WinGet reinstall v2.1.187, /logout+/login and credential purge done. 401 persists for 48h. Support ticket open, no human response.
I’m seeing the same 401 auth failure, but with an additional account-level onboarding loop.
Account state:
Current failure:
This is now day 3 of being locked out of a paid Max 20x account.
Troubleshooting already attempted:
Because my existing mobile session still works, this does not look like a deleted account or local cache issue. It looks like existing sessions remain valid, but new login/session issuance is broken, possibly due to server-side account mapping, onboarding state, or OAuth token issuance.
Support has not meaningfully responded for 2 days. Can someone from Anthropic confirm whether this auth/onboarding/401 class of issue is being tracked internally, and what support path can actually fix account mapping for paid users?
**UPDATE: It's been now more than a week since the 401 issue started. I have to relog (/login) every day - creating a new code every day - to reopen a claude pro sessio as a turnaround since the persistent CLAUDE_CODE_OAUTH_TOKEN on Github/codespace/secret is failing and is not being recognised by Claude Code.
CAN SOMEONE FROM ANTHROPIC CAN TAKE THIS ISSUE SERIOUSLY. We are paid users and this is disruptive of the daily workflows.**
Not a maintainer — but this thread has two different 401s tangled together, and applying the wrong fix is why "logout / login / reinstall" isn't working for some of you. Splitting them:
Shape 1 — a stale/empty stored credential (the empty
refreshToken@TranBaDat2607 found). When~/.claude/.credentials.jsonhas a blankrefreshToken(oraccessToken), the silent token refresh fails and every request 401s. The reasonclaude logout+ deleting%APPDATA%\Claude/~/.config/claudedoesn't fix it for everyone: on macOS the credential also lives in the login Keychain (Keychain Access → search "Claude"), and on Windows in Credential Manager.logoutis supposed to clear it, but when it doesn't, your fresh/loginreads/writes the same stale entry. Fix: afterclaude logout, also delete the OS keychain / Credential Manager item and~/.claude/.credentials.json, then/login. Copying a known-good.credentials.jsonfrom a working machine (as @TranBaDat2607 did) works because it bypasses the broken refresh — but clearing the keychain entry is the cleaner local fix.Shape 2 — headless / remote where the OAuth callback can't be caught (@jocelynprevot's Codespaces / SSH / Chromebook case).
/loginopens a browser redirect tolocalhost, and a cloud/remote box has nothing listening there, so even freshly minted tokens never complete the handshake and get rejected. Don't keep regenerating tokens — run theclaude setup-tokenflow (made for headless), or do the OAuth on a local machine and copy the resulting~/.claude/.credentials.jsonover. The localhost-redirect limitation is the blocker, not your subscription.One money warning for everyone here: several comments mention "switch to API mode" as a workaround. Don't — for a subscription 401, choosing the API-key option silently moves you onto pay-as-you-go billing (a commenter above lost real money this way). It isn't a fix for a subscription auth problem; it's a separate metered account path. Stay on the subscription login.
If, after clearing the keychain + json and re-authing, you still 401 on a confirmed-active Pro/Max plan (no payment failure under claude.ai → Billing), that points upstream. The single most useful detail to post then: your platform, and whether
~/.claude/.credentials.jsonrepopulates with a non-emptyrefreshTokenafter/login— that one fact separates "client credential store is broken" (Shape 1, fixable locally) from "token issuance is failing server-side" (not yours to fix).Seem to have the same problem on Mac starting v2.1.191. Manually fall back to v2.1.187 as workaround.
Same issue