-
Notifications
You must be signed in to change notification settings - Fork 3.6k
Description
Description
When using Claude models with extended thinking (e.g., claude-opus-4-5-thinking, claude-4-5-sonnet with thinking enabled) via custom providers (like oh-my-opencode's Antigravity), multi-turn conversations with tool use fail with:
messages.X.content.0.type: Expected `thinking` or `redacted_thinking`, but found `tool_use`.
When `thinking` is enabled, a final `assistant` message must start with a thinking block
(preceeding the lastmost set of `tool_use` and `tool_result` blocks).
Root Cause
Claude's API requires:
- When
thinkingis enabled, every assistant message must start with athinkingblock - Thinking blocks in message history MUST include the
signaturefield (returned by Claude in original response)
The signature appears to not be preserved when storing assistant messages in OpenCode's message history. When the message is sent back in subsequent requests, the thinking block is either:
- Missing entirely, OR
- Missing the required
signaturefield
Related Issues
- [bug] v0.8.0 Introduced thinking block bug with Claude Sonnet 4: "AI_APICallError: messages.3.content.0.type: Expected
thinkingorredacted_thinking, but foundtext." #2599 - Original thinking block bug (closed but issue persists) - Expected
thinkingorredacted_thinking, but foundtool_use#3077 - Same error message - [Bug] Anthropic API Error: Assistant message must start with thinking block when thinking is enabled anthropics/claude-code#11432 - Same error in Claude Code
Expected Behavior
When Claude returns:
{
"content": [
{ "type": "thinking", "thinking": "...", "signature": "abc123..." },
{ "type": "tool_use", "id": "...", "name": "bash", "input": {...} }
]
}The signature field should be preserved in message history so it can be sent back in subsequent requests.
Workaround
For oh-my-opencode users, I've submitted a PR that strips unsigned thinking blocks from history to prevent the API error: code-yeongyu/oh-my-opencode#253
This is a workaround, not a fix - the proper fix is to preserve signatures in OpenCode's message storage.
Environment
- OpenCode version: 1.0.x (latest)
- Provider: Custom (oh-my-opencode Antigravity)
- Model: claude-opus-4-5-thinking, claude-4-5-sonnet with thinking
- OS: Linux