[BUG] Claude code -p mode authentication does not work
Environment
- Platform (select one):
- [ ] Anthropic API
- [ ] AWS Bedrock
- [ ] Google Vertex AI
- [ ] Other: Just terminal on Mac using Claude Code
- Claude CLI version: 1.0.3 (Claude Code)
- Operating System: macOS 15.4.1
- Terminal: Terminal App
Bug Description
"claude -p" mode does not authenticate although interactive mode is authenticated.
claude -p "test"
Invalid API key · Please run /login
I have done web site authentication for Claude Code interactive mode and it works just fine. Documentation (and claude 4) says that: "The -p mode should use the same authentication as interactive mode." but clearly it is not working. I have nothing authentication related in my .claude/settings.json.
Steps to Reproduce
- Run "claude /login"
- Follow the instructions and authenticate using the web method
- Ensure claude interactive mode is working by making any prompt
- Quite interactive mode
- Run "claude -p "test"
Expected Behavior
Claude Code would execute the test prompt
Actual Behavior
Claude Code responds with:Invalid API key · Please run /login
Additional Context
It used to work with beta version although there were random authentication issues and I had to sometimes do the /login again which every time causes a new Claude Code API key to be generated.
This issue has 3 comments on GitHub. Read the full discussion on GitHub ↗