claude-code
claude-code copied to clipboard
[Bug] /context command fails with: Anthropic API Error: Invalid message format with thinking blocks and tool use
Bug Description using "/context" leads to:
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.33.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.
Environment Info
- Platform: linux
- Terminal: vte-based
- Version: 2.0.65
- Feedback ID: f6302ca8-02b4-40a5-a830-5ad350cddde4
Errors
[{"error":"ZodError: [\n {\n \"code\": \"invalid_type\",\n \"expected\": \"object\",\n \"received\": \"undefined\",\n \"path\": [\n \"hooks\"\n ],\n \"message\": \"Required\"\n }\n]\n at get error (file:///home/ludwig/.nvm/versions/node/v22.20.0/lib/node_modules/@anthropic-ai/claude-code/cli.js:77:27070)\n at QJ.parse (file:///home/ludwig/.nvm/versions/node/v22.20.0/lib/node_modules/@anthropic-ai/claude-code/cli.js:77:20339)\n at zSB (file:///home/ludwig/.nvm/versions/node/v22.20.0/lib/node_modules/@anthropic-ai/claude-code/cli.js:1067:278)\n at wSB (file:///home/ludwig/.nvm/versions/node/v22.20.0/lib/node_modules/@anthropic-ai/claude-code/cli.js:1067:3214)\n at Ld3 (file:///home/ludwig/.nvm/versions/node/v22.20.0/lib/node_modules/@anthropic-ai/claude-code/cli.js:1067:7453)\n at async qd3 (file:///home/ludwig/.nvm/versions/node/v22.20.0/lib/node_modules/@anthropic-ai/claude-code/cli.js:1067:5709)\n at async file:///home/ludwig/.nvm/versions/node/v22.20.0/lib/node_modules/@anthropic-ai/claude-code/cli.js:1067:14558","timestamp":"2025-12-11T11:03:25.328Z"},{"error":"Error: 400 {\"type\":\"error\",\"error\":{\"type\":\"invalid_request_error\",\"message\":\"max_tokens: Extra inputs are not permitted\"},\"request_id\":\"req_011CVznfbLfrGrHZ13XvKY7c\"}\n at B9.generate (file:///home/ludwig/.nvm/versions/node/v22.20.0/lib/node_modules/@anthropic-ai/claude-code/cli.js:122:10379)\n at MR.makeStatusError (file:///home/ludwig/.nvm/versions/node/v22.20.0/lib/node_modules/@anthropic-ai/claude-code/cli.js:860:2195)\n at MR.makeRequest (file:///home/ludwig/.nvm/versions/node/v22.20.0/lib/node_modules/@anthropic-ai/claude-code/cli.js:860:5419)\n at process.processTicksAndRejections (node:internal/process/task_queues:105:5)\n at async file:///home/ludwig/.nvm/versions/node/v22.20.0/lib/node_modules/@anthropic-ai/claude-code/cli.js:1411:3503\n at async file:///home/ludwig/.nvm/versions/node/v22.20.0/lib/node_modules/@anthropic-ai/claude-code/cli.js:1411:2262\n at async oc3 (file:///home/ludwig/.nvm/versions/node/v22.20.0/lib/node_modules/@anthropic-ai/claude-code/cli.js:1410:354)\n at async mxB (file:///home/ludwig/.nvm/versions/node/v22.20.0/lib/node_modules/@anthropic-ai/claude-code/cli.js:1411:2195)\n at async xLA (file:///home/ludwig/.nvm/versions/node/v22.20.0/lib/node_modules/@anthropic-ai/claude-code/cli.js:2082:52)\n at async kV8 (file:///home/ludwig/.nvm/versions/node/v22.20.0/lib/node_modules/@anthropic-ai/claude-code/cli.js:2082:2358)","timestamp":"2025-12-11T11:03:31.619Z"}]
Found 3 possible duplicate issues:
- https://github.com/anthropics/claude-code/issues/13401
- https://github.com/anthropics/claude-code/issues/13648
- https://github.com/anthropics/claude-code/issues/12311
This issue will be automatically closed as a duplicate in 3 days.
- If your issue is a duplicate, please close it and 👍 the existing issue instead
- To prevent auto-closure, add a comment or 👎 this comment
🤖 Generated with Claude Code
Confirming this issue on WSL2 (Linux 6.6.87.2-microsoft-standard-WSL2).
My error:
Error: 400 {"type":"error","error":{"type":"invalid_request_error","message":"messages.43.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_011CW1Vb8UZNYZUPz7xTQF1w"}
- Triggered by
/contextcommand - Session had ~105k tokens with multiple tool_use interactions
- Claude Code version: latest
- Model: Opus 4.5