[BUG] ANTHROPIC_API_KEY ignored on Windows when set at User scope — requires Machine scope to work
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?
TLDR; When switching from a 'MAX' style account to an 'API' account the system is not finding the 'User' Key now. It defaults to forcing the user to open a browser and I don't have an actual login for the API key..
Environment
- OS: Windows 11
- Claude Code version: 2.1.177
- Node/npm: latest
Problem
ANTHROPIC_API_KEY is completely ignored when set at Windows User scope. Claude Code always falls back to the OAuth browser login flow regardless of the key being present and valid.
Steps to Reproduce
- Set API key at User scope:
[System.Environment]::SetEnvironmentVariable("ANTHROPIC_API_KEY", "sk-ant-...", "User")
- Open a new PowerShell terminal
- Confirm key is visible: $env:ANTHROPIC_API_KEY (prints correctly)
- Run: claude
- Login prompt appears — API key is ignored
Additional confirming tests performed
- Deleted credentials.json to eliminate cached OAuth tokens
- Cleared session-env and sessions folders
- Injected key directly inline: $env:ANTHROPIC_API_KEY = "sk-ant-..."; claude — still prompted for login
- Tried claude --api-key flag — unknown option
Fix
Setting the key at Machine scope works immediately:
[System.Environment]::SetEnvironmentVariable("ANTHROPIC_API_KEY", "sk-ant-...", "Machine")
Impact
Users with Console-only accounts (no user login provisioned, API keys only) are completely blocked — OAuth login fails and User-scope env var is ignored, leaving no working auth path until Machine scope is discovered.
What Should Happen?
Expected behavior
ANTHROPIC_API_KEY at User scope should be sufficient to authenticate without any browser login flow.
Error Messages/Logs
Steps to Reproduce
- Set API key at User scope:
[System.Environment]::SetEnvironmentVariable("ANTHROPIC_API_KEY", "sk-ant-...", "User")
- Open a new PowerShell terminal
- Confirm key is visible: $env:ANTHROPIC_API_KEY (prints correctly)
- Run: claude
- Login prompt appears — API key is ignored
Claude Model
Not sure / Multiple models
Is this a regression?
I don't know
Last Working Version
_No response_
Claude Code Version
2.1.177
Platform
Anthropic API
Operating System
Windows
Terminal/Shell
PowerShell
Additional Information
_No response_
This issue has 2 comments on GitHub. Read the full discussion on GitHub ↗