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 4 months 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

Found 3 possible duplicate issues:

  1. https://github.com/anthropics/claude-code/issues/12311
  2. https://github.com/anthropics/claude-code/issues/12783
  3. 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

github-actions[bot] avatar Dec 03 '25 13:12 github-actions[bot]

I've got the same issue.

tolmme avatar Dec 04 '25 20:12 tolmme

Closing as duplicate of #12311 (earliest compact-related thinking block issue with most activity). Please follow that issue for updates.

dicksontsai avatar Dec 09 '25 18:12 dicksontsai

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.

github-actions[bot] avatar Dec 17 '25 14:12 github-actions[bot]