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

Bug Report API Error: 400 `tool_use` ids were found without `tool_result` blocks immediately after...

Open GratefulDave opened this issue 6 months ago • 4 comments

Bug Description This happens randomly and persists forcing me to restart new Claude Code instance.

Refactor S3_manager according to best practices and @docs/refactoring.md ⎿  Read docs/refactoring.md (1605 lines) ⎿  API Error: 400 {"type":"error","error":{"type":"invalid_request_error","message":"messages.5: tool_use ids were found without tool_result blocks immediately after: toolu_01FRvEykWmCgrgJ22mvBbKhV. Each tool_use block must have a corresponding tool_result block in the next message."}}

continue ⎿  API Error: 400 {"type":"error","error":{"type":"invalid_request_error","message":"messages.5: tool_use ids were found without tool_result blocks immediately after: toolu_01FRvEykWmCgrgJ22mvBbKhV. Each tool_use block must have a corresponding tool_result block in the next message."}}

UPDATE documentation ⎿  API Error: 400 {"type":"error","error":{"type":"invalid_request_error","message":"messages.5: tool_use ids were found without tool_result blocks immediately after: toolu_01FRvEykWmCgrgJ22mvBbKhV. Each tool_use block must have a corresponding tool_result block in the next message."}}

Environment Info

  • Platform: macos
  • Terminal: pycharm
  • Version: 1.0.17
  • Feedback ID: 39ad9130-c5ee-477f-bac9-ece2e0554c1e

Errors

