claude-code - 💡(How to fix) Fix [BUG] Bug Report: 401 Invalid Bearer Token Immediately After Successful Login [1 comments, 2 participants]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…
GitHub stats
anthropics/claude-code#48996Fetched 2026-04-17 08:53:43
View on GitHub
Comments
1
Participants
2
Timeline
4
Reactions
0
Timeline (top)
labeled ×3commented ×1

Error Message

Please run /login · API Error: 401 {"type":"error","error":{"type":"authentication_error","message":"Invalid bearer token"}

Credentials file after login correctly shows:

{ "claudeAiOauth": { "subscriptionType": "max", "rateLimitTier": "default_claude_max_20x" } }

Code Example

Please run /login · API Error: 401 {"type":"error","error":{"type":"authentication_error","message":"Invalid bearer token"}

Credentials file after login correctly shows:

{
  "claudeAiOauth": {
    "subscriptionType": "max",
    "rateLimitTier": "default_claude_max_20x"
  }
}
RAW_BUFFERClick to expand / collapse

Preflight Checklist

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

What's Wrong?

Claude Code returns a 401 authentication error immediately after a successful login. The login flow completes and shows "Login successful", but any subsequent message returns a 401 Invalid bearer token error. The UI also always displays "API Usage Billing" even after logging in with a subscription account (Option 1). A colleague using the exact same organization account on a different machine has no issues — their Claude Code works correctly and shows "Claude Max" after login.

What Should Happen?

After completing the OAuth login flow (Option 1 · Claude account with subscription), Claude Code should authenticate correctly, display "Claude Max" as the plan, and respond to messages without any 401 error.

Error Messages/Logs

Please run /login · API Error: 401 {"type":"error","error":{"type":"authentication_error","message":"Invalid bearer token"}

Credentials file after login correctly shows:

{
  "claudeAiOauth": {
    "subscriptionType": "max",
    "rateLimitTier": "default_claude_max_20x"
  }
}

Steps to Reproduce

  1. Run claude logout
  2. Delete %USERPROFILE%\.claude\.credentials
  3. Run claude and type /login
  4. Select Option 1 (Claude account with subscription · Pro, Max, Team, or Enterprise)
  5. Complete OAuth flow in Chrome browser — shows "Login successful"
  6. Type any message (e.g., hello or test)
  7. Immediately receives 401 Invalid bearer token error
  8. Repeating /login and sending a message always results in the same 401 error

Claude Model

Sonnet (default)

Is this a regression?

No, this never worked

Last Working Version

Claude Code Version

2.1.110 (native installer)

Platform

Other

Operating System

Windows

Terminal/Shell

Windows Terminal

Additional Information

  • Account type: Organization account (Max plan, rateLimitTier: default_claude_max_20x)
  • No ANTHROPIC_API_KEY environment variable is set
  • Reinstalling via native installer (claude install) did not resolve the issue
  • Deleting credentials and logging in multiple times did not resolve the issue
  • A colleague using the exact same organization account on a different Windows machine works fine and shows "Claude Max" after login
  • Browser used for OAuth: Google Chrome (single profile, organization account active)
  • The issue appears to be that the OAuth token is accepted during login but immediately rejected when making API calls

extent analysis

TL;DR

The most likely fix is to investigate and resolve the discrepancy between the successful OAuth login and the subsequent 401 Invalid bearer token error, potentially related to token storage or usage.

Guidance

  • Verify that the claudeAiOauth credentials are being stored and retrieved correctly, and that the token is being passed in the API requests.
  • Check for any differences in environment variables, browser settings, or system configurations between the working and non-working machines.
  • Attempt to use a different browser for the OAuth flow to rule out browser-specific issues.
  • Review the Claude Code documentation to ensure that the OAuth token is being used correctly in API requests.

Example

No code snippet is provided as the issue seems to be related to configuration or environment rather than code.

Notes

The issue may be specific to the Windows platform or the native installer, and further investigation is needed to determine the root cause. The fact that a colleague using the same organization account on a different machine has no issues suggests that the problem may be machine-specific.

Recommendation

Apply workaround: Try using a different browser for the OAuth flow or check for any browser extensions that may be interfering with the token storage or usage, as this may help to isolate the issue.

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING