Skip to content

Claude API error: thinking/redacted_thinking blocks modified in conversation history #18073

Closed

Description

@wonjun3991

Description

When using OpenCode with Claude models that have extended thinking enabled (e.g., claude-opus-4 via Amazon Bedrock), the API returns the following error after several conversation turns:

undefined: The model returned the following errors:
messages.3.content.7: `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 indicates that when OpenCode sends conversation history back to the Claude API, the thinking or redacted_thinking content blocks in assistant messages are being altered from their original form. The Claude API requires these blocks to be passed back byte-for-byte identical to how they were received.

Root Cause Hypothesis

Somewhere in the message serialization/deserialization pipeline (likely during session persistence, message compaction, or history truncation), the thinking blocks are being modified — possibly through:

  1. Message compaction/summarization stripping or truncating thinking blocks
  2. Database storage/retrieval altering the content (e.g., encoding changes, whitespace normalization)
  3. Content block filtering inadvertently modifying thinking blocks (note: v1.2.26 added "Filter empty content blocks for Bedrock provider" — similar pipeline)

Workaround

Starting a new session avoids the error since there are no prior thinking blocks in history.

Plugins

Custom skills/agents via .opencode/ config (not related to the issue — reproducible with default config)

OpenCode version

v1.2.20 (checked release notes through v1.2.27 — no related fix found)

Steps to reproduce

  1. Configure OpenCode with a Claude model that has extended thinking enabled (e.g., claude-opus-4 via Amazon Bedrock with thinking_mode: auto)
  2. Have a multi-turn conversation (3+ turns) where the model uses extended thinking
  3. The error occurs when the conversation history containing thinking blocks is sent back to the API

Note: This is intermittent — it depends on whether the model produces thinking blocks and how the history is managed across turns.

Screenshot and/or share link

Error message:

undefined: The model returned the following errors:
messages.3.content.7: `thinking` or `redacted_thinking` blocks in the latest assistant message
cannot be modified. These blocks must remain as they were in the original response.

Operating System

macOS (Apple Silicon)

Terminal

iTerm2 / Ghostty

Activity

  1. added
    coreAnything pertaining to core functionality of the application (opencode server stuff)
    on Mar 18, 2026
  2. github-actions commented on Mar 18, 2026

    @github-actions
    Contributor

    This issue might be a duplicate of existing issues. Please check:

    If your issue is the same as #13286, please add a reaction or comment there instead so the discussion stays focused.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

coreAnything pertaining to core functionality of the application (opencode server stuff)

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions