[BUG] Interactive Mode Ignores ANTHROPIC_API_KEY — Requires /login Despite Valid Auth
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?
Title
claude interactive mode says "Not logged in" despite ANTHROPIC_API_KEY being set and claude -p working correctly
Description
Claude Code interactive mode refuses to use ANTHROPIC_API_KEY environment variable for authentication, always requiring /login (OAuth flow). However, claude -p (print mode) works perfectly with the same API key.
Environment
Claude Code version: 2.1.50
OS: Ubuntu 22.04 (GCP VM, headless/SSH)
Shell: bash
Installation method: curl -fsSL https://claude.ai/install.sh | bash
Workaround
claude -p "message" works for non-interactive use, but loses the interactive features (multi-turn conversation context, tool approval UI, etc.).
Suggested Fix
Interactive mode should work with ANTHROPIC_API_KEY alone, without requiring a prior OAuth /login. The behavior should match claude -p, which already works correctly with just the API key.
What Should Happen?
Expected Behavior
Interactive mode should use ANTHROPIC_API_KEY for API calls, just like claude -p does. claude auth status confirms the key is recognized and valid.
Actual Behavior
Interactive mode blocks all messages with Not logged in · Please run /login, even though:
claude auth status shows "loggedIn": true
claude -p works perfectly with the same API key
The API key is confirmed valid via direct curl calls
Error Messages/Logs
Steps to Reproduce
Steps to Reproduce
Set ANTHROPIC_API_KEY in environment or in ~/.claude/settings.json:
bashCopyexport ANTHROPIC_API_KEY="sk-ant-api03-..."
jsonCopy// ~/.claude/settings.json
{
"env": {
"ANTHROPIC_API_KEY": "sk-ant-api03-..."
},
"model": "opus"
}
Verify auth status:
bashCopy$ claude auth status
{
"loggedIn": true,
"authMethod": "api_key",
"apiProvider": "firstParty",
"apiKeySource": "ANTHROPIC_API_KEY"
}
Verify API key works via print mode:
bashCopy$ claude -p "hello"
Hello! How can I help you today? # ✅ Works
Verify API key works via curl:
bashCopy$ curl https://api.anthropic.com/v1/messages \
-H "x-api-key: $ANTHROPIC_API_KEY" \
-H "content-type: application/json" \
-H "anthropic-version: 2023-06-01" \
-d '{"model": "claude-sonnet-4-20250514", "max_tokens": 50, "messages": [{"role": "user", "content": "say hi"}]}'
✅ Returns valid response
Run interactive mode:
bashCopy$ claude
Type any message:
Copy❯ hi
⎿ Not logged in · Please run /login
Additional Context
Running /login inside interactive mode forces an OAuth flow that connects to a different workspace/organization — one that may have different billing/limits than the workspace the API key belongs to.
On a macOS laptop with the same API key AND a prior OAuth login (authMethod: "claude.ai"), interactive mode works — it shows "Auth conflict: Using ANTHROPIC_API_KEY instead of Anthropic Console key" and uses the API key. This suggests interactive mode requires an OAuth login to exist first, then optionally overrides it with ANTHROPIC_API_KEY.
On a headless Linux VM without a prior OAuth login, there is no way to make interactive mode work with just an API key.
The OAuth token is stored in the system keyring (secret-service/gnome-keyring), not in ~/.claude/ files, making it difficult to manage on headless servers.
Claude Model
Opus
Is this a regression?
I don't know
Last Working Version
_No response_
Claude Code Version
2.1.50
Platform
Anthropic API
Operating System
macOS
Terminal/Shell
Terminal.app (macOS)
Additional Information
_No response_
This issue has 11 comments on GitHub. Read the full discussion on GitHub ↗