Billing-header nonce (`cch`) in system prompt breaks prompt caching on third-party providers
Summary
When using Claude Code against a third-party Anthropic-compatible endpoint via ANTHROPIC_BASE_URL, the first system block of every /v1/messages request is a billing/telemetry header:
x-anthropic-billing-header: cc_version=2.1.177.01c; cc_entrypoint=sdk-cli; cch=<NONCE>;
The cch= value changes on every request. For providers that do automatic prefix-based caching (and don't honor Anthropic's cache_control breakpoints), this mutable token sits at the very start of the prompt and busts the cache for the entire downstream prefix (system instructions + tools), which is otherwise byte-identical turn-to-turn.
Result: 0% prompt-cache hit → inflated input cost and higher TTFT, even though the system prompt and tool definitions never change within a session.
Reproduction
- Point
ANTHROPIC_BASE_URLat a provider that does prefix caching (e.g. Fireworks AI,https://api.fireworks.ai/inference). - Run two turns in the same session.
- Inspect the request bodies, or the provider's reported
cache_read_input_tokens.
Captured first system block on two consecutive requests in the same session:
- Request 1:
...; cch=36ee5; - Request 2:
...; cch=0aaa9;
Everything after that block is identical, but because the prefix differs, the provider re-processes the full (~38k-token) prefix every turn — cache_read_input_tokens: 0.
Confirmation
Placing a tiny normalizing proxy in front of the provider that simply strips the x-anthropic-billing-header block (leaving everything else untouched) takes the cache from 0% → ~99.7% (cache_read_input_tokens ≈ full prefix), with no behavior change.
CLAUDE_CODE_DISABLE_NONESSENTIAL_TRAFFIC=1 does not remove the block.
Suggestion
A few options that would fix this for prefix-caching providers without affecting Anthropic's own cache_control-based caching:
- Place the billing/telemetry header after the cacheable content (system + tools), so the mutable token isn't part of the cached prefix; or
- Make the per-request
cchnonce optional / disable-able (e.g. via an env var); or - Move it out of the
systemarray into an HTTP header instead.
Environment
- Claude Code v2.1.177
- Windows 11, PowerShell
- Third-party provider via
ANTHROPIC_BASE_URL(Anthropic-compatible/v1/messages)
This issue has 2 comments on GitHub. Read the full discussion on GitHub ↗