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

API Error: 400 due to tool use concurrency issues. Run /rewind to recover the conversation. - [Bug] Anthropic API Error: Unexpected 400 Bad Request Response

Open ariccio opened this issue 1 year ago • 270 comments

Bug Description What? Why is this a 400 error?

Environment Info

  • Platform: darwin
  • Terminal: Apple_Terminal
  • Version: 2.0.2
  • Feedback ID: 21c957ff-1170-4fc2-9688-db8454c622bf

Errors

[{"error":"SyntaxError: Unexpected token '/', \"/Users/ale\"... is not valid JSON\n    at JSON.parse (<anonymous>)\n    at file:///Users/alexanderriccio/.nvm/versions/node/v20.19.4/lib/node_modules/@anthropic-ai/claude-code/cli.js:747:9932\n    at Q (file:///Users/alexanderriccio/.nvm/versions/node/v20.19.4/lib/node_modules/@anthropic-ai/claude-code/cli.js:713:13287)\n    at l_0.<anonymous> (file:///Users/alexanderriccio/.nvm/versions/node/v20.19.4/lib/node_modules/@anthropic-ai/claude-code/cli.js:3676:224)\n    at l_0.B [as _actionHandler] (file:///Users/alexanderriccio/.nvm/versions/node/v20.19.4/lib/node_modules/@anthropic-ai/claude-code/cli.js:703:528)\n    at file:///Users/alexanderriccio/.nvm/versions/node/v20.19.4/lib/node_modules/@anthropic-ai/claude-code/cli.js:707:3127\n    at l_0._chainOrCall (file:///Users/alexanderriccio/.nvm/versions/node/v20.19.4/lib/node_modules/@anthropic-ai/claude-code/cli.js:707:1694)\n    at l_0._parseCommand (file:///Users/alexanderriccio/.nvm/versions/node/v20.19.4/lib/node_modules/@anthropic-ai/claude-code/cli.js:707:3103)\n    at l_0.parseAsync (file:///Users/alexanderriccio/.nvm/versions/node/v20.19.4/lib/node_modules/@anthropic-ai/claude-code/cli.js:704:4195)\n    at ae5 (file:///Users/alexanderriccio/.nvm/versions/node/v20.19.4/lib/node_modules/@anthropic-ai/claude-code/cli.js:3705:1502)","timestamp":"2025-10-02T00:35:17.916Z"},{"error":"Error: Language not supported while highlighting code, falling back to markdown: \n    at FK (file:///Users/alexanderriccio/.nvm/versions/node/v20.19.4/lib/node_modules/@anthropic-ai/claude-code/cli.js:2337:1226)\n    at file:///Users/alexanderriccio/.nvm/versions/node/v20.19.4/lib/node_modules/@anthropic-ai/claude-code/cli.js:2337:954\n    at Array.map (<anonymous>)\n    at vX (file:///Users/alexanderriccio/.nvm/versions/node/v20.19.4/lib/node_modules/@anthropic-ai/claude-code/cli.js:2337:945)\n    at K2B (file:///Users/alexanderriccio/.nvm/versions/node/v20.19.4/lib/node_modules/@anthropic-ai/claude-code/cli.js:2337:19010)\n    at $C (file:///Users/alexanderriccio/.nvm/versions/node/v20.19.4/lib/node_modules/@anthropic-ai/claude-code/cli.js:34:19415)\n    at Xp (file:///Users/alexanderriccio/.nvm/versions/node/v20.19.4/lib/node_modules/@anthropic-ai/claude-code/cli.js:36:42814)\n    at W9 (file:///Users/alexanderriccio/.nvm/versions/node/v20.19.4/lib/node_modules/@anthropic-ai/claude-code/cli.js:36:38355)\n    at Dh (file:///Users/alexanderriccio/.nvm/versions/node/v20.19.4/lib/node_modules/@anthropic-ai/claude-code/cli.js:36:38283)\n    at jC (file:///Users/alexanderriccio/.nvm/versions/node/v20.19.4/lib/node_modules/@anthropic-ai/claude-code/cli.js:36:38137)","timestamp":"2025-10-02T02:41:39.345Z"},{"error":"SyntaxError: Unterminated string in JSON at position 1697\n    at JSON.parse (<anonymous>)\n    at file:///Users/alexanderriccio/.nvm/versions/node/v20.19.4/lib/node_modules/@anthropic-ai/claude-code/cli.js:747:9932\n    at Q (file:///Users/alexanderriccio/.nvm/versions/node/v20.19.4/lib/node_modules/@anthropic-ai/claude-code/cli.js:713:13287)\n    at file:///Users/alexanderriccio/.nvm/versions/node/v20.19.4/lib/node_modules/@anthropic-ai/claude-code/cli.js:3469:228\n    at Array.map (<anonymous>)\n    at xJ1 (file:///Users/alexanderriccio/.nvm/versions/node/v20.19.4/lib/node_modules/@anthropic-ai/claude-code/cli.js:3469:51)\n    at ETB (file:///Users/alexanderriccio/.nvm/versions/node/v20.19.4/lib/node_modules/@anthropic-ai/claude-code/cli.js:3309:17258)\n    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)\n    at async file:///Users/alexanderriccio/.nvm/versions/node/v20.19.4/lib/node_modules/@anthropic-ai/claude-code/cli.js:3309:12991\n    at async AT0 (file:///Users/alexanderriccio/.nvm/versions/node/v20.19.4/lib/node_modules/@anthropic-ai/claude-code/cli.js:3309:4232)","timestamp":"2025-10-02T02:42:19.217Z"},{"error":"Error: Error normalizing tool input: [\n  {\n    \"code\": \"invalid_type\",\n    \"expected\": \"string\",\n    \"received\": \"undefined\",\n    \"path\": [\n      \"file_path\"\n    ],\n    \"message\": \"Required\"\n  },\n  {\n    \"code\": \"invalid_type\",\n    \"expected\": \"string\",\n    \"received\": \"undefined\",\n    \"path\": [\n      \"content\"\n    ],\n    \"message\": \"Required\"\n  }\n]\n    at file:///Users/alexanderriccio/.nvm/versions/node/v20.19.4/lib/node_modules/@anthropic-ai/claude-code/cli.js:3469:353\n    at Array.map (<anonymous>)\n    at xJ1 (file:///Users/alexanderriccio/.nvm/versions/node/v20.19.4/lib/node_modules/@anthropic-ai/claude-code/cli.js:3469:51)\n    at ETB (file:///Users/alexanderriccio/.nvm/versions/node/

Note: Error logs were truncated.

ariccio avatar Oct 02 '25 15:10 ariccio

Same here

ManuelCostanzo avatar Oct 02 '25 15:10 ManuelCostanzo

Found 3 possible duplicate issues:

  1. https://github.com/anthropics/claude-code/issues/5934
  2. https://github.com/anthropics/claude-code/issues/8514
  3. https://github.com/anthropics/claude-code/issues/8108

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

github-actions[bot] avatar Oct 02 '25 15:10 github-actions[bot]

Same here

API Error: 400 {"type":"error","error":{"type":"invalid_request_error","message":"messages.212: tool_use ids were found without tool_result blocks immediately after: toolu_014B9d4M4gmHwdW7buS4mwYC, toolu_01KJoW8efgDsbqifcV7d2Y5Y. Each tool_use block must have a corresponding tool_result block in the next message."},"request_id":"req_011CTj1o5oPpwnhuFNJhV3vP"}

kurtjcu avatar Oct 02 '25 20:10 kurtjcu

This is a disaster and an emergency. It's preventing me from doing real work. Occuring in pretty much every session I'm running, sooner or later.

I have PostToolUse hooks active - I wonder if that's the culprit?

The PostToolUse output is being sent as USER MESSAGES back to CLAUDE as if I am sending new messages FOR EVERY NEW TOOL USE.

For me it often gets into a state of uninterruptable looping based on subsequent tool uses triggering "user messages" which simply contain PostToolUse hook outputs. Insanity.

UNACCEPTABLE.

Please somebody from the Claude Code team - reach out if you want help debugging this.

Collection of other similar bug reports: #8187 #8077 #8201 #8303 #8325 #8425 #8507 #8612 #8652 #8670 #8746 #8763 #8783 #8790 #8817 #8818 #8821 #8847 #8867 (my report) #8887 #8893 #8894 #8895 #8897 #8903

EDIT (Oct 14): Workaround for tool_use/tool_result 400 errors:

A research-backed solution was posted on Oct 10: https://github.com/anthropics/claude-code/issues/8763#issuecomment-3391509893

Add the provided instructions to your global CLAUDE.md (~/.claude/CLAUDE.md) to enforce sequential tool execution and prevent parallel tool calls that trigger the bug.

Technical approach:

Uses semantic overlap to override CC's default parallel execution behavior Explicit precedence declarations with concrete harm justification Based on LLM instruction conflict research (2024-2025) This prevents the majority of occurrences for users with PostToolUse hooks and complex workflows.

Note: Workaround while Anthropic completes fixes for remaining 2 root causes (1 of 3 mitigated per Oct 7 update).

I haven't had the problem once since I added this.

semikolon avatar Oct 04 '25 15:10 semikolon

Same here

I am getting the same errors.

API Error: 400 {"type":"error","error":{"type":"invalid_request_error","mess age":"messages.2: tool_use ids were found without tool_result blocks immediately after: toolu_01HQfMhsy6uSyiDpcL1GxVUX. Each tool_use block must have a corresponding tool_result block in the next message."},"request_id":"req_011CTqEKwWrc7w9RH6XKP7VJ"}

API Error: 400 due to tool use concurrency issues. Run /rewind to recover the conversation.

MayurKarmakar avatar Oct 06 '25 03:10 MayurKarmakar

it happened to me on code server vs code, stopped completly the production capacity that i have promised to my clients as i have it highly integrated in my workflow. Tried terminal and chat officla app and this is the erro rdisplayed API Error: 400 {"type":"error","error":{"type":"invalid_request_error","message":"messages.2: tool_use ids were found without tool_result blocks immediately after: toolu_016yfuWSRiqXgpHaEwDPZwgv, toolu_01LY8VuLCkzhY36jgWN9rsa8. Each tool_use block must have a corresponding tool_result block in the next message."},"request_id":"req_011CTqdf8FEQ2hmwmFRBqynw"}

BY-SAMBO avatar Oct 06 '25 08:10 BY-SAMBO

same issue

baldawsari avatar Oct 06 '25 14:10 baldawsari

same here .... I am far from any usage limits for the 5 hours window or the week :(

smoockpp avatar Oct 06 '25 18:10 smoockpp

Any news? Stopping me from working????

andreaskviby avatar Oct 06 '25 18:10 andreaskviby

uh... Version: 2.0.8 - same

azalio avatar Oct 06 '25 19:10 azalio

It seems that API level parallelism isnt working with Claude Code. Bug still here. Upvote so they solve

bengous avatar Oct 06 '25 20:10 bengous

This is most likely related to some big pdf files which are to heavy to read. Maybe for you it is another tool, however find out which is causing the error (whatever you added last) For me it helped to get rid of the big pdf files that are causing it to fail

iQuxLE avatar Oct 06 '25 22:10 iQuxLE

⎿  API Error: 400 due to tool use concurrency issues. Run /rewind to recover the conversation.

same issue trying to run two sessions on macos

roethlar avatar Oct 06 '25 22:10 roethlar

Same issue here. Only 1 session running. At 4% of my current session's usage, and 26% of my weekly. Using Sonnet in non-thinking mode. Not reading any big PDF or anything different to what I've been doing for the past week. Running v2.0.9

Edit: resolved itself approx 30 minutes later.

Further edit 2 days later: it keeps re-occurring. Rewind works, but all that happens is the CC starts re-doing the work it's already done and at some point I get the same error. Not always the same point, as far as I can tell (also, these are non-deterministic processes, so of course it's not the same point).

ap1969 avatar Oct 06 '25 23:10 ap1969

is that bug? i am still experience the issue

ghost avatar Oct 07 '25 01:10 ghost

I also suddenly started getting this error now. Not 4 days ago but now

Claude Code v2.0.9 Sonnet 4.5 · Claude Max

When I disabled my smart linter hook, the issue disappeared. But I didn't make any changes to my linter, so the issue shouldn't be in that hook.

tonisives avatar Oct 07 '25 01:10 tonisives

Ugh Claude Code..

richfergus avatar Oct 07 '25 04:10 richfergus

My issue resolved itself with no changes on my side.

ap1969 avatar Oct 07 '25 05:10 ap1969

My issue was just resolved, after updating Cursor.app, inside which I was running claude code as an extension

kolydart avatar Oct 07 '25 06:10 kolydart

I'm getting this too right now on Claude Code v2.0.9 Sonnet 4.5 · Claude Max

hyper-lode avatar Oct 07 '25 07:10 hyper-lode