[Bug] Claude Code subprocess silently uses API key auth instead of subscription, draining credits
Bug Description
Title: Assistant-initiated claude -p subprocesses silently drained API
credits despite active Max subscription and user-side guardrails
## What happened
- I'm a Max subscriber. I keep ANTHROPIC_API_KEY exported in my shell
for SDK development — like most developers building on the API.
- I was aware API-key precedence interferes with subscription auth, so I
had explicitly guarded against it: my shell aliases claude to
env -u ANTHROPIC_API_KEY claude.
- During an interactive Claude Code session (billed to my subscription,
as expected), the assistant used its Bash tool to run a batch of
claude -p calls to parallelize a task I asked for.
- Those subprocesses bypassed my alias (aliases don't expand in
non-interactive shells), picked up the env API key per the documented
precedence, and silently drained my entire prepaid API balance (~$15)
to zero. The first indication was batch calls failing with
"Credit balance is too low."
- Support confirmed: consumed credits are non-refundable per Credit
Terms. So this failure mode is unrecoverable once it happens.
## Why this is a product-design problem, not user error
1. The population with ANTHROPIC_API_KEY in their environment
(developers building on the API) overlaps almost completely with
Claude Code's core users. This collision is the default case, not an
edge case.
2. "It's documented" is not a defense here: -p prints no warning and
no indicator of which auth/billing route it used. The docs sentence
("the key is always used when present") is discovered after the
money is gone.
3. Most importantly: I had already defended against this, and my
guardrail was structurally unable to help — because the calls were
initiated by the assistant, not by me. Users cannot see, intercept,
or configure the billing route of processes the agent spawns. As
agentic usage grows, "the assistant launched headless sub-instances
I didn't know were separately billed" will become a common and very
trust-damaging failure mode.
## Suggested fixes (any one of these would have prevented this)
- Print the active auth/billing source (subscription vs API key) as one
stderr line on every -p invocation.
- Warn (or require one-time confirmation) when -p is about to bill
API credits while a subscription login exists on the machine.
- Provide a user-level setting to prefer subscription auth over an env
API key. Currently impossible: the fixed precedence ranks
ANTHROPIC_API_KEY above subscription OAuth, with no override.
- When Claude Code's own Bash tool spawns claude subprocesses,
default them to the parent session's auth — the user's intent is
clearly "this session's billing."
Amount involved is small (~$15). The pattern is not.
Environment Info
- Platform: darwin
- Terminal: Apple_Terminal
- Version: 2.1.220
- Feedback ID: 91adbc21-5f13-4a4b-8168-2a01d10e4dc9
Errors
[]