[{"error":"AbortError: The operation was aborted\n    at abortChildProcess (node:child_process:716:27)\n    at onAbortListener (node:child_process:786:7)\n    at process.processTicksAndRejections (node:internal/process/task_queues:85:11)","timestamp":"2025-06-10T07:36:15.666Z"},{"error":"MCPContentTooLargeError: MCP tool \"read_file\" response (30206 tokens) exceeds maximum allowed tokens (25000). Please use pagination, filtering, or limit parameters to reduce the response size.\n    at is1 (file:///Users/davidandrews/.nvm/versions/node/v23.10.0/lib/node_modules/@anthropic-ai/claude-code/cli.js:1376:7798)\n    at process.processTicksAndRejections (node:internal/process/task_queues:105:5)\n    at async vX2 (file:///Users/davidandrews/.nvm/versions/node/v23.10.0/lib/node_modules/@anthropic-ai/claude-code/cli.js:1376:12473)\n    at async Object.call (file:///Users/davidandrews/.nvm/versions/node/v23.10.0/lib/node_modules/@anthropic-ai/claude-code/cli.js:1376:8729)\n    at async iZ5 (file:///Users/davidandrews/.nvm/versions/node/v23.10.0/lib/node_modules/@anthropic-ai/claude-code/cli.js:1896:19166)\n    at async WK1 (file:///Users/davidandrews/.nvm/versions/node/v23.10.0/lib/node_modules/@anthropic-ai/claude-code/cli.js:1896:17752)\n    at async cZ5 (file:///Users/davidandrews/.nvm/versions/node/v23.10.0/lib/node_modules/@anthropic-ai/claude-code/cli.js:1896:16794)\n    at async uZ5 (file:///Users/davidandrews/.nvm/versions/node/v23.10.0/lib/node_modules/@anthropic-ai/claude-code/cli.js:1896:16423)\n    at async NO (file:///Users/davidandrews/.nvm/versions/node/v23.10.0/lib/node_modules/@anthropic-ai/claude-code/cli.js:1896:15452)\n    at async NO (file:///Users/davidandrews/.nvm/versions/node/v23.10.0/lib/node_modules/@anthropic-ai/claude-code/cli.js:1896:16278)","timestamp":"2025-06-10T07:40:15.927Z"},{"error":"MCPContentTooLargeError: MCP tool \"read_multiple_files\" response (26545 tokens) exceeds maximum allowed tokens (25000). Please use pagination, filtering, or limit parameters to reduce the response size.\n    at is1 (file:///Users/davidandrews/.nvm/versions/node/v23.10.0/lib/node_modules/@anthropic-ai/claude-code/cli.js:1376:7798)\n    at process.processTicksAndRejections (node:internal/process/task_queues:105:5)\n    at async vX2 (file:///Users/davidandrews/.nvm/versions/node/v23.10.0/lib/node_modules/@anthropic-ai/claude-code/cli.js:1376:12473)\n    at async Object.call (file:///Users/davidandrews/.nvm/versions/node/v23.10.0/lib/node_modules/@anthropic-ai/claude-code/cli.js:1376:8729)\n    at async iZ5 (file:///Users/davidandrews/.nvm/versions/node/v23.10.0/lib/node_modules/@anthropic-ai/claude-code/cli.js:1896:19166)\n    at async WK1 (file:///Users/davidandrews/.nvm/versions/node/v23.10.0/lib/node_modules/@anthropic-ai/claude-code/cli.js:1896:17752)\n    at async cZ5 (file:///Users/davidandrews/.nvm/versions/node/v23.10.0/lib/node_modules/@anthropic-ai/claude-code/cli.js:1896:16794)\n    at async uZ5 (file:///Users/davidandrews/.nvm/versions/node/v23.10.0/lib/node_modules/@anthropic-ai/claude-code/cli.js:1896:16423)\n    at async NO (file:///Users/davidandrews/.nvm/versions/node/v23.10.0/lib/node_modules/@anthropic-ai/claude-code/cli.js:1896:15452)\n    at async NO (file:///Users/davidandrews/.nvm/versions/node/v23.10.0/lib/node_modules/@anthropic-ai/claude-code/cli.js:1896:16278)","timestamp":"2025-06-10T07:55:01.437Z"},{"error":"MCPContentTooLargeError: MCP tool \"read_file\" response (28285 tokens) exceeds maximum allowed tokens (25000). Please use pagination, filtering, or limit parameters to reduce the response size.\n    at is1 (file:///Users/davidandrews/.nvm/versions/node/v23.10.0/lib/node_modules/@anthropic-ai/claude-code/cli.js:1376:7798)\n    at process.processTicksAndRejections (node:internal/process/task_queues:105:5)\n    at async vX2 (file:///Users/davidandrews/.nvm/versions/node/v23.10.0/lib/node_modules/@anthropic-ai/claude-code/cli.js:1376:12473)\n    at async Object.call (file:///Users/davidandrews/.nvm/versions/node/v23.10.0/lib/node_modules/@anthropic-ai/claude-code/cli.js:1376:8729)\n    at async iZ5 (file:///Users/davidandrews/.nvm/versions/node/v23.10.0/lib/node_modules/@anthropic-ai/claude-code/cli.js:1896:19166)\n    at async WK1 (file:///Users/davidandrews/.nvm/versions/node/v23.10.0/lib/node_modules/@anthropic-ai/claude-code/cli.js:1896:17752)\n    at async cZ5 (file:///Users/davidandrews/.nvm/versions/node/v23.10.0/lib/node_modules/@anthropic-ai/claude-code/cli.js:1896:16794)\n    at async uZ5 (file:///Users/davidandrews/.nvm/versions/node/v23.10.0/lib/node_modules/@anthropic-ai/claude-code/cli.js:1896:16423)\n    at async NO (file:///Users/davidandrews/.nvm/versions/node/v23.10.0/lib/node_modules/@anthropic-ai/claude-code/cli.js:1896:15452)\n    at async NO (file:///Users/davidandrews/.nvm/versions/node/v23.10.0/lib/node_modules/@anthropic-ai/claude-code/cli.js:1896:16278)","timestamp":"2025-06-10T07:56:05.926Z"},{"error":"Error: Language not supported while highlighting code, falling back

Note: Error logs were truncated.

GratefulDave avatar Jun 10 '25 15:06 GratefulDave

I also got this today, never had it before.

● Bash(just bump-patch)
  ⎿  Error: sh: line 1: jq: command not found
     error: Recipe `get-version` failed on line 55 with exit code 127
     error: Recipe `bump-patch` failed with exit code 127

● Let me fix the get-version command to not rely on jq:
  ⎿  Interrupted by user
  ⎿  Interrupted by user
  ⎿  Interrupted by user

> actually if we need jq then add it to our nix flake
  ⎿  API Error: 400 {"type":"error","error":{"type":"invalid_request_error","message":"messages.19: `tool_use` ids were found without `tool_result` blocks immediately after: toolu_0162edssqab1kYwpztdNfXru. Each `tool_use` block must have a 
     corresponding `tool_result` block in the next message."}}

> actually if we need jq then add it to our nix flake
  ⎿  API Error: 400 {"type":"error","error":{"type":"invalid_request_error","message":"messages.19: `tool_use` ids were found without `tool_result` blocks immediately after: toolu_0162edssqab1kYwpztdNfXru. Each `tool_use` block must have a 
     corresponding `tool_result` block in the next message."}}

AnthonyRonning avatar Jun 10 '25 16:06 AnthonyRonning

same here just after I Interrupted it.

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

ahmedibrahim085 avatar Jun 10 '25 20:06 ahmedibrahim085

Same. Has anyone found a way to recover from it other than restarting Claude Code?

jri-klaay avatar Jun 10 '25 23:06 jri-klaay

I get this from time to time as well. You can hit double escape and go to the previous prompt (eliminating some context) and start there again.

galenward avatar Jun 11 '25 01:06 galenward

We've resolve the root cause for this issue in 1.0.21 (claude update and claude --version). To recover a stuck session hit "esc" twice and rewind back to before the error.

igorkofman avatar Jun 11 '25 22:06 igorkofman

Hello, I'm using version 1.0.24 but same error happened.

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

kalaomer avatar Jun 16 '25 20:06 kalaomer

same here Claude Code Status v1.0.25 Error: Error during compaction: Error: API Error: 400 {"type":"error","error":{"type":"invalid_request_error","message":"messages.27: tool_use ids were found without tool_result blocks immediately after: toolu_01GCg6SKLPsVVW15sNuJ6jwa. Each tool_use block must have a corresponding tool_result block in the next message."}}

khalidDaoud avatar Jun 17 '25 15:06 khalidDaoud

Getting this error with Claude Code v1.0.25 too: API Error: 400 {"type":"error","error":{"type":"invalid_request_error","message":"messages.223: tool_use ids were found without tool_result blocks immediately after: toolu_011zra4NRpA4xYVjvA4dof9t, toolu_012hVvD4ueHGNKsqDVMzZcMn, toolu_013N1NakAhCnQfVHqdb9d2qn, toolu_014iJS1MNuMPJx76oUTxbfWW, toolu_01AnA7aMdVE4zHxNpGKdKkkm, toolu_01BCxWTT6ZjfgrK4kLZH3j7k, toolu_01C8R3r9LfjHrnmeg9mnytGx, toolu_01KrY5mzWPFJQq6V4Xeo7FR2, toolu_01P3Ssb9FFnoPmfstk2TnV9X, toolu_01TgLj2ktFpkR43rfoEh11Vv, toolu_01X38MMqvXBuJkroJmjmv6na, toolu_01XxH41RgMndShaFJnyPoW4p. Each tool_use block must have a corresponding tool_result block in the next message."}}

zachberk avatar Jun 17 '25 16:06 zachberk

Just got the "tool_use block must have a corresponding tool_result block in the next message" error on 1.0.29.

ESRogs avatar Jun 19 '25 05:06 ESRogs

What account type are you using? Does quitting and claude --resume ing the conversation restore it? Do new conversations work? What was happening when the error occurred?

On Wed, Jun 18, 2025 at 10:13 PM Eric S. Rogstad @.***> wrote:

ESRogs left a comment (anthropics/claude-code#1894) https://github.com/anthropics/claude-code/issues/1894#issuecomment-2986632912

Just got the "tool_use block must have a corresponding tool_result block in the next message" error on 1.0.29.

— Reply to this email directly, view it on GitHub https://github.com/anthropics/claude-code/issues/1894#issuecomment-2986632912, or unsubscribe https://github.com/notifications/unsubscribe-auth/AADSWQX3LEUA7MHF6OMFEYL3EJBGLAVCNFSM6AAAAAB677MV3OVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDSOBWGYZTEOJRGI . You are receiving this because you modified the open/close state.Message ID: @.***>

igorkofman avatar Jun 19 '25 05:06 igorkofman

What account type are you using? Does quitting and claude --resume ing the conversation restore it? Do new conversations work? What was happening when the error occurred?

i just got the same problem. max($100) account. --resume doesn't work but new conversations are fine.

I was using it just fine. Then I copy pasted a console output to ask something about it and now that conversation is bugged. 2x esc doesn't work. /compact doesn't work. Tried logout + login but its still broken.

Rasit-Vatan avatar Jun 23 '25 12:06 Rasit-Vatan

Session File Investigation Report

I investigated session files that couldn't be resumed and found evidence directly related to this issue.

Findings

Tool Use/Result Mismatch:

Session file: 482cb242-01c9-4149-8c8a-b9b24fdc9844.jsonl
Tool use blocks: 47
Tool result blocks: 44
Missing: 3 tool_result blocks

Root Cause:

  • User interruptions ([Request interrupted by user for tool use]) left tool_use blocks without corresponding tool_result blocks
  • These orphaned tool_use blocks prevent session resumption with the exact error: "tool_use ids were found without tool_result blocks"

Impact:

  • Sessions with mismatched counts cannot be resumed
  • Users must start new sessions, losing context

This confirms the issue is caused by incomplete tool_use/tool_result pairs in session files, particularly after user interruptions.

apstndb avatar Jun 24 '25 11:06 apstndb

This issue can also be caused by conflicting tool calls/overlapping functionality when one supersedes the other.

w0wl0lxd avatar Jun 24 '25 13:06 w0wl0lxd

same in Claude Code Status v1.0.33 ... the double esc and going back up to 10 positions before the error ... and no way to recover ...

jwaes avatar Jun 24 '25 18:06 jwaes

Hi guys, just received the same issue;

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

No way to reovery sessions and I lose all of my context.

^ This was using Claude Code on Debian WSL instance (Windows).

spruik-co avatar Jun 26 '25 13:06 spruik-co

Could you resume the affected session and submit a report using /bug? That will really help us debug. Thanks

On Thu, Jun 26, 2025 at 6:40 AM spruik-co @.***> wrote:

spruik-co left a comment (anthropics/claude-code#1894) https://github.com/anthropics/claude-code/issues/1894#issuecomment-3008541295

Hi guys, just received the same issue;

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

No way to reovery sessions and I lose all of my context.

— Reply to this email directly, view it on GitHub https://github.com/anthropics/claude-code/issues/1894#issuecomment-3008541295, or unsubscribe https://github.com/notifications/unsubscribe-auth/AADSWQXQM7UVJURQVMCXORT3FPZ4TAVCNFSM6AAAAAB677MV3OVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZTAMBYGU2DCMRZGU . You are receiving this because you modified the open/close state.Message ID: @.***>

igorkofman avatar Jun 26 '25 13:06 igorkofman

Hi @igorkofman - I had to step back 3/4 messages in terms of context and was able to continue. I didn't have to shut Claude down. Messaging the same thing wouldn't clear the error.

/bug ⎿  Error submitting bug report

:)

spruik-co avatar Jun 26 '25 14:06 spruik-co

Oh no! Try /bug again if it happens again. Are you on 1P or 3P?

On Thu, Jun 26, 2025 at 7:43 AM spruik-co @.***> wrote:

spruik-co left a comment (anthropics/claude-code#1894) https://github.com/anthropics/claude-code/issues/1894#issuecomment-3008746052

Hi @igorkofman https://github.com/igorkofman - I had to step back 3/4 messages in terms of context and was able to continue. I didn't have to shut Claude down. Messaging the same thing wouldn't clear the error.

/bug ⎿ Error submitting bug report

:)

— Reply to this email directly, view it on GitHub https://github.com/anthropics/claude-code/issues/1894#issuecomment-3008746052, or unsubscribe https://github.com/notifications/unsubscribe-auth/AADSWQV7VB62RZAXPZGPU333FQBIBAVCNFSM6AAAAAB677MV3OVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZTAMBYG42DMMBVGI . You are receiving this because you were mentioned.Message ID: @.***>

igorkofman avatar Jun 26 '25 15:06 igorkofman

I also was stuck this way today. Going back to a message before getting stuck (hit esc+esc) allowed me to continue.

felixniemeyer avatar Jun 29 '25 09:06 felixniemeyer

Still running into this on 1.0.24. Can we change the logic so it stops hard failing on badly formatted messages in context?

Anyone have workarounds?

jleechan2015 avatar Jul 02 '25 16:07 jleechan2015

Someone please fix this. ⎿ API Error: Claude Code is unable to respond to this request, which appears to violate our Usage Policy (https://www.anthropic.com/legal/aup). Please double press esc to edit your last message or start a new session for Claude Code to assist with a different task. ⎿  API Error: 400 {"type":"error","error":{"type":"invalid_request_error","message":"messages.223: tool_use ids were found without tool_result blocks immediately after: toolu_vrtx_01QhEAXjsVvt3yhEWBT5NwE2. Each tool_use block must have a corresponding tool_result block in the next message."}}

drhuston1 avatar Jul 02 '25 16:07 drhuston1

just ran into this as well. was pushing claude hard to spin up as many agents as it could on a large project. mostly just using a google workspace MCP so tons of tool calls, not even on the coding yet. realllly need this to be fixed though because my claude-trace wasnt running for part of this conversation and i need access to that context.

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

skarnz avatar Jul 03 '25 05:07 skarnz

This usually happens when we interupt claude while thinking and then send directly another message but the interuption before didnt really "intreupt" and it was yet still thinking or doing. thats what I was noticing.

FahrlyAdmin avatar Jul 09 '25 01:07 FahrlyAdmin

Getting the same exact thing, I can't just abandon the chat I have though

camspilly avatar Jul 09 '25 15:07 camspilly

1.0.48 hit the same issue today.

ccchow avatar Jul 10 '25 18:07 ccchow

esc-esc back a few steps with some new instructions seems to work around it. "note that we already implemented the task you were going to work on next, please proceed to task XYZ"

mikem-coalesce avatar Jul 11 '25 23:07 mikem-coalesce

Ran into the same issue. No amount of escaping fixed it. Had to start a new thread.

alandotcom avatar Jul 11 '25 23:07 alandotcom

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

Same issue

Graveside2022 avatar Jul 13 '25 18:07 Graveside2022

15 July 2025

 API Error: 400 
    {"type":"error","error":{"type":"invalid_request_error","message":"messages.6: `tool_use` 
    ids were found without `tool_result` blocks immediately after: 
    toolu_01WJjaQpXMi27SfHirJfLVpa. Each `tool_use` block must have a corresponding 
    `tool_result` block in the next message."}}
  ⎿  API Error (529 {"type":"error","error":{"type":"overloaded_error","message":"Overloaded"}}) · Retrying in 36 seconds… (attempt 9/10)

snapfast avatar Jul 15 '25 14:07 snapfast

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

webdevtodayjason avatar Jul 15 '25 15:07 webdevtodayjason