[BUG] Non-interactive Claude Code (-p) cannot use existing Claude Pro login
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?
Summary
Claude Code interactive mode recognizes my Claude Pro subscription, but non-interactive print mode does not.
In the same machine/environment:
claudelaunches normally and shows me as logged in with Claude Proclaude -p ...fails withNot logged in · Please run /login
This reproduces on both:
- Windows PowerShell
- WSL (Ubuntu) Bash
It also happened after removing ANTHROPIC_API_KEY, so this does not appear to be just API-key precedence.
Claude Code version
v2.1.84
Subscription / account mode
- Claude Pro subscription
- not using Max
- interactive Claude Code shows the correct logged-in account and subscription
Environment
Windows
- Windows host
- PowerShell
Linux
- WSL Ubuntu
- same behavior there
Exact behavior
1. Interactive mode recognizes my subscription
Running:
claude
shows me as logged in, for example:
Claude Pro- correct account email
- normal interactive usage works
2. Non-interactive print mode does not
Running:
claude --model sonnet --effort high --allowedTools "Read" --bare -p "hi"
returns:
Not logged in · Please run /login
This happens even though interactive claude in the same environment is already logged in and works.
Additional observations
At first I also had ANTHROPIC_API_KEY set, and then non-interactive usage failed with:
Credit balance is too low
After unsetting ANTHROPIC_API_KEY, the failure changed to:
Not logged in · Please run /login
So:
- with
ANTHROPIC_API_KEYset, Claude Code appears to prefer API billing - without it, interactive subscription auth works
- but non-interactive
-pstill does not see login state
What Should Happen?
If interactive Claude Code is already logged in via Claude Pro subscription, non-interactive print mode should be able to use the same authenticated subscription state.
This should happen even if the ANTHROPIC_API_KEY env var is set.
Error Messages/Logs
Steps to Reproduce
Windows PowerShell
- Ensure
ANTHROPIC_API_KEYis unset:
Remove-Item Env:ANTHROPIC_API_KEY -ErrorAction SilentlyContinue
- Start interactive Claude:
claude
- Confirm the UI shows:
- logged-in account
- Claude Pro subscription
- Exit interactive Claude.
- Run:
claude --model sonnet --effort high --allowedTools "Read" --bare -p "hi"
- Observe:
Not logged in · Please run /login
WSL Ubuntu
- Start interactive Claude:
claude
- Confirm it shows:
- logged-in account
- Claude Pro subscription
- Exit.
- Run:
claude --model sonnet --effort high --allowedTools "Read" --bare -p "hi"
- Observe:
Not logged in · Please run /login
Claude Model
Not sure / Multiple models
Is this a regression?
I don't know
Last Working Version
_No response_
Claude Code Version
2.1.84
Platform
Anthropic API
Operating System
Windows
Terminal/Shell
PowerShell
Additional Information
Related:
#1932
This issue has 4 comments on GitHub. Read the full discussion on GitHub ↗