[FEATURE] --bare mode: option to preserve OAuth/keychain auth while skipping context

Status Fixed / completed
Maintainer reply None cached
Activity 10 comments · opened Mar 24, 2026 · closed Aug 17, 2026

Problem

--bare mode strips all auto-discovery, including OAuth and keychain authentication. This makes it unusable for tools that need clean, context-free API calls but rely on the CLI's built-in auth (e.g. team/company subscriptions where there is no explicit API key).

Use case

We maintain skill-validator, a CLI tool that scores Agent Skill files using an LLM-as-judge pattern. Each file is scored in isolation through a single prompt+response pair. We added a claude-cli provider that shells out to claude -p so users can score skills without managing API keys.

The scoring system is designed so that each call contains only a system prompt (the scoring rubric) and the file content. Local context like CLAUDE.md files, project memory, and rules act as hidden confounders that can bias scores and make them non-reproducible across environments.

--bare would solve this perfectly, except it also disables OAuth/keychain auth, which is the primary auth mechanism for users who don't have an explicit ANTHROPIC_API_KEY. This forces a choice between clean context isolation and working authentication.

Proposal

One of:

  1. A flag like --no-context that skips CLAUDE.md, memory, rules, hooks, and plugins but preserves the full auth chain (OAuth, keychain, API key).
  2. A --bare sub-option (e.g. --bare --auth) that re-enables auth discovery while keeping everything else stripped.
  3. Allow --bare to read OAuth/keychain credentials while still skipping all other auto-discovery.

Current workaround

We use claude -p without --bare and document that scores from the claude-cli provider may be less consistent than API-based providers due to injected local context.

View original on GitHub ↗

9 Comments

kevjin02 · 5 months ago

For the time being, I found running claude -p like this strips context to something equivalent to bare (3K tokens):

ENABLE_CLAUDEAI_MCP_SERVERS=false \
CLAUDE_CODE_DISABLE_AUTO_MEMORY=1 \
claude -p "your prompt" --tools "" 

And you can strip (100 tokens) even further by running:

ENABLE_CLAUDEAI_MCP_SERVERS=false \
CLAUDE_CODE_DISABLE_AUTO_MEMORY=1 \
claude \
  -p "*Your prompt*" \
  --system-prompt "*Your instructions*" \
  --tools ""

Unfortunately, couldn't find a workaround for CLAUDE.md besides running claude in a directory with a 1-word CLAUDE.md .

Bakr-Albakri · 5 months ago

Working workaround: --bare + apiKeyHelper (macOS)

Discovered this while building a multi-agent orchestrator that needs clean context isolation with Max subscription auth — same core problem described here.

The fix

--bare's own help text says auth is available via apiKeyHelper in --settings. You can read the existing OAuth token from the macOS keychain and pass it back through this channel, getting full --bare isolation with working auth.

Steps

1. Read the OAuth token from keychain:

TOKEN=$(security find-generic-password -s "Claude Code-credentials" -w \
  | python3 -c "import sys,json; print(json.loads(sys.stdin.read())['claudeAiOauth']['accessToken'])")

2. Create a temporary settings file:

echo "{\"apiKeyHelper\": \"echo $TOKEN\"}" > /tmp/bare-settings.json
chmod 600 /tmp/bare-settings.json

3. Run with --bare:

claude --bare --settings /tmp/bare-settings.json -p "your prompt" --output-format json

4. Clean up:

rm /tmp/bare-settings.json

What this gives you

| Concern | Status |
|---|---|
| CLAUDE.md auto-discovery | Stripped |
| Hooks, auto-memory, background prefetches | Stripped |
| Rules, plugins behavior | Stripped |
| OAuth/Max subscription auth | Working |
| Reproducible across environments | Yes (no local context contamination) |

What it doesn't fix

  • Plugins still appear in the system/init event, but they are inactive under --bare
  • macOS-specific — the security find-generic-password command reads from the macOS keychain. Linux would need a different credential lookup (possibly secret-tool or reading from ~/.claude/ config files)

Tested on

  • macOS 15.x (arm64)
  • Claude Code v2.1.87
  • Max subscription (OAuth)

For the skill-validator use case

