fix(converters): strip Claude Code 2.1.x billing attribution from sys…#214
Closed
liwenquantop-dot wants to merge 1 commit into
Closed
fix(converters): strip Claude Code 2.1.x billing attribution from sys…#214liwenquantop-dot wants to merge 1 commit into
liwenquantop-dot wants to merge 1 commit into
Conversation
|
Thank you for your pull request and welcome to our community. We could not parse the GitHub identity of the following contributors: liwenquan.
|
…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.
1bbe020 to
14fe863
Compare
|
Thanks for the PR! 🎉 Before merge, we need a one-time CLA confirmation. Full CLA text: Please reply once with: You need to write once, all further messages from me can be ignored. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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
cchtoken is a fresh random hex on every request. Becauseextract_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 forclaude -p/ SDK mode.)Solution
Add
_strip_billing_attribution()and call it fromextract_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 bySTRIP_BILLING_HEADER(defaulttrue) 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:
Byte-level check via
DEBUG_MODE=all: incoming body containscch=<hex>andx-anthropic-billing-header; outgoing Kiro payload has zero matches for either string.Alternative
CLAUDE_CODE_ATTRIBUTION_HEADER=0set 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: addSTRIP_BILLING_HEADERenv (default true)kiro/converters_anthropic.py: add_strip_billing_attribution(), apply inextract_system_prompt()