[BUG] /compact fails with 400 error when last assistant turn contains thinking blocks

Resolved 💬 1 comment Opened May 28, 2026 by mrfrostycakes Closed Jun 30, 2026

Preflight Checklist

  • [x] I have searched existing issues and this hasn't been reported yet
  • [x] This is a single bug report (please file separate reports for different bugs)
  • [x] I am using the latest version of Claude Code

What's Wrong?

When a conversation grows long enough to trigger compaction (either via /compact or auto-compact), the operation fails with a 400 API error if the most recent assistant message contains thinking or redacted_thinking blocks. The conversation is then stuck — too long to continue, but impossible to compact.

Actual behavior

Compaction fails completely. The session is stuck — the conversation is too long to continue and /compact cannot recover it. The only escape is /clear (losing all context) or starting a new conversation.

Workaround

Run /compact manually early, while the conversation still has room, before auto-compact triggers at the edge. Starting a new conversation and pasting in context also works.

Environment

Claude Code version: (check claude --version)
Model: any model with extended thinking enabled
Platform: (your OS)

What Should Happen?

Expected behavior

/compact should handle conversations that end with thinking blocks. It should either:

Exclude the last assistant turn's thinking blocks from the summary payload (keeping only the text blocks for context), or
Omit the last assistant message from the replay entirely and let the summary stand alone

Error Messages/Logs

API Error: 400 messages.181.content.1: thinking or redacted_thinking blocks
in the latest assistant message cannot be modified. These blocks must remain
as they were in the original response.

Error: Error during compaction: API Error: 400 messages.181.content.1:
thinking or redacted_thinking blocks in the latest assistant message cannot
be modified. These blocks must remain as they were in the original response.

Steps to Reproduce

To reproduce

Use a model with extended thinking enabled (e.g. Opus fast mode)
Have a long multi-turn conversation until it approaches the context limit
Run /compact (or wait for auto-compact to trigger)
Observe the 400 error — compaction fails and the session is unrecoverable

Claude Model

Opus

Is this a regression?

I don't know

Last Working Version

_No response_

Claude Code Version

opus 4.7 1m

Platform

Anthropic API

Operating System

Windows

Terminal/Shell

Other

Additional Information

using claude for vscode extension access in cursor

View original on GitHub ↗

This issue has 1 comment on GitHub. Read the full discussion on GitHub ↗