claude-code icon indicating copy to clipboard operation
claude-code copied to clipboard

[BUG] Claude Code OAuth Authentication Fails - "OAuth account information not found in config"

Open hellohqd opened this issue 8 months ago • 8 comments

Environment

  • Claude Code version: 1.0.6
  • Operating System: macOS
  • Node.js version: v22.16.0
  • npm version: 10.9.2
  • Account type: Claude Max subscription
  • Network environment: Corporate network with specific routing requirements

Description

Claude Code fails to complete OAuth authentication in my network environment, consistently showing the error:

OAuth error: Failed to fetch user roles: OAuth account information not found in config

Steps to Reproduce

  1. Install Claude Code: npm install -g @anthropic-ai/claude-code
  2. Run Claude Code: claude
  3. Select theme (any option)
  4. Select login method: "2. Claude app (requires Max subscription)"
  5. Browser opens OAuth page successfully
  6. Complete authorization (shows "You're all set up for Claude Code")
  7. Return to terminal
  8. Error appears: OAuth error: Failed to fetch user roles: OAuth account information not found in config

Expected Behavior

After OAuth authorization, Claude Code should successfully authenticate and start normally.

Actual Behavior

Despite successful OAuth flow in browser, Claude Code fails to save or retrieve the authentication configuration, resulting in the error message. The browser shows "You're all set up" but the CLI cannot proceed.

Additional Context

  • The OAuth flow completes successfully in browser
  • Sometimes an authentication code is displayed to paste into Claude Code, but entering it doesn't resolve the issue
  • The error suggests the OAuth account information is not being properly saved to the config file
  • Message "Creating API key for Claude Code..." appears briefly before the error

Troubleshooting Attempted

  1. Complete uninstall and cleanup:
    npm uninstall -g @anthropic-ai/claude-code
    rm -rf ~/.claude
    rm -rf ~/.npm-global/lib/node_modules/@anthropic-ai/
    rm -rf ~/Library/Application\ Support/ClaudeCode
    npm cache clean --force
    
  2. Tried both login methods (Claude app & Anthropic Console) - same error
  3. Tested with different browsers (Safari, Chrome)
  4. Fresh install on clean system

Possible Cause

The issue appears to be related to Claude Code's OAuth callback handling or configuration file creation/reading after successful browser authentication.

Related Issues

Similar authentication issues reported by other users with Max subscriptions, suggesting this might be a broader issue with the OAuth implementation.

hellohqd avatar Jun 01 '25 17:06 hellohqd

Some things you can try:

  1. Remove ~/.claude.json, not just ~/.claude.
  2. Can you check if your network allows https://api.anthropic.com? Claude Code makes a couple calls there for authentication.
  3. Can you try downloading and logging in to a newer version (v1.0.11, for example)

dicksontsai avatar Jun 05 '25 07:06 dicksontsai

Some things you can try:

  1. Remove ~/.claude.json, not just ~/.claude.
  2. Can you check if your network allows https://api.anthropic.com? Claude Code makes a couple calls there for authentication.
  3. Can you try downloading and logging in to a newer version (v1.0.11, for example)

Update: Even single character commands like 'h' or 'pwd' result in the same error: "API Error: Cannot convert argument to a ByteString because the character at index 0 has a value of 8217"

This happens with ANY input, suggesting a critical bug in Claude Code's character encoding handling.

Environment details:

  • macOS Terminal works fine (echo "test" works)
  • Using API key authentication (Max member OAuth also failed)
  • Error persists after removing all config files
  • Version: [run claude --version to check]

hellohqd avatar Jun 05 '25 14:06 hellohqd

There seems to be a different error here related to your input.

The character at index 0 with value 8217 is a right single quotation mark (' - Unicode U+2019). This is a "smart quote" or "curly quote" that's commonly inserted by word processors, rich text editors, or when copying text from formatted documents.

Can you share a screenshot of the API Error and also the result of /status?

dicksontsai avatar Jun 05 '25 16:06 dicksontsai

Here's the screenshot showing both the API error and /status result:

Image

Key observations:

  • Error occurs when typing single character 'h'
  • Claude Code Status: v1.0.11
  • Auth Token: none (using API Key authentication instead)
  • API Key: ANTHROPIC_API_KEY (environment variable)
  • Model: claude-sonnet-4-20250514
  • Working Directory: /Users/moment

The error happens with ANY input, suggesting the issue is in Claude Code's input handling before it reaches the API.

hellohqd avatar Jun 05 '25 17:06 hellohqd

Ok I think there's something wrong with how the OAuth was saved. Can you try:

  1. security delete-generic-password -a $USER -s "Claude Code-credentials"
  2. Run /login again.

If that still doesn't work, I don't have many remaining ideas...

dicksontsai avatar Jun 05 '25 17:06 dicksontsai

Thank you for the suggestion! It helped uncover the root cause:

What I discovered:

  1. security delete-generic-password returned "item could not be found" - meaning OAuth credentials were never saved to keychain
  2. This explains why authentication never persists

Testing OAuth flow:

  • OAuth browser flow completes successfully
  • But Claude Code fails with: "Failed to fetch user roles: Request failed with status code 403"
  • Since user roles can't be fetched, credentials are never saved to keychain
  • This creates the authentication loop

Two separate bugs identified:

  1. OAuth Bug: 403 error when fetching user roles (prevents Max subscription login)
  2. Input Bug: ByteString encoding error with ANY input after authentication fails

The OAuth credentials not being in keychain is a symptom, not the cause - they can't be saved because the user role fetch fails with 403.

Environment: macOS, Max subscription, v1.0.11

hellohqd avatar Jun 05 '25 18:06 hellohqd

You may be running into the following issue: https://www.anthropic.com/supported-countries

Thanks for your patience in debugging this with me.

dicksontsai avatar Jun 05 '25 18:06 dicksontsai

Actually, based on the fact that you see "fetching user roles", you are likely going through the "Anthropic Console account" flow instead of the "Claude account with subscription" flow. Ensure that you are selecting "Claude account with subscription" if you want to use your Claude Max plan.

dicksontsai avatar Jun 05 '25 18:06 dicksontsai

Fixed my issue. Thx

floresfreddy avatar Jun 26 '25 23:06 floresfreddy

Sorry to reopen the issue but I am getting this right now, maybe related to the outage that you guys had today:

claude -p hi
API Error: 401 {"type":"error","error":{"type":"authentication_error","message":"Invalid OAuth token. The provided token was not found or is malformed."}}

I am trying to use my claude code account. I've already removed the .claude files, reinstalled the npm package and logged out & back in, same deal.

Any ideas?

darkguy2008 avatar Jul 10 '25 00:07 darkguy2008

Must be an outage. I just encountered the same.

rnmp avatar Jul 10 '25 00:07 rnmp

Same

MintCollector avatar Jul 10 '25 00:07 MintCollector

Same here, time to hit the hay

kootenpv avatar Jul 10 '25 00:07 kootenpv

Same

Neiso avatar Jul 10 '25 00:07 Neiso

same

imWildCat avatar Jul 10 '25 00:07 imWildCat

Hopping on the "same" bandwagon

tansanDOTeth avatar Jul 10 '25 00:07 tansanDOTeth

same me too

5AMLab avatar Jul 10 '25 00:07 5AMLab

same :)

agamm avatar Jul 10 '25 00:07 agamm

Same

yr99jparkin avatar Jul 10 '25 00:07 yr99jparkin

Same

illusivejosiah avatar Jul 10 '25 00:07 illusivejosiah

Same

lsgrep avatar Jul 10 '25 00:07 lsgrep

Same

cameronembling avatar Jul 10 '25 01:07 cameronembling

seems to be working for me now

theprestonian avatar Jul 10 '25 01:07 theprestonian

When your dealers phone stops working

cameronembling avatar Jul 10 '25 01:07 cameronembling

lmaoooo all bros here

time to hit the gym

0xDAEF0F avatar Jul 10 '25 01:07 0xDAEF0F

same here. I thought it was because I installed both the local and global versions of Claude Code by mistake, but it seems to be a bug.

sumhwang avatar Jul 10 '25 01:07 sumhwang

Image

rnmp avatar Jul 10 '25 01:07 rnmp

same issue here

nidty719 avatar Jul 10 '25 01:07 nidty719

I'm having the same issue with the exact same error message. Haven't logged in for a week... Definitely on Anthropic's side.

Crohnos avatar Jul 10 '25 01:07 Crohnos

same issue.

mak-john avatar Jul 10 '25 01:07 mak-john