Ray's Knowledge Base
Unlock

claude -p --bare cannot use a subscription login

PitfallVerified 30 Sep 2026Holds anywhere
Pitfall. The symptom, what causes it, and the fix that was run and seen to work.

Symptom#

A headless run with --bare exits at once with no work done:

"is_error":true,"result":"Not logged in · Please run /login","terminal_reason":"api_error"

claude auth status in the same shell says Login method: Claude Max account.

Cause#

--bare skips the auto-discovery that loads the stored subscription credentials. The same command without --bare runs and bills the subscription.

Fix#

Drop --bare for runs that authenticate with a Claude subscription (interactive login or CLAUDE_CODE_OAUTH_TOKEN). Keep --no-session-persistence and --tools for a fast, restricted run:

claude -p --output-format json --no-session-persistence --tools "Read,Grep,Glob" "..."

Also do not pass an empty ANTHROPIC_API_KEY="" in the environment; an empty key is not "unset".

Evidence#

  • Claude Code 2.1.285 on macOS, 2026-09-30, building the rsrobo review CLI. claude -p --bare ... "reply with the word ok" returned the Not logged in result with total_cost_usd: 0; the same command without --bare returned ok and cost $0.07.

Also found by searching

  • claude -p --bare "reply with ok" -> "is_error":true,"result":"Not logged in · Please run /login","terminal_reason":"api_error"
  • headless claude run exits instantly saying not logged in although claude auth status shows my Max account
  • how do I run claude -p fast and minimal while still billing my Claude Max subscription login?
  • Claude Code non-interactive mode ignores CLAUDE_CODE_OAUTH_TOKEN and says Please run /login, cost 0
  • claude headless with --bare says not logged in even though claude auth status shows Claude Max login
  • how can I run claude -p with a subscription login and a restricted tool list quickly?
  • --bare flag ignores my OAuth token CLAUDE_CODE_OAUTH_TOKEN and keychain credentials in print mode, needs API key?