[FEATURE] --bare mode: option to preserve OAuth/keychain auth while skipping context
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:
- A flag like
--no-contextthat skips CLAUDE.md, memory, rules, hooks, and plugins but preserves the full auth chain (OAuth, keychain, API key). - A
--baresub-option (e.g.--bare --auth) that re-enables auth discovery while keeping everything else stripped. - Allow
--bareto 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.
Showing cached comments. Read the full discussion on GitHub ↗
9 Comments
For the time being, I found running
claude -plike this strips context to something equivalent to bare (3K tokens):And you can strip (100 tokens) even further by running:
Unfortunately, couldn't find a workaround for CLAUDE.md besides running claude in a directory with a 1-word CLAUDE.md .
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 viaapiKeyHelperin--settings. You can read the existing OAuth token from the macOS keychain and pass it back through this channel, getting full--bareisolation with working auth.Steps
1. Read the OAuth token from keychain:
2. Create a temporary settings file:
3. Run with
--bare:4. Clean up:
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
system/initevent, but they are inactive under--baresecurity find-generic-passwordcommand reads from the macOS keychain. Linux would need a different credential lookup (possiblysecret-toolor reading from~/.claude/config files)Tested on
For the skill-validator use case
This should solve the scoring reproducibility problem directly —
--bare+apiKeyHelpergives 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.Thanks for the suggestion, @Bakr-Albakri .
For a handful of reasons, the
apiKeyHelperisn'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 entireskill-validatoruser base.The
-pflag reuses the existing user auth without any manipulation of API keys, so a bare-equivalent that preserves auth seems like the best path forward.BTW, this is much faster for extracting token then going through python:
You can also add this to your
.zshrcif you're on mac to getclaude-barealias in your prompt that will inject--bareand the token for you automatically: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 servicesFWIW 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:
if you see something like ANTHROPIC_API_KEY then you can do:
you'll then be able to run
claude -pjust fine. Your key is likely in a startup file for your shell so a new session should pick it back up if you need itHitting the same issue with
claude agents— it appears to run in bare mode and rejectsCLAUDE_CODE_OAUTH_TOKENwith401 Invalid bearer token. As a subscription user, this effectively makes theagentssubcommand unusable without separately fundingANTHROPIC_API_KEYvia Console credit.The
apiKeyHelperworkaround 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:
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.
The documentation says
I really hope the
--bare with authproposal is accepted before that happens. Otherwise, we won't be able to useclaude -pwith OAuth anymore 😢