Fix guides · Claude Code ·

Fix Claude Code 400 about unpaired tool_use and tool_result blocks

Claude Code returns a 400 error when tool_use blocks aren't followed by their tool_result blocks in the conversation. The API names the specific tool_use ids found without matching tool_result blocks immediately after.

Claude Code returns a 400 error when tool_use blocks aren't followed by their tool_result blocks. Starting a new session usually clears it. The API requires each tool_use to be immediately followed by a matching tool_result in the next user message.

Free · 3 a day · no signup

Common causes – and how to tell which one you have

1. Interrupted tool call left an orphaned tool_use

How to tell: The error started right after a dropped connection, a Ctrl+C during a tool run, or a request that timed out mid-tool.

Fix: Start a new session in the same working directory and re-state the task. Do not paste the broken transcript back in.

2. Manually edited or merged transcript

How to tell: You edited a session file, merged two conversations, or resumed a session after upgrading Claude Code.

Fix: Start a new session in the same working directory and re-state the task. Do not paste the broken transcript back in.

3. Conversation history has unpaired tool_use

How to tell: The conversation has a tool_use block without a matching tool_result immediately after.

Fix: Start a new session and try the failing operation again.

4. History too long / compaction went wrong

How to tell: It appeared late in a long session, often right after an automatic compaction.

Fix: Start a new session in the same working directory and re-state the task. Do not paste the broken transcript back in.

How to fix it

  1. If you see a 400 about tool_use and tool_result blocks, the conversation history has an unpaired tool_use block. Use /clear in Claude Code or start a new session to rebuild clean history. Note that /clear or a new session drops the current conversation context — save any important work first, then re-state the task.
  2. Do not paste the broken transcript back in. A new session rebuilds a clean history.
  3. Try the failing operation again in the new session. Verify the 400 is gone before proceeding.
  4. Try the failing operation again in the new session. Verify the 400 is gone before proceeding.

Using Lovable, Bolt or v0?

This guide is written for the user. The primary fix is to start a new session. Do not instruct the model to run /compact — it's a slash command typed by the user in the CLI.

Using Cursor, Claude Code or Windsurf?

This guide is written for the user. The primary fix is to start a new session. Do not instruct the agent to run /compact — it's a slash command the user types in the CLI.

The “fix” to avoid

The primary fix is to start a new session in the same working directory and re-state the task. Do not paste the broken transcript back in. Compaction sends the broken history to the API and may hit the same 400, so do not rely on /compact as the first fix.

Copy-paste fix prompt for your AI coding tool

Paste this into Cursor, Claude Code, Lovable or Bolt:

Claude Code returns a 400 error about unpaired tool_use/tool_result blocks. Start a new session in the same working directory and re-state the task. Do not paste the broken transcript back in. A new session rebuilds a clean history. Try the failing operation again in the new session.
Your error looks a bit different? Paste your exact error and get a diagnosis tailored to your code — free.

Questions people ask

Why does Claude Code fail on every message, not just one?

The error persists because a persisted orphaned tool_use stays in the history and is resent with each request. Starting a new session clears it.

Will /compact lose my work?

It replaces the conversation history with a summary but keeps the files on disk. Your code changes are untouched; only the chat context is shortened.

Is this the same as the 413 request too large error?

No. 413 means the request body is too big. 400 tool_use/tool_result means a tool call is unpaired. Both often appear late in long sessions, but the fixes differ.

Related errors

Get fixes like this every week