[BUG] Claude code -p mode authentication does not work

Resolved 💬 3 comments Opened May 27, 2025 by timoruokonen Closed Dec 10, 2025

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

  1. Run "claude /login"
  2. Follow the instructions and authenticate using the web method
  3. Ensure claude interactive mode is working by making any prompt
  4. Quite interactive mode
  5. 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.

View original on GitHub ↗

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