/compact fails with 'thinking or redacted_thinking blocks cannot be modified' error when context is too long
Bug Report
Description
When a conversation reaches the context limit and the user runs /compact, compaction fails with the following error:
Error: Error during compaction: API Error: 400 messages.9.content.4: thinking or redacted_thinking blocks in the latest assistant message cannot be modified. These blocks must remain as they were in the original response.
This leaves the user completely stuck — the conversation is too long to continue, but /compact also fails, so there's no way to recover the session.
Steps to Reproduce
- Have a long conversation that reaches the context limit
- See the "Conversation is too long" error banner
- Run
/compact - Compaction fails with the error above
Expected Behavior
/compact should successfully summarize and compress the conversation history, allowing the session to continue.
Actual Behavior
Compaction fails because the last assistant message contains thinking or redacted_thinking blocks, which the API does not allow to be modified during compaction.
Impact
User is completely unable to recover the session — cannot compact, cannot continue, only option is to start a new chat and lose all context.
Suggested Fix
Before compaction, strip or handle thinking/redacted_thinking blocks from the latest assistant message so the API call doesn't fail.
Environment
- Claude Code CLI
- Reported by user via FleetView session
This issue has 2 comments on GitHub. Read the full discussion on GitHub ↗