Compaction fails with 400 error when thinking blocks present in assistant message

Resolved 💬 4 comments Opened Dec 3, 2025 by JuanCS-Dev Closed Dec 9, 2025

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

  1. Start a Claude Code session with extended thinking enabled (e.g., using Opus model)
  2. Have a long conversation with multiple tool calls and thinking blocks
  3. Run /compact command
  4. 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:

  1. Preserve thinking blocks unchanged during compaction
  2. Skip messages with thinking blocks when compacting
  3. 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

View original on GitHub ↗

This issue has 4 comments on GitHub. Read the full discussion on GitHub ↗