Skip to content

VS Code extension always returns 401 "OAuth token has expired" on macOS 12 (Monterey) - cannot authenticate at all #43715

@kenjiswift

Description

@kenjiswift

What's Wrong?

The Claude Code VS Code extension (v2.1.92) constantly shows 401 {"type":"error","error":{"type":"authentication_error","message":"OAuth token has expired. Please obtain a new token or refresh your existing token."}} and cannot authenticate at all.

This has been happening for multiple days. Even after:

  • Complete VS Code uninstall and fresh reinstall
  • Clearing all keychain entries for "Claude Code-credentials"
  • Running claude auth login to get a fresh OAuth token
  • The CLI works fine (claude -p "test" returns OK with the keychain token)

The VS Code extension still shows 401 immediately after loading.

Key finding: The CLI binary works correctly using the keychain token. The VS Code extension does NOT work even with the same valid token in keychain.

What Should Happen?

VS Code extension should authenticate successfully using the valid OAuth token stored in the macOS keychain, just like the CLI does.

Error Messages/Logs

Failed to authenticate. API Error: 401 {"type":"error","error":{"type":"authentication_error","message":"OAuth token has expired. Please obtain a new token or refresh your existing token."}}
[WARN] [keychain] readAsync failed; serving stale cache

Request IDs for server-side lookup:

  • req_011CZjYvFh6CuVLGKfCM7Huc
  • req_011CZjaNANwkTHb1RoY6VUkc
  • req_011CZjhExmKMUXhbRkUzfMXf
  • req_011CZjhWVNz7Q23L9FcBHucQ

Steps to Reproduce

  1. Open VS Code with Claude Code extension installed (v2.1.92)
  2. Open the Claude Code panel
  3. Immediately see "Failed to authenticate. API Error: 401 OAuth token has expired"
  4. This happens even immediately after running claude auth login
  5. CLI works: env -u CLAUDE_CODE_OAUTH_TOKEN claude -p "test" → "OK"
  6. VS Code extension always returns 401

Additional Information

Environment:

  • OS: macOS 12.7.6 (Monterey)
  • VS Code: 1.114.0
  • Claude Code extension: v2.1.92
  • Claude Desktop: also running simultaneously

Root cause hypothesis:
CLAUDE_CODE_OAUTH_TOKEN env var is set by Claude Desktop app with an expired token. When VS Code inherits this env var, the CLI binary uses this expired token instead of the valid keychain token.

Also: [keychain] readAsync failed; serving stale cache suggests keychain reads may fail silently in VS Code context on macOS 12 Monterey.

This issue has persisted for multiple days. Please follow up — I would appreciate a response from the Anthropic team regarding compensation for this ongoing service disruption.

Metadata

Metadata

Assignees

No one assigned

    Labels

    area:authbugSomething isn't workinghas reproHas detailed reproduction stepsplatform:macosIssue specifically occurs on macOSplatform:vscodeIssue specifically occurs in VS Code

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions