[BUG] API 400: thinking block ordering error during conversation with Task/Explore agent

Resolved 💬 5 comments Opened Jan 25, 2026 by rafaelperoco Closed Mar 1, 2026

Bug Description

During a normal conversation using the Task tool with the Explore subagent, the API returns a 400 error about thinking block ordering. This happens mid-conversation without any special action from the user.

Error Message

API Error: 400 {"type":"error","error":{"type":"invalid_request_error","message":"messages.1.content.0: If an assistant message contains any thinking blocks, the first block must be `thinking` or `redacted_thinking`. Found `text`."},"request_id":"req_011CXTJwUYeHpsCcHwWadsMw"}

A second occurrence in the same session:

API Error: 400 {"type":"error","error":{"type":"invalid_request_error","message":"messages.9.content.0: If an assistant message contains any thinking blocks, the first block must be `thinking` or `redacted_thinking`. Found `text`."},"request_id":"req_011CXTKJPMSMUvsVRHE7ZFYx"}

Steps to Reproduce

  1. Start a new Claude Code session with an extended thinking model (claude-opus-4-5-20251101)
  2. Ask Claude to explore/understand a project (triggering the Task tool with Explore subagent)
  3. Claude uses the Task tool with Explore subagent to analyze the codebase
  4. After the Explore agent completes, the next assistant response triggers the error
  5. The error occurs on subsequent messages in the same conversation as well

Expected Behavior

The conversation should continue normally after a Task/Explore agent completes its work.

Actual Behavior

The API returns a 400 error indicating that a text block appears before a thinking block in an assistant message. This suggests that during conversation context serialization (possibly after summarization or after processing tool results from subagents), the thinking blocks are being placed after text blocks instead of before them.

Environment

  • Platform: macOS (Darwin 25.2.0)
  • Model: claude-opus-4-5-20251101
  • Feature: Extended thinking enabled

Notes

  • The error persists across multiple messages in the same session (messages.1 and messages.9)
  • Starting a new session temporarily resolves the issue
  • This appears related to several open issues (#20705, #20692, #20691, #10199) but specifically involves the Task/Explore agent flow triggering the bug

View original on GitHub ↗

This issue has 5 comments on GitHub. Read the full discussion on GitHub ↗