claude-code icon indicating copy to clipboard operation
claude-code copied to clipboard

[BUG] /context fails on first try with thinking anabled, works on second try

Open howard1963 opened this issue 1 year ago • 8 comments

Preflight Checklist

  • [x] I have searched existing issues and this hasn't been reported yet
  • [x] This is a single bug report (please file separate reports for different bugs)
  • [x] I am using the latest version of Claude Code

What's Wrong?

Here is the error being returned: Error: 400 {"type":"error","error":{"type":"invalid_request_error","message":"messages.373.content.0.type: Expected thinking or redacted_thinking, but found text. 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_011CTgunMYhfTRB5CtNiStG4"}

I asked Claude Code (Sonnet 4.5 1M) about this and this is what is said:

This is not a connection error - it's a bug in how Claude Code handles the /context command with extended thinking enabled.

The Issue

The error message is very clear: messages.373.content.0.type: Expected thinking or redacted_thinking, but found text When thinking is enabled, a final assistant message must start with a thinking block

What's happening:

  1. You have extended thinking enabled in your Claude Code settings
  2. When you run /context, Claude Code sends a message to the API
  3. The API response structure requires that when thinking is enabled, the LAST assistant message must start with a block before any text or tool use
  4. Claude Code is incorrectly formatting the message - it's sending text first instead of thinking first
  5. The retry works because the second attempt might be structured differently in the conversation history

Solutions

Option 1: Disable extended thinking (quick fix)

In Claude Code settings, turn off extended thinking

Option 2: Report the bug (proper fix) This is a bug in Claude Code itself. You should report it at: https://github.com/anthropics/claude-code/issues

Option 3: Workaround (what you're already doing) Just retry the /context command when it fails - the second attempt usually works because the conversation state is slightly different.

Why It Works on Retry

On the first /context attempt, your last message was my response (text without thinking block). On the second attempt, there's now an error message in the history, which changes how Claude Code constructs the next API call, and it happens to format it correctly.

Bottom line: This is a Claude Code bug, not a you problem or a connection issue. The retry workaround is fine for now, but reporting it would help get it fixed properly.

What Should Happen?

when calling /context, Claude should handle the thinking state in such a way as not to throw an error when calling /context

Error Messages/Logs


Steps to Reproduce

  1. enable extended thinking in Claude settings
  2. Call /context using Sonnet 4.5

Claude Model

None

Is this a regression?

Yes, this worked in a previous version

Last Working Version

Sonnet 4.2

Claude Code Version

2.0.2 (Claude Code)

Platform

Anthropic API

Operating System

macOS

Terminal/Shell

Terminal.app (macOS)

Additional Information

No response

howard1963 avatar Oct 01 '25 18:10 howard1963

same error here.

first time:

/context ⎿ Error: 400 {"type":"error","error":{"type":"invalid_request_error","message":"messages.109.content.0.type: Expected thinking or redacted_thinking, but found text. 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_011CUtVPxfeUMqhHtFrYGsUS"}

2nd time: "request_id":"req_011CUtix6MfZSXhdhtac6uVp"}

Pento95 avatar Nov 07 '25 15:11 Pento95

Same here, happened multiple times now.

Image

ralpha avatar Nov 09 '25 22:11 ralpha

Mine was a duplicate of this issue if this helps: Session was running since yesterday. everything else looks the same from above. I did use ultrathink in the same session earlier but not sure if its related.

Environment Info Platform: darwin Terminal: ghostty Version: 2.0.36 Feedback ID: ea3e39f6-b62a-4c17-b97a-193a7ef2f91e

mid0 avatar Nov 11 '25 17:11 mid0

Same for me but on 2.0.53 Error: 400 {"type":"error","error":{"type":"invalid_request_error","message":"messages.101.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_011CVUPubkppCemPk65TAQMT"}

ColtonKinstley avatar Nov 25 '25 09:11 ColtonKinstley

Switch model, solution in comments https://github.com/anthropics/claude-code/issues/13669

abicorios avatar Dec 24 '25 20:12 abicorios

This issue has been inactive for 30 days. If the issue is still occurring, please comment to let us know. Otherwise, this issue will be automatically closed in 30 days for housekeeping purposes.

github-actions[bot] avatar Jan 25 '26 10:01 github-actions[bot]

Closing for now — inactive for too long. Please open a new issue if this is still relevant.

github-actions[bot] avatar Feb 14 '26 00:02 github-actions[bot]

This issue has been automatically locked since it was closed and has not had any activity for 7 days. If you're experiencing a similar issue, please file a new issue and reference this one if it's relevant.

github-actions[bot] avatar Feb 21 '26 14:02 github-actions[bot]