Skip to content

Auto-compact fails with Opus 4.5 extended thinking blocks #12311

Closed

Description

@ManuelMRosa

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

  1. Start a Claude Code session with Opus 4.5 model
  2. Have a long conversation that triggers auto-compaction
  3. When Claude Code attempts PreCompact:auto, the API returns error 400
  4. The error repeats on every subsequent message
  5. 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:

  1. It modifies or reorganizes messages containing thinking blocks
  2. The API rejects this because thinking blocks "cannot be modified" and "must remain as they were in the original response"
  3. Both streaming and non-streaming fallback fail with the same error
  4. 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:

  1. Preserve thinking blocks exactly as-is during compaction
  2. Handle the error gracefully and continue the session
  3. Warn users before using Opus 4.5 about this limitation

Suggested Fix

When compacting conversations with Opus 4.5:

  • Extract and preserve thinking/redacted_thinking blocks 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

Activity

  1. github-actions commented on Nov 25, 2025

    @github-actions

    Found 3 possible duplicate issues:

    1. [BUG] API Error 400 - Thinking Block Modification Error #10199
    2. [Bug] Anthropic API Error: Cannot modify thinking blocks in multi-turn conversation #12130
    3. [BUG] API Error 400: Thinking Block Modification Error (Not a Duplicate) #12225

    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

  2. art-shen commented on Nov 25, 2025

    @art-shen

    Breaks everything and neither manual nor automatic compaction works.

  3. TheDropZone commented on Nov 25, 2025

    @TheDropZone

    Definitely experiencing this as well with opus 4.5 and auto or manual compacts

  4. kyleorin commented on Nov 26, 2025

    @kyleorin

    same here on macos

  5. Noir-Lime commented on Nov 26, 2025

    @Noir-Lime

    Workaround is to /model set to Sonnet, then /compact, then set model back to opus.

  6. pentafive commented on Dec 8, 2025

    @pentafive

    Confirming on WSL2 (Linux 6.6.87.2-microsoft-standard-WSL2) with Claude Code 2.0.61 and Opus 4.5.

    My variant shows a slightly different error - the API complained about missing thinking block at message start rather than modification:

    messages.55.content.0.type: Expected 'thinking' or 'redacted_thinking', but found 'tool_use'
    

    Request ID: req_011CVtsi7huAUbEEm1GsSccY

    Triggered when context hit 4% remaining and /context command was run.

  7. 1 remaining item

  8. self-assigned this
    on Dec 9, 2025
  9. dicksontsai commented on Dec 12, 2025

    @dicksontsai
    Collaborator

    We've addressed this issue in 2.0.67. However, sessions created prior to 2.0.67 may still encounter this issue when resuming. We are working on a fix for the resume case.

  10. Nostromos commented on Dec 16, 2025

    @Nostromos

    @dicksontsai Reaching out to confirm that this issue remains post 2.0.67 (i'm on 2.0.71)

  11. nerdeveloper commented on Dec 17, 2025

    @nerdeveloper

    I am also experiencing this issue, using the latest version 2.0.70

  12. pentafive commented on Dec 17, 2025

    @pentafive

    @dicksontsai Reaching out to confirm that this issue remains post 2.0.67 (i'm on 2.0.71)

    I am also experiencing this issue, using the latest version 2.0.70

    Are they old sessions or new? I haven't been able to replicate it on 2.0.71 when it's a fresh session.

  13. dicksontsai commented on Dec 17, 2025

    @dicksontsai
    Collaborator

    If you are still encountering this issue, please file /feedback (the GitHub issue should have a feedback ID) when you encounter the session. This will help us out greatly, and it's how we've managed to reduce this particular "thinking blocks cannot be modified" error by 90+%. That said, I do still see a long tail of occurrences.

    Don't worry about de-duping issues. We'll handle that for you.

    @Nostromos @nerdeveloper

  14. github-actions commented on Dec 24, 2025

    @github-actions

    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.

  15. locked as resolved and limited conversation to collaborators on Dec 24, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions