Skip to content

Does OpenCode send back all previous reasoning blocks to Claude (or any provider)? #8185

Closed

Description

@skerit

Question

So I was under the impression that thinking blocks were ephemeral. That older thinking blocks are not used to generate a new response.

But I don't see any sort of "pruning" happening in the OpenCode code, so it seems as if the entire conversation with all the reasoning blocks gets sent back all the time?

Here's where the conversation gets made, right?

const result = await processor.process({
user: lastUser,
agent,
abort,
sessionID,
system: [...(await SystemPrompt.environment()), ...(await SystemPrompt.custom())],
messages: [
...MessageV2.toModelMessage(sessionMessages),
...(isLastStep
? [
{
role: "assistant" as const,
content: MAX_STEPS,
},
]
: []),
],
tools,
model,
})

And here is the explicit line in MessageV2.toModelMessage that includes reasoning blocks:

if (part.type === "reasoning") {
assistantMessage.parts.push({
type: "reasoning",
text: part.text,
providerMetadata: part.metadata,
})
}
}

Is this how it is supposed to work?

Or do providers like Anthropic filter these out on their end?

Activity

  1. github-actions commented on Jan 13, 2026

    @github-actions
    Contributor

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

    Feel free to ignore if none of these address your specific case.

  2. skerit commented on Jan 13, 2026

    @skerit
    Author

    I don't think those existing issues match this question.
    Issue #5577 is most interesting here, it seems as if it would be most logical to filter out thinking blocks in this file:

    function normalizeMessages(msgs: ModelMessage[], model: Provider.Model): ModelMessage[] {

    But as far as I understand it, it does not.

  3. skerit commented on Jan 16, 2026

    @skerit
    Author

    To be clear: I'm not asking if its wrong or forbidden to keep all previous thinking blocks in the conversation all the time, I'm asking if this is optimal use of the context.

    Anthropic's documentation says:

    • That thinking blocks are ephemeral
    • The AI SDK provides pruneMessages({ reasoning: 'before-last-message' }) specifically for this
  4. skerit commented on Jan 16, 2026

    @skerit
    Author

    Alright, so I dove a bit deeper into the extended-thinking docs:
    https://platform.claude.com/docs/en/build-with-claude/extended-thinking

    I found some important notes here:

    "Preserving thinking blocks"

    "While you can omit thinking blocks from prior assistant role turns, we suggest always passing back all thinking blocks to the API for any multi-turn conversation. The API will:

    • Automatically filter the provided thinking blocks
    • Use the relevant thinking blocks necessary to preserve the model's reasoning
    • Only bill for the input tokens for the blocks shown to Claude"

    "Understanding thinking block caching behavior"

    "When a non-tool-result user block is included, all previous thinking blocks are ignored and stripped from context"

    "Thinking block context removal"

    • Thinking blocks from previous turns are removed from context, which can affect cache breakpoints
    • When continuing conversations with tool use, thinking blocks are cached and count as input tokens when read from cache
    • This creates a tradeoff: while thinking blocks don't consume context window space visually, they still count toward your input token usage when cached
    • If thinking becomes disabled, requests will fail if you pass thinking content in the current tool use turn. In other contexts, thinking content passed to the API is simply ignored

    Model difference:

    "For Claude Opus 4.5 and later, all previous thinking blocks are kept by default. For older models, because a non-tool-result user block was included, all previous thinking blocks are ignored."

    So I guess this is official Anthropic documentation confirming:

    1. You can omit old thinking blocks (but they recommend sending them)
    2. The API automatically strips old thinking blocks, but only for pre-4.5 models?
    3. Claude Opus 4.5+ keeps thinking blocks by default
  5. github-actions commented on Mar 26, 2026

    @github-actions
    Contributor

    To stay organized issues are automatically closed after 90 days of no activity. If the issue is still relevant please open a new one.

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

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions