Auto-compact fails with Opus 4.5 extended thinking blocks
Bug Report: Auto-compact fails with Opus 4.5 extended thinking blocks
Description
When using Claude Code with the claude-opus-4-5-20251101 model, the automatic conversation compaction feature fails repeatedly with a 400 error. This causes the session to become unusable and all context is lost.
Environment
- Claude Code version: Latest (npm global install)
- Model: claude-opus-4-5-20251101
- OS: Windows 10/11
- Date: 2025-11-24
Error Message
400 {"type":"error","error":{"type":"invalid_request_error","message":"messages.11.content.11: `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_011CVTZiv4zz4a4AmyidNwVx"}
Steps to Reproduce
- Start a Claude Code session with Opus 4.5 model
- Have a long conversation that triggers auto-compaction
- When Claude Code attempts
PreCompact:auto, the API returns error 400 - The error repeats on every subsequent message
- Session becomes unusable
Debug Log Evidence
From the debug log (~/.claude/debug/*.txt):
2025-11-24T23:15:23.678Z [DEBUG] Skipping PreCompact:auto hook execution - workspace trust not accepted
2025-11-24T23:15:24.181Z [ERROR] Error streaming, falling back to non-streaming mode: 400 {"type":"error"...
2025-11-24T23:15:24.604Z [ERROR] Error in non-streaming fallback: 400 {"type":"error"...
Total failed compact attempts in session: 77
Root Cause Analysis
The Opus 4.5 model uses "extended thinking" which generates <thinking> blocks in responses. When Claude Code attempts to compact/summarize the conversation:
- It modifies or reorganizes messages containing thinking blocks
- The API rejects this because thinking blocks "cannot be modified" and "must remain as they were in the original response"
- Both streaming and non-streaming fallback fail with the same error
- The compaction never succeeds, making the session unrecoverable
Impact
- Severity: High
- Data Loss: Complete loss of conversation context
- User Experience: Session becomes completely unusable
- Workaround: Switch to Sonnet model (no extended thinking)
Expected Behavior
Claude Code should either:
- Preserve thinking blocks exactly as-is during compaction
- Handle the error gracefully and continue the session
- Warn users before using Opus 4.5 about this limitation
Suggested Fix
When compacting conversations with Opus 4.5:
- Extract and preserve
thinking/redacted_thinkingblocks unchanged - Only summarize the non-thinking content
- Or skip compaction for messages containing thinking blocks
Additional Context
The user was working on AutoCAD LISP development when this occurred. The session had grown large enough to trigger auto-compaction, at which point it entered an error loop and became unusable.
---
Reported via Claude Code session analysis
This issue has 12 comments on GitHub. Read the full discussion on GitHub ↗