claude-code
claude-code copied to clipboard
Compaction fails with 400 error when thinking blocks present in assistant message
Bug Description
The /compact command fails with a 400 API error when the conversation contains thinking blocks in the latest assistant message.
Error Message
Error: Error during compaction: Error: API Error: 400
{
"type": "error",
"error": {
"type": "invalid_request_error",
"message": "messages.3.content.46: `thinking` or `redacted_thinking` blocks in the latest assistant message cannot be modified. These blocks must remain as they were in the original response."
},
"request_id": "req_011CVjqia3fJodhRgi9Y4Yc9"
}
Steps to Reproduce
- Start a Claude Code session with extended thinking enabled (e.g., using Opus model)
- Have a long conversation with multiple tool calls and thinking blocks
- Run
/compactcommand - Error occurs
Expected Behavior
The /compact command should successfully summarize the conversation, handling thinking blocks appropriately (either preserving them as-is or excluding them from the compaction process).
Environment
- Claude Code Version: Latest (as of 2025-12-03)
- Model: claude-opus-4-5-20251101
- OS: Linux (Ubuntu/Mint)
Suggested Fix
The compaction logic should either:
- Preserve thinking blocks unchanged during compaction
- Skip messages with thinking blocks when compacting
- Handle the API constraint before sending the compaction request
Additional Context
This prevents users from managing long conversations when using models with extended thinking enabled, which is a common workflow for complex coding tasks.
🤖 Generated with Claude Code