[BUG] `tool_use` ids were found without `tool_result` blocks after failed cancel

Status Fixed / completed
Maintainer reply ✓ Yes — bcherny
Activity 13 comments · opened Apr 9, 2025 · closed May 8, 2025
💡 Likely answer: A maintainer (bcherny, collaborator) responded on this thread — see the highlighted reply below.

Environment

  • Platform (select one):
  • [X] Google Vertex AI
  • Claude CLI version: 0.2.66 (Claude Code)

Bug Description

  ⎿ API Error: 400 {"type":"error","error":{"type":"invalid_request_error","message":"messages.8: `tool_use` ids were found without

> /compact
  ⎿  Error: Error during compaction: Error: API Error: 400 {"type":"error","error":{"type":"invalid_request_error","message":"messages.8:
     `tool_use` ids were found without `tool_result` blocks immediately after: toolu_vrtx_015oxzdhxTvyks3Djx4FZE3h. Each `tool_use` block
     must have a corresponding `tool_result` block in the next message."}}

Steps to Reproduce

Not sure I'll be able to reproduce it. It happened after I hit Escape to cancel what it was doing after an auto-compaction, but it failed to properly cancel it. While the activity was still ongoing, I could submit prompts and hit enter, but it would immediately return:
⎿ API Error: 400 {"type":"error","error":{"type":"invalid_request_error","message":"messages.8: tool_use ids were found without
and continue running the previous activity.

I let it complete, then hit Escape to reject the proposed edit, and then tried to /compact, and got a more complete version of the same error, as show in the description section above.

Expected Behavior

When I hit escape, it cancels the ongoing activity.

View original on GitHub ↗

13 Comments

scottleibrand · 1 year ago

The ignored cancellation attempt thing just happened again. I think it might be related to the handling of the Escape cancellation sequence during the "status":"RESOURCE_EXHAUSTED"}}) · Retrying that are so common on Vertex AI: when I try to cancel in the middle of a retry, it seems to take me back to the prompt without actually cancelling the retry-in-progress task.

After the task finally completed, a /compact gives the same kind of error as before:

> /compact
  ⎿  Error: Error during compaction: Error: API Error: 400 {"type":"error","error":{"type":"invalid_request_error","message":"messages.371:
     `tool_use` ids were found without `tool_result` blocks immediately after: toolu_vrtx_01WRXD2syA3U7ay72PwF2u3B. Each `tool_use` block
     must have a corresponding `tool_result` block in the next message."}}
RekarBotany · 1 year ago

i face the same issue, any update?

L422Y · 1 year ago

claude code is persistently running into this when reading a specific file in my project, i have to tell it to use cat instead of whatever "Read" uses

update: I believe this might have to do with accessing files outside of the current startup path for claude code

when I ran into it the first time, it was always a file in a separate repo/parent directory

so i started a new session in that folder, and now it's causing the error on a file in the original path

dylan-conlin · 1 year ago

I just got this same error. Claude code was stalled while attempting to List files in a directory outside the directory where I started claude code. I escaped and got this error when sending a new message:

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

What I have noticed since opening this issue is that if I hit escape to cancel something, I have to wait for the interrupted by user message to show up, which requires waiting for the 429 overloaded messages to resolve and the last LLM call to complete. If I try to send anything before that, it goes into a bad state. There are probably other conditions that can get it into that state as well, but that is the one that I've been able to reliably reproduce.

L422Y · 1 year ago
What I have noticed since opening this issue is that if I hit escape to cancel something, I have to wait for the interrupted by user message to show up, which requires waiting for the 429 overloaded messages to resolve and the last LLM call to complete. If I try to send anything before that, it goes into a bad state. There are probably other conditions that can get it into that state as well, but that is the one that I've been able to reliably reproduce.

i think this happens after trying to access files outside the startup path

bcherny collaborator · 1 year ago

This should be feeling better in newer versions. Restart to update and feel free to open a new issue if you're still hitting this.

lostmsu · 1 year ago

@bcherny still reproduces on

$ claude --version 1.0.24 (Claude Code)
penwyp · 1 year ago
  • I quit claude code, setting some permissions tool in settings.json, then resume to latest conversation.
  • 1.0.27 (Claude Code)
  • {"type":"error","error":{"type":"invalid_request_error","message":"messages.9: tool_use ids were found without tool_result blocks immediately after: toolu_01GBbvmXsNhUCh31uLKymNFu. Each

tool_use block must have a corresponding tool_result block in the next message."}}

raoulmillais · 1 year ago

I am getting this error a lot after updating to claude updated to 1.0.51 . I have to scrollback though my session grabbing important pieces to summarise before exiting and restarting. I cannot summarise/compact or run any commands at all once I start receiving this error.

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

/info

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

Claude CLI Diagnostic
Currently running: unknown (1.0.51)
Path: /usr/bin/node
Invoked: /home/raoul/.npm-global/bin/claude
Config install method: unknown
Auto-updates enabled: true

christianpeirson · 1 year ago

also getting the error:

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."}}

rockerBOO · 1 year ago

workaround temporarily, if you can lose the last couple of messages, is to use escape escape and then fork it from a previous message before it had this issue. Still happening in the latest but worked for me.

github-actions[bot] · 1 year ago

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.