Skip to content

[BUG] /login reports success but the bearer token is immediately invalid (401). #17402

Description

@mosseri

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?

After running /login, Claude Code reports "Login successful" but any subsequent prompt immediately fails with:
API Error: 401 {"type":"error","error":{"type":"authentication_error","message":"Invalid bearer token"},"request_id":"req_..."}
Environment:

Claude Code v2.1.3
macOS (Homebrew node via nvm)
Account: Pro subscription

Troubleshooting attempted:

Uninstalled/reinstalled Claude Code (npm)
Deleted ~/.claude, ~/.claude.json, ~/Library/Application Support/Claude
Confirmed no ANTHROPIC_API_KEY environment variable set
Tried OAuth flow in both Chrome and Safari
Logged out/in to claude.ai before re-authorizing

Observed behavior:

~/.claude.json shows "hasAvailableSubscription": false despite active Pro subscription
Header shows "API Usage Billing" instead of subscription-based billing
OAuth completes successfully in browser but token is rejected by API

Expected behavior:
OAuth login should return a valid bearer token that authenticates against the API.

What Should Happen?

After completing the OAuth flow, Claude Code should:

Receive a valid bearer token that authenticates successfully against the API
Detect the active Pro subscription and set hasAvailableSubscription: true
Display "Pro subscription" (not "API Usage Billing") in the header
Allow prompts to execute without 401 errors

Error Messages/Logs

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

Steps to Reproduce

Steps to Reproduce:

Ensure no ANTHROPIC_API_KEY environment variable is set (unset ANTHROPIC_API_KEY)
Remove existing Claude Code config: rm -rf ~/.claude ~/.claude.json
Run claude /login
Complete OAuth flow in browser (authorize access)
Observe "Login successful" message in terminal
Send any prompt (e.g., "hi")
Receive 401 "Invalid bearer token" error

Claude Model

None

Is this a regression?

I don't know

Last Working Version

No response

Claude Code Version

Claude Code v2.1.3

Platform

Anthropic API

Operating System

macOS

Terminal/Shell

Terminal.app (macOS)

Additional Information

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    duplicateThis issue or pull request already exists

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions