User discovers Claude Code -p calls bypass flat-rate plan, causing API billing
A developer using Anthropic's Claude Code on the Max flat‑rate plan noticed a sudden spike in token usage over two days. The overnight batch that recreates old blog articles runs six times daily, each consuming about 750,000 input tokens and 90,000 output tokens. When the batch was executed in non‑interactive "-p" mode, the management console showed token spikes of roughly 7.2 million on 9/19,…
Key points
- Claude Code -p mode uses any ANTHROPICAPIKEY in the environment, sending usage to API billing instead of the flat‑rate plan.
- Token usage spiked to about 7.2 million tokens on 9/19 and ~4.8 million tokens on 9/21‑22 due to article‑recreation runs.
- Removing ANTHROPICAPIKEY and ANTHROPICAUTHTOKEN from the environment stopped API billing and restored flat‑rate usage.
Investigation revealed that the tool’s .env file contained an ANTHROPICAPIKEY (and ANTHROPICAUTHTOKEN). In "-p" mode Claude Code gives priority to any present API key, routing the request through the API rather than the flat‑rate quota. An experiment with an invalid key caused a 401 error, confirming the behavior. Removing the two environment variables from the call stopped the API‑based billing, and a follow‑up run succeeded using the flat‑rate quota.
The fix is a simple two‑line code change that strips the API keys from the environment before invoking Claude Code. Users running similar automation should audit their .env files to avoid unexpected charges.
The story so far
4 episodes →- User discovers Claude Code -p calls bypass flat-rate plan, causing API billingthis story
The AI overnight processing I thought was on a flat-rate plan was actually all being billed via API: -p in Claude Code and environment variable API keys
note.com · 22 September 2026
Loading the full article…
This text was published by note.com and written by ソルー@セット本せどり. It is reproduced here with attribution so you can read it in full; the rights remain with the publisher. Read it at the source ↗
The headline, key points and digest above were generated by Digest AI's editorial model from the linked sources. Automated summaries can contain errors: the sources are the record. Spotted a mistake? Tell us. Published by Martin K., who runs Digest AI and handles corrections.
More in Marketing & Small Business
All →- Higgsfield AI adds video ad features using GPT‑6 Astra · 2 src
- Opinion: use chatgpt’s three modes in order to avoid usage limits · 2 src
- Reactiv cuts merchant configuration time 80% with Amazon Bedrock AgentCore · 1 src
- How a lazy office worker uses Claude to sort tasks, draft messages, and write reports · 2 src
- Opinion: personal experience, voice, and judgment curb AI-like feel in ChatGPT articles · 5 src
Comments
via GitHub Discussions