Bedrock: x-anthropic-billing-header and system prompt injected into user message body when context is large
Summary
When using Claude Code with Amazon Bedrock (CLAUDE_CODE_USE_BEDROCK=1), once the total context (system prompt + conversation history) exceeds a certain size threshold, the x-anthropic-billing-header and the entire system prompt are injected into the user message body. The model receives its own system prompt as if the user typed it, responds with something like "it looks like you sent a copy of the system prompt", and refuses to engage normally.
Behaviour
The model's thinking (visible via ctrl+o) confirms what it receives:
"The message starts with x-anthropic-billing-header: cc_version=2.1.224.744; cc_entrypoint=cli; and then repeats the entire system prompt."
This happens in two scenarios:
- At session startup — if the system prompt alone is large enough (project CLAUDE.md + memory files), the very first user message triggers it
- Mid-session — even with a smaller system prompt, as conversation history grows, the combined context eventually hits the threshold and the bug begins occurring for subsequent messages
Steps to reproduce
- Use Claude Code with
CLAUDE_CODE_USE_BEDROCK=1in~/.claude/settings.json - Work in a project with a large system prompt (large
CLAUDE.md+ populated~/.claude/projects/<path>/memory/files), or run a long session until context grows - Send any message
- Observe the model responding as if the user sent the system prompt as a message
Expected behaviour
When the total context exceeds Bedrock's limit, Claude Code should truncate or summarise the conversation history to bring it back under the limit — the same way it handles context compression in normal operation. The system prompt and billing headers should never appear in the user message body under any circumstances.
Environment
- Claude Code version: 2.1.224
- Model:
anthropic.claude-sonnet-4-6via Amazon Bedrock - Region:
eu-west-2
Impact
Sessions become unusable. /clear resets conversation history and temporarily restores normal behaviour, but the bug recurs as context grows again.
Workaround
/clear to reset conversation history. Reducing memory files and CLAUDE.md reduces how quickly the threshold is reached.
Notes
Removing ANTHROPIC_CUSTOM_HEADERS: X-Amzn-Bedrock-Trace: ENABLED does not fix the issue. The root cause appears to be that the Bedrock integration overflows excess context into the user message body rather than truncating gracefully.