Context loading breaks with extended thinking enabled - missing thinking blocks
Description
When using the /context command to load conversation context from a previous session, Claude Code throws a 400 error from the API when extended thinking is enabled.
Error Message
This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). The promise rejected with the reason:
Error: 400 {"type":"error","error":{"type":"invalid_request_error","message":"messages.125.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). We recommend you include thinking blocks from previous turns. To avoid this requirement, disable `thinking`. Please consult our documentation at https://docs.claude.com/en/docs/build-with-claude/extended-thinking"},"request_id":"req_011CWEvgFQsdoi91vm1oc6ZK"}
at generate (/$bunfs/root/claude:414:11098)
at makeRequest (/$bunfs/root/claude:761:5435)
at processTicksAndRejections (native:7:39)
Root Cause
When extended thinking is enabled, the Claude API requires that assistant messages start with a thinking or redacted_thinking block before any tool_use blocks. The /context command appears to be stripping or not preserving these thinking blocks when serializing/deserializing conversation context, which causes the API to reject the request.
Steps to Reproduce
- Start a Claude Code session with extended thinking enabled (e.g., using Opus model)
- Have a conversation that includes tool use
- Use
/contextto export the context - In a new Claude Code instance, load that context
- Continue the conversation - API returns 400 error
Expected Behavior
The /context command should preserve thinking and redacted_thinking blocks in the conversation history so that loaded contexts remain valid for the API when thinking mode is enabled.
Suggested Fix
When serializing conversation context, ensure thinking blocks are preserved (or properly redacted as redacted_thinking blocks if the actual thinking content shouldn't be stored). When deserializing, these blocks need to be restored in the correct positions before tool_use blocks.
---
🤖 Generated with Claude Code
This issue has 3 comments on GitHub. Read the full discussion on GitHub ↗