claude-code icon indicating copy to clipboard operation
claude-code copied to clipboard

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

Open JuanCS-Dev opened this issue 3 weeks ago • 2 comments

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

JuanCS-Dev avatar Dec 03 '25 13:12 JuanCS-Dev