This should solve the scoring reproducibility problem directly — --bare + apiKeyHelper gives you a fully isolated context with only your system prompt (the scoring rubric) and the file content, no hidden confounders, while using the team's existing OAuth auth.

dacharyc · 5 months ago

Thanks for the suggestion, @Bakr-Albakri .

For a handful of reasons, the apiKeyHelper isn't a good fit for enterprise adoption. While that's probably a good workaround for individuals, I don't view it as solving the problem for the entire skill-validator user base.

The -p flag reuses the existing user auth without any manipulation of API keys, so a bare-equivalent that preserves auth seems like the best path forward.

macsux · 4 months ago

BTW, this is much faster for extracting token then going through python:

TOKEN=$(security find-generic-password -s "Claude Code-credentials" -w | jq -r '.claudeAiOauth.accessToken')

You can also add this to your .zshrc if you're on mac to get claude-bare alias in your prompt that will inject --bare and the token for you automatically:

claude-bare() {
  local token settings
  token=$(security find-generic-password -s "Claude Code-credentials" -w | jq -r '.claudeAiOauth.accessToken')
  settings=$(mktemp)
  echo "{\"apiKeyHelper\": \"echo $token\"}" > "$settings"
  chmod 600 "$settings"
  claude --bare --settings "$settings" "$@"
  rm -f "$settings"
}
kennedybaird · 3 months ago

It would be really disappointing if Anthropic gives no path with OAuth and --bare - currently using claude code headless is the only way that I use the product, so it would be another significant negative against using Anthropic's services

chadfurman · 3 months ago

FWIW if you're running into this and you're not specifying --bare but you are specifying -p and you're still getting invalid auth errors, chances are you have an env var set:

env | grep -i "anthropic" | cut -d '=' -f 1

if you see something like ANTHROPIC_API_KEY then you can do:

unset ANTHROPIC_API_KEY

you'll then be able to run claude -p just fine. Your key is likely in a startup file for your shell so a new session should pick it back up if you need it

RatanKalpaSai · 3 months ago

Hitting the same issue with claude agents — it appears to run in bare mode and rejects CLAUDE_CODE_OAUTH_TOKEN with 401 Invalid bearer token. As a subscription user, this effectively makes the agents subcommand unusable without separately funding ANTHROPIC_API_KEY via Console credit.

The apiKeyHelper workaround doesn't help either — OAuth tokens (sk-ant-oat01-...) aren't accepted as bearer auth on the standard API endpoint, so returning the OAuth token from the helper still yields 401.

Strongly +1 option (3) from the proposal — let bare mode read OAuth/keychain creds even if it skips all other context.

Repro:

export CLAUDE_CODE_OAUTH_TOKEN=sk-ant-oat01-...
claude agents
# → Please run /login · API Error: 401 Invalid bearer token

Environment: Claude Code v2.1.140, macOS Darwin 25.5.0 (arm64), subscription auth only.

JeffreyChenTaiwan · 3 months ago
Hitting the same issue with claude agents — it appears to run in bare mode and rejects CLAUDE_CODE_OAUTH_TOKEN with 401 Invalid bearer token. As a subscription user, this effectively makes the agents subcommand unusable without separately funding ANTHROPIC_API_KEY via Console credit. The apiKeyHelper workaround doesn't help either — OAuth tokens (sk-ant-oat01-...) aren't accepted as bearer auth on the standard API endpoint, so returning the OAuth token from the helper still yields 401. Strongly +1 option (3) from the proposal — let bare mode read OAuth/keychain creds even if it skips all other context. Repro: export CLAUDE_CODE_OAUTH_TOKEN=sk-ant-oat01-... claude agents # → Please run /login · API Error: 401 Invalid bearer token Environment: Claude Code v2.1.140, macOS Darwin 25.5.0 (arm64), subscription auth only.

The oauth token first time you need run claude to active it. it's strangeness but work.

monkeyWzr-mf · 2 months ago

The documentation says

--bare is the recommended mode for scripted and SDK calls, and will become the default for -p in a future release.

I really hope the --bare with auth proposal is accepted before that happens. Otherwise, we won't be able to use claude -p with OAuth anymore 😢

Showing cached comments. Read the full discussion on GitHub ↗