claude-code - 💡(How to fix) Fix claude -p --bare ignores ANTHROPIC_API_KEY (and --settings.apiKey/apiKeyHelper) — auth always fails

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…

claude -p --bare returns "Not logged in · Please run /login" for every invocation regardless of how the API key is supplied. The --help text explicitly promises:

Anthropic auth is strictly ANTHROPIC_API_KEY or apiKeyHelper via --settings (OAuth and keychain are never read).

In practice, none of three documented auth paths work.

Root Cause

claude -p --bare returns "Not logged in · Please run /login" for every invocation regardless of how the API key is supplied. The --help text explicitly promises:

Anthropic auth is strictly ANTHROPIC_API_KEY or apiKeyHelper via --settings (OAuth and keychain are never read).

In practice, none of three documented auth paths work.

Fix Action

Fix / Workaround

This is a recurring issue — my project has hit it across two separate workflows (yonatangross/orchestkit#1629 ~6 months ago, yonatangross/orchestkit#1857 today). Each time the workaround is the same: drop --bare. Filing here so it gets fixed upstream instead of being routed around for a third time.

Workaround currently shipped downstream

Code Example

# Path 1: ANTHROPIC_API_KEY env var (per --help)
ANTHROPIC_API_KEY=sk-ant-... claude -p --bare --max-turns 1 --output-format json "hi"
# → {"is_error":true, "result":"Not logged in · Please run /login"}

# Path 2: apiKey via --settings (per --help)
echo '{"apiKey":"sk-ant-..."}' > /tmp/s.json
claude -p --bare --settings /tmp/s.json --max-turns 1 --output-format json "hi"
# → same failure

# Path 3: apiKeyHelper via --settings (per --help)
echo '{"apiKeyHelper":"echo sk-ant-..."}' > /tmp/s.json
claude -p --bare --settings /tmp/s.json --max-turns 1 --output-format json "hi"
# → same failure

---

ANTHROPIC_API_KEY=sk-ant-... claude -p --max-turns 1 --output-format json "hi"
# → {"is_error":false, "result":"Hi there, friend."}
RAW_BUFFERClick to expand / collapse

Summary

claude -p --bare returns "Not logged in · Please run /login" for every invocation regardless of how the API key is supplied. The --help text explicitly promises:

Anthropic auth is strictly ANTHROPIC_API_KEY or apiKeyHelper via --settings (OAuth and keychain are never read).

In practice, none of three documented auth paths work.

Version

claude --version2.1.143 (Claude Code) · macOS 25.4.0 (Darwin)

Reproducer (all three paths fail)

# Path 1: ANTHROPIC_API_KEY env var (per --help)
ANTHROPIC_API_KEY=sk-ant-... claude -p --bare --max-turns 1 --output-format json "hi"
# → {"is_error":true, "result":"Not logged in · Please run /login"}

# Path 2: apiKey via --settings (per --help)
echo '{"apiKey":"sk-ant-..."}' > /tmp/s.json
claude -p --bare --settings /tmp/s.json --max-turns 1 --output-format json "hi"
# → same failure

# Path 3: apiKeyHelper via --settings (per --help)
echo '{"apiKeyHelper":"echo sk-ant-..."}' > /tmp/s.json
claude -p --bare --settings /tmp/s.json --max-turns 1 --output-format json "hi"
# → same failure

Tested with HOME=$(mktemp -d) (no prior CC state on disk) — same result.

Same ANTHROPIC_API_KEY env var works without --bare:

ANTHROPIC_API_KEY=sk-ant-... claude -p --max-turns 1 --output-format json "hi"
# → {"is_error":false, "result":"Hi there, friend."}

Impact

--bare is the recommended path for headless CI/CD invocations (skips plugin/hook/LSP load → predictable token cost). Without it, every CI workflow that uses Claude Code must use full plain claude -p, which roughly 2.5× the per-invocation token cost (and pulls in plugins+hooks that bare was meant to skip).

This is a recurring issue — my project has hit it across two separate workflows (yonatangross/orchestkit#1629 ~6 months ago, yonatangross/orchestkit#1857 today). Each time the workaround is the same: drop --bare. Filing here so it gets fixed upstream instead of being routed around for a third time.

Expected behavior

Either:

  1. --bare honors ANTHROPIC_API_KEY env var per the help text — preferred, matches docs.
  2. OR: --help text is corrected to document the actual auth path (3P providers only? specific env var name? specific settings shape?).

Suggested test addition

A non-interactive end-to-end test that exercises claude -p --bare --max-turns 1 --output-format json "..." with ANTHROPIC_API_KEY set and asserts is_error == false.

Workaround currently shipped downstream

fix(ci-sentinel): drop --bare (auth broken) — yonatangross/orchestkit#1857. Trade-off documented in the PR body.

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

FAQ

Expected behavior

Either:

  1. --bare honors ANTHROPIC_API_KEY env var per the help text — preferred, matches docs.
  2. OR: --help text is corrected to document the actual auth path (3P providers only? specific env var name? specific settings shape?).

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING

claude-code - 💡(How to fix) Fix claude -p --bare ignores ANTHROPIC_API_KEY (and --settings.apiKey/apiKeyHelper) — auth always fails