CLAUDE_CODE_ATTRIBUTION_HEADER causes cache invalidation - CC Switch Fix
Quick fix
Set CLAUDE_CODE_ATTRIBUTION_HEADER=0 to disable the dynamic request header and restore KV cache hits.
Symptom
Section titled “Symptom”缓存固定为13824Cache is fixed at 13824
Starting from Claude Code v2.1.36, every API request includes an `x-anthropic-billing-header` with dynamic values such as cc_version and cc_entrypoint. These changing header values break KV cache prefix matching, forcing full prompt processing on every request. This increases latency and cost, and appears as cache counts not updating or staying fixed.
Many third-party proxies, such as LiteLLM and claude-code-router, do not recognize this header and may return ValidationException. Setting the environment variable `CLAUDE_CODE_ATTRIBUTION_HEADER=0` disables the header and restores normal cache behavior. Note: older Claude Code versions, such as v2.1.148, may have compatibility issues; update to the latest version, such as v2.1.215+.
Add or set CLAUDE_CODE_ATTRIBUTION_HEADER to 0 in the system environment variables.
Windows 用户可通过系统属性 -> 高级 -> 环境变量 设置 # Linux/macOS 用户可在 ~/.bashrc, ~/.zshrc 或 /etc/environment 中添加:export CLAUDE_CODE_ATTRIBUTION_HEADER=0
Affected Versions
Section titled “Affected Versions”Source Issues
Section titled “Source Issues”This page is distilled from 1 real issues
- Why is caching still broken after setting it?
- Check whether your Claude Code version is too old, such as v2.1.148. Reports indicate older versions may have mutable-prefix compatibility issues. Update to v2.1.215 or later.
- Does this setting affect the official Anthropic API?
- No. It only disables the dynamic header used for billing and tracking and does not affect core functionality. If you use the official Anthropic API directly, this setting is usually unnecessary; it is useful with third-party proxies or local inference.
- How can I quickly toggle this setting in CC Switch?
- CC Switch does not currently provide a built-in toggle; Issue #2025 requests this feature. Set it manually in your operating system environment variables.
Related problems
Section titled “Related problems”This is an unofficial community wiki with no affiliation to the cc-switch authors or the project itself. Its content is compiled from the project's public GitHub issues. This site distributes no software.