Skip to content

fix(proxy): strip Claude Code billing header from prompt for non-Anthropic providers#126

Open
jsboige wants to merge 1 commit into
MadAppGang:mainfrom
jsboige:fix/strip-billing-header
Open

fix(proxy): strip Claude Code billing header from prompt for non-Anthropic providers#126
jsboige wants to merge 1 commit into
MadAppGang:mainfrom
jsboige:fix/strip-billing-header

Conversation

@jsboige
Copy link
Copy Markdown

@jsboige jsboige commented May 16, 2026

Summary

Strips the x-anthropic-billing-header: cc_version=...; cch=XXXXX; line that Claude Code injects into the system prompt body when the request is not routed to Anthropic's native API.

Problem

Claude Code injects a billing header into the system field of every /v1/messages request. The cch= token changes on every request, which breaks prefix caching on self-hosted inference engines (vLLM, Ollama, LM Studio) that use strict hash matching for KV cache hits. Each request is treated as a unique prefix, resulting in zero cache hits and wasted GPU compute re-processing the same system prompt repeatedly.

Fix

  • In the /v1/messages handler, after resolving the handler and before forwarding, check if the handler is a NativeHandler (Anthropic direct).
  • If not native (i.e., OpenRouter, local models, custom endpoints, etc.), strip the billing header line from body.system using a regex.
  • Handles both string and array (block) forms of the system field per the Anthropic API spec.
  • Zero impact on Anthropic routing — native requests pass through unchanged.

Testing

  • Verified diff scope: only packages/cli/src/proxy-server.ts touched (23 insertions, 0 deletions).
  • The NativeHandler import already exists in the file — no new dependencies.

Co-Authored-By: Claude Opus 4.7 noreply@anthropic.com

@mtparet
Copy link
Copy Markdown
Contributor

mtparet commented May 19, 2026

We have the same fix #101 this is really a must have otherwise claudish is not usable because it cost 10X @erudenko

…ropic providers

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
@jsboige jsboige force-pushed the fix/strip-billing-header branch from f962278 to ed89ef7 Compare May 30, 2026 11:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants