Skip to content

fix(converters): strip Claude Code 2.1.x billing attribution from sys…#214

Closed
liwenquantop-dot wants to merge 1 commit into
jwadow:mainfrom
liwenquantop-dot:fix/strip-billing-attribution-cch
Closed

fix(converters): strip Claude Code 2.1.x billing attribution from sys…#214
liwenquantop-dot wants to merge 1 commit into
jwadow:mainfrom
liwenquantop-dot:fix/strip-billing-attribution-cch

Conversation

@liwenquantop-dot

Copy link
Copy Markdown

Problem

Claude Code 2.1.x prepends a per-request system text block of the form:

x-anthropic-billing-header: cc_version=2.1.153.d02; cc_entrypoint=sdk-cli; cch=<5hex>;

The cch token is a fresh random hex on every request. Because extract_system_prompt() concatenates all system text blocks into a single string before forwarding to Kiro, this random prefix poisons the prompt seen by upstream and invalidates any prefix-keyed prompt cache. (The attribution header is meant to be an HTTP header but ships in the request body for claude -p / SDK mode.)

Solution

Add _strip_billing_attribution() and call it from extract_system_prompt() for both string and list system formats. Pure-attribution blocks are dropped; mixed blocks have the leading attribution line removed. Behavior is gated by STRIP_BILLING_HEADER (default true) so it can be disabled for A/B comparison.

Empirical validation (local)

Replay benchmark using real captured Claude Code body (212KB, 3 system blocks), N=30 interleaved, randomized cch per request:

Metric Baseline (no strip) Patched (strip) Δ
TTFB mean 4813ms 4238ms -574ms (-11.9%)
TTFB median 4506ms 3952ms -554ms (-12.3%)
TTFB p95 6263ms 4958ms -1305ms (-20.8%)

Byte-level check via DEBUG_MODE=all: incoming body contains cch=<hex> and x-anthropic-billing-header; outgoing Kiro payload has zero matches for either string.

Alternative

CLAUDE_CODE_ATTRIBUTION_HEADER=0 set in the client environment achieves the same effect on the Claude Code side. The gateway-level fix is complementary and protects users / clients that don't (or can't) set the env var.

Files

  • kiro/config.py: add STRIP_BILLING_HEADER env (default true)
  • kiro/converters_anthropic.py: add _strip_billing_attribution(), apply in extract_system_prompt()

@cla-bot

cla-bot Bot commented Jun 11, 2026

Copy link
Copy Markdown

Thank you for your pull request and welcome to our community. We could not parse the GitHub identity of the following contributors: liwenquan.
This is most likely caused by a git client misconfiguration; please make sure to:

  1. check if your git client is configured with an email to sign commits git config --list | grep email
  2. If not, set it up using git config --global user.email email@example.com
  3. Make sure that the git commit email is configured in your GitHub account settings, see https://github.com/settings/emails

…tem prompt

Claude Code 2.1.x prepends a per-request system text block of the form:

  x-anthropic-billing-header: cc_version=2.1.153.d02; cc_entrypoint=sdk-cli; cch=<5hex>;

The cch segment is a fresh random hex token on every request. Because
extract_system_prompt() concatenates all system text blocks into a single
string before forwarding to Kiro, this random prefix poisons the prompt
seen by the upstream and invalidates any prefix-keyed prompt cache (the
attribution header is meant to be an HTTP header but ships in body here).

Add _strip_billing_attribution() and call it from extract_system_prompt()
for both string and list system formats. Blocks that are pure attribution
are dropped; mixed blocks have the leading attribution line removed.

The behavior is gated by STRIP_BILLING_HEADER (default true) so it can be
disabled for A/B comparison.
@liwenquantop-dot liwenquantop-dot force-pushed the fix/strip-billing-attribution-cch branch from 1bbe020 to 14fe863 Compare June 11, 2026 10:39
@cla-bot

cla-bot Bot commented Jun 11, 2026

Copy link
Copy Markdown

Thanks for the PR! 🎉

Before merge, we need a one-time CLA confirmation.
It confirms that you have the right to contribute this code and allow the project to use it.

Full CLA text:
https://github.com/jwadow/kiro-gateway/blob/main/CLA.md

Please reply once with:

I have read the CLA and I accept its terms

You need to write once, all further messages from me can be ignored.

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.

1 participant