anomalyco / anomalyco/opencode
Reasoning from OpenAI-compatible providers that inline <think> tags leaks into text content
@neriousy is already working on this.
Since Aug 21, 2026.
- Dominant language
- TypeScript
- Stars
- 209k
- Forks
- 27.5k
- PR merge metrics
- PR metrics pending
Description
Summary
For OpenAI-compatible providers whose models emit reasoning inline in content wrapped in <think>...</think> tags, opencode stores the raw tagged text verbatim as a text part. The UI then renders the model's chain-of-thought as regular assistant output instead of a collapsible thinking block.
Environment
- opencode 1.18.19
- Provider: custom OpenAI-compatible (
poolside, endpointhttps://inference.poolside.ai/v1) - Model:
poolside/laguna-s-2.1 - Model definition declares interleaved reasoning via
interleaved: { field: "reasoning_content" }
Observed behavior
- Many requests correctly populate the separate reasoning channel and are displayed as thinking.
- Intermittently, a response arrives with the entire reasoning trace inline in
content:
<long reasoning monologue ...></think><final answer>
opencode saves this whole string as one text part. The affected message reports reasoning: 0 tokens at message level, while the session total still shows accumulated reasoning tokens — so token accounting is also distorted (reasoning counted as output).
Expected behavior
Inline <think> blocks should be extracted into separate reasoning parts so they render as thinking, not as body text.
Suggested fix
Wrap affected provider/model instances with the AI SDK's extraction middleware, e.g.:
import { wrapLanguageModel, extractReasoningMiddleware } from 'ai'
const model = wrapLanguageModel({
model: openaiCompatibleModel,
middleware: extractReasoningMiddleware({ tagName: 'think' }),
})
Options:
- Apply
extractReasoningMiddlewareautomatically for providers/models known to inline think tags (similar to how DeepSeek R1 is handled). - Expose a per-model config flag (e.g.
reasoning.extract: "think-tags") in the model/provider schema so users can enable it for any OpenAI-compatible endpoint. - A safe fallback could also apply
startWithReasoning: truesemantics for models that omit the opening tag.
Impact
- Users cannot review the agent's reasoning process (it appears as unreadable body text mixed with output).
- Reasoning/output token attribution is wrong on affected messages.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Assessment
This issue has not been assessed yet.