[BUG] 401 "Invalid bearer token" caused by ANTHROPIC_AUTH_TOKEN environment variable

Resolved 💬 3 comments Opened Mar 16, 2026 by osvaldobuttarini-hue Closed Apr 13, 2026

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?

After /login (which reports success), every prompt fails with 401 "Invalid bearer token". This happens on both the Windows CLI (v2.1.76) and the Claude Desktop App. The root cause is the environment variable ANTHROPIC_AUTH_TOKEN which silently overrides the valid OAuth token. In my case it was set to "ollama" from a previous configuration. Removing it fixes the issue immediately.

What Should Happen?

Claude Code should either ignore ANTHROPIC_AUTH_TOKEN when OAuth login is used, or display a clear warning like: "⚠️ ANTHROPIC_AUTH_TOKEN environment variable detected. This overrides your subscription login. Remove it to use your Max/Pro plan."

Error Messages/Logs

Steps to Reproduce

  1. Set environment variable ANTHROPIC_AUTH_TOKEN to any value (e.g. ollama)
  2. Open Claude Code CLI or Claude Desktop App (Codice tab)
  3. Run /login — login reports success
  4. Send any message (e.g. "ciao")
  5. Error: 401 "Invalid bearer token"

The ANTHROPIC_AUTH_TOKEN env var silently overrides the valid OAuth token from login, causing all requests to fail. Removing it fixes the issue:

[System.Environment]::SetEnvironmentVariable("ANTHROPIC_AUTH_TOKEN", $null, "User")

Claude Code should warn when this variable is set and conflicts with OAuth credentials.

Claude Model

None

Is this a regression?

Yes, this worked in a previous version

Last Working Version

_No response_

Claude Code Version

2.1.76

Platform

Anthropic API

Operating System

Windows

Terminal/Shell

PowerShell

Additional Information

_No response_

View original on GitHub ↗

This issue has 3 comments on GitHub. Read the full discussion on GitHub ↗