Missing Tool Result Block After Tool Use This error suggests that after a tool use block in the conversation, you did not include the corresponding tool result block, which is required by the API. To resolve this: 1. Ensure that any `tool_use` block is i
Resolved 💬 60 comments Opened Mar 13, 2025 by Belkins Closed Aug 22, 2025
💡 Likely answer: A maintainer (igorkofman, collaborator)
responded on this thread — see the highlighted reply below.
Bug Description
stuck on Error: API Error: 400 {"type":"error","error":{"type":"invalid_request_error","message":"messages.156: Did not find 1 tool_result block(s) at the beginning of this message. Messages following tool_use blocks must begin with a matching number of
tool_result blocks."}}
Environment Info
- Platform: macos
- Terminal: Apple_Terminal
- Version: 0.2.14
- Feedback ID: 4441d4b9-707d-4983-b467-74dd96d8ddc5
60 Comments
I ran across this error when using the Anthropic API (not Claude Code) and I assumed it was my fault initially. However I've looked more into it and I'm seeing something that looks like it could be a mistake on Anthropic's side. And I'm wondering if Claude Code may be subject to the same situation occasionally.
The key message sequence seems to be:
Note the assistant's own text content is BETWEEN the "tool_use" and the "tool_result" in the overall sequence. This seems to be the atypical order, as Claude most often will respond with (text first, tool_use second).
Here's an excerpt from the messages that cause the problem for me:
The error I get is this:
Note that the tool_result
toolu_01FGfUwSu2N7d8f1tAFh4snUIS directly after the assistant message.Curious if this resonates with anyone else that stumbles across this!
Actually, I ran into this just this evening as well - my solution was to order content blocks in messages like this:
This makes the API happy and guarantees responses are always right after requests, if you take all the blocks out and process them in literal order.
I think this is a bug in the Anthropic API - it used to work fine with the blocks out of order until just recently.
@myzie
Thanks @johnewart for chiming in!
Running into the same issue as well.
This becomes pretty complicated when it comes to building agents where you may not necessarily have a lot of control with the ordering of messages.
I thought i was going crazy but seems like the Anthropic API calls occasionally will return the messages out of order with tool use and result
Happening to me right now out of nowhere also
@TweedBeetle same here, right now
version
0.2.100Hello. Same for me.
hi same for me
From an affected user in Claude Code CLI: Is there a way I can recover my conversation when this happens? There's a lot of context I don't want to lose!
Edit: it's extremely hairy but I managed to rescue this session by finding the session JSON under
~/.claude/projects/_path_to_my_project/[LATEST-SESSION-STORE-HERE].jsonand editing out messages that caused the error (in my case the last 6 or so lines) before continuing the session withclaude -cHappening to me now as well in Claude Code. Anyone have a solution? Im stuck.
I am experiencing this the past 2 weeks trying to use Neovim Avante plugin with Anthropic API:
Error: {
message = "messages.10:
tool_useids were found withouttool_resultblocks immediately after: toolu_019dFspJ71N2tnHV31Bwkgq5. Eachtool_useblock must have a correspondingtool_resultblock in the next message.",type = "invalid_request_error"
}
Claude claims this is due to Avante. But looking at the discussions here, the problem seems to be related to Anthropic. I would appreciate any help.
I'll chime in that I too have just experienced this error in Neovim's
avanteplugin (claude-3-7-sonnet-latest), basically the same as @Erik-2040:This issue was opened over two months ago with many reported sufferers and 👍 s. Anthropic, can we at least hear from you?
Here is how I solved the problem. In avante.lua, I added:
disable_tools = true
Like this:
6 provider = 'claude',
7 claude = {
8 endpoint = 'https://api.anthropic.com',
9 model = 'claude-3-7-sonnet-20250219',
10 timeout = 30000,
11 temperature = 0,
12 --max_tokens = 20480,
13 max_tokens = 4096,
14 disable_tools = true,
15 -- REMOVED: strip_whitespace = true,
16 },
@Erik-2040
disable_tools = truekind of throws the baby out with the bathwater though, doesn't it? Sure you no longer get the error, but you also don't get tool calls, significantly limiting Claude's agentic intelligence. No?You're right. Today, I dealt with the issue again and the following solved the issue: mode = 'agentic',
...
opts = {
provider = 'claude',
claude = {
endpoint = 'https://api.anthropic.com',
model = 'claude-3-5-sonnet-20241022',
timeout = 30000,
temperature = 0,
max_tokens = 1024,
-- TRY THIS: More conservative tool handling
disable_tools = false,
)
},
-- IMPORTANT: Try 'agentic' mode - it handles tools better
mode = 'agentic', -- Better tool message handling than 'legacy'
...
I just ran into this error as well while using
claude-3-7-sonnet-20250219. With help from this thread I was able to see where the error was in the logs. I ran into the error during an interactiveclaudesession (installed via https://www.npmjs.com/package/@anthropic-ai/claude-code). It just kind of broke in the middle of processing a command. The output said "interrupted by user" and then I got the error on every following prompt.I ended up fixing it, and keeping the context, by using the "undo" feature ( pressing escape twice ), and going to the command before the one that broke it. After that it worked just fine again. Feels like it broke during processing but moving back to before the problem made claude .. forget(?)? Whats strange is that I still see the affected blocks in the log.
I'm unsure if my situation is or will be similar to anyone else's, but that's what happened with me.
Ran into this on claude code 1.10, did a
/bug. maybe it will help you debugalso getting this and no way to recover in the claude code session
API Error: 400 {"type":"error","error":{"type":"invalid_request_error","message":"messages.92:tool_usetool_resultids were found without
blocks immediately after: toolu_01S1bUuuq1FAWEg8FEJsXFaG. Each
tool_useblock must have a correspondingtool_resultblock in the next message."}}Thank you, this (double escape and choose an earlier history checkpoint) worked for me to recover
This happens to me all the time if I press [ESC] while it is trying to do something...
Also happened to me twice now (once was after pasting logs) and wasn't able to recover the session. Double ESC works -- thanks everyone!
Welp, I ran into this too, but I was able to recover the session with the following:
~/.claude/projects/<project-path-name>/<session-uuid>.jsonlclaude --resume <session-uuid>Again, remember to backup the session file first!
@dhirajsb
how did you find the session id?
@abhagsain
use --output-format json option.
like
claude -c -p --output-format json "hello"| jqrefs: https://docs.anthropic.com/en/docs/claude-code/sdk#json-output
I don't know what's wrong but whenever I try to resume my session the claude memory spikes up and after 1-2 minute the system restarts itself, so probably I lost the context? :(
!Image
!Image
This tool issue is happening when Claude is doing something and you hit ESC. You'll see the message "Interrupted by the user" in the console. After that, you'll get the tool call issue.
My memory spike issue was happening because to edit this JSON lines file I was opening it in WindSurf because the content was not readable.
I set the language mode of the editor to JSON so I can read the content, and the editor formatted the file.
When you format the file to a JSON type, it will ad new lines, spacing etc, in the file
!Image
I’m running into the same issue.
Environment details:
node:18-slim)@anthropic-ai/claude-codeglobally via npm``
sh
``claude --dangerously-skip-permissions --model opus -p "$(cat "$prompt_file")";
/workspaceand i got this:
API Error: 400 {"type":"error","error":{"type":"invalid_request_error","message":"messages.97:
tool_useids were found withouttool_resultblocks immediately after: toolu_018TaGiocJstYpjX5biVRdDu. Eachtool_useblock must have a correspondingtool_resultblock in the next message."}}Let me know if any extra logs or configs would help—happy to provide more info.
Luckily, I just had one session at the time, but if you do get an error with a tool call id, you can grep for it in your sessions and find the session id from the jsonl file name.
It works, thank you!
I tried this and no go. Solution = edit the request using a different AI altogether. Sorry but this is a workflow breaking critical issue that is still ongoing across various "API calls"
This is why, I always keep an editor open in the claude conversation history directory so whenever I face the issue, I can search the last message, remove the tool calls error and resume the session.
It's a hassle, but it works. I wish Anthropic solves this quickly and lately I'm getting these APi errors 🙄
!Image
I just linked several duplicate issues for the same bug. It seems the latest release has been causing this to happen more frequently. In #1776 @illusivejosiah has an additional work around suggestion, stating:
The double escape solution to fork the session might be the easiest workaround I've seen so far. That's assuming you didn't quit out of frustration like I had and had to resort to hand editing the session logs. :(
Fix for Claude Code CLI "tool_use without tool_result" Error
The Problem
If you're encountering this error with Claude Code CLI:
This happens when Claude's session history contains tool_use messages that don't have corresponding tool_result messages immediately following them. This can occur due to interrupted sessions, network issues, or other edge cases.
The Solution
I've created a Python script that automatically fixes these corrupted session files by:
The Script
How to Use
``
bash
``# Search for session files with the error
grep -l "tool_use.*ids were found without.*tool_result" ~/.claude/projects/*/*.jsonl
``
bash
``# Save the script above to a file
nano ~/fix_claude_session.py
# Make it executable
chmod +x ~/fix_claude_session.py
``
bash
``python3 ~/fix_claude_session.py /path/to/your/problematic/session.jsonl
``
bash
``claude -c
Finding Session Files
You can use Claude Code to help identify recent conversations:
Claude Code stores session files in:
~/.claude/projects/[project-path]/[session-id].jsonlThe project path is your working directory with slashes replaced by dashes. For example:
/home/user/my-project→~/.claude/projects/-home-user-my-project/What the Script Does
Example Output
---
This solution was discovered and implemented using Claude Code itself! When I encountered this error, I asked Claude to help me understand the issue and create a fix. Claude analyzed the session file structure, identified the pattern causing the error, wrote this script to automatically repair corrupted sessions, AND even helped me write this GitHub comment explaining how to fix it. Talk about self-healing AI helping itself! 🤖
If this helps you, please give it a thumbs up. If you encounter any issues or have improvements, feel free to comment below.
This needs a solid fix. It destroys my sessions.
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.
Still facing the issue after updating to 1.0.22, session becomes irrecoverable
same here after updating to 1.0.22
1.0.25 – still experiencing the issue. Rewinding ("esc" twice) doesn't help.
1.0.27 - was working for few days stable (I just got into claude code few days ago), and for past hour I started getting this error few times.
One of the folks still hitting this issue, could you share more details on the session (screen shot or some sense of what was happening)? Ideally you'd load an affected session with claude --resume and then use /bug to share it with us for debugging. Would love to track any remaining issues here down.
1.0.29 - still experiencing.
Submitted the bug report as
9270c693-f07d-41e8-83be-1d8a101f2e321.0.34 and still experiencing
1.0.35 - still experiencing
@igorkofman (hi! been a while!) — submitted a
/bugfor81488219-6078-4013-883c-e8e1ffea57d3I had been seeing this pretty frequently a few weeks ago but it had gone away until today.
Same, seeing it frequently, It always triggers when asked to conduct web search. Web searches for me fail about ~60% of the time if not more.
v1.0.38 - still experiencing.
Perhaps Claude Code just doesn't exit gracefully when encountering an improper image (bad curl, different platforms modifying the image differently, etc). Another possibility is outages on the backend for image processing.
I often have to caution Claude to avoid image analysis otherwise the session gets locked up until I run /clear .
I had the issue almost daily for a month - but as of
v1.0.40, it's stopped occurring for me.I haven't had the issue before, though after the release of v1.0.40 it's happened several times.
I saw this issue today.
I am using claude code with bedrock. Same issue.
it happens irregularly no matter what version I have this since version 1.0.10
It happens on version 1.0.44 when I use
claude --continuein one project, not even pressing esc twice helps, I can rollback as far as I can and it won't budge. I have submitted /bug with this ID1421edcf-5be3-4dcc-8723-6259a5ab1e42Yep, the issue seems to be back with a vengeance today.
I've seen a few "Interrupted by user" when I didn't press anything - so I wonder if that's got anything to do with it?
Hey guys, I fix this bug with reorder messages, this is my idea:
on step 4, if you run this, wont you be getting a new session? I checked with /status and i see a new session id altogether. i ran it with --resume it works but its constantly arising one after the other.
This should be fixed in the latest version. Make sure
claude update, and let us know if you're still hitting this.Hitting this with 1.0.89 today. My session last night was stopped by Claude's own 5 hour cutoff.
This should be self-healing.
EDIT: although the script above makes changes and seems satisfied, I still get the error resuming that session. @bcherny
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.