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
Found 3 possible duplicate issues:
- https://github.com/anthropics/claude-code/issues/12311
- https://github.com/anthropics/claude-code/issues/12783
- https://github.com/anthropics/claude-code/issues/12316
This issue will be automatically closed as a duplicate in 3 days.
- If your issue is a duplicate, please close it and 👍 the existing issue instead
- To prevent auto-closure, add a comment or 👎 this comment
🤖 Generated with Claude Code
I've got the same issue.
Closing as duplicate of #12311 (earliest compact-related thinking block issue with most activity). Please follow that issue for updates.
This issue has been automatically locked since it was closed and has not had any activity for 7 days. If you're experiencing a similar issue, please file a new issue and reference this one if it's relevant.