[Bug] Anthropic API Error: Invalid tool_result block without corresponding tool_use

Status Closed — not planned
Maintainer reply None cached
Activity 11 comments · opened Nov 4, 2025 · closed Feb 28, 2026

Bug Description
I was using claude code and it did not complete. It shows disconnected and I cant recomment. I used teleport claude --teleport session_011CUodG12UHpWf6HYKJ97iT to run on my deskotp now I get the error ⎿ API Error: 400 {"type":"error","error":{"type":"invalid_request_error","message":"messages.2.content.1: unexpected tool_use_id
found in tool_result blocks: toolu_01TFQZVdAgEdnmsGYZ3qZhs1. Each tool_result block must have a corresponding tool_use block
in the previous message."},"request_id":"req_011CUokNANXZnaviTWyswzPa"}

Environment Info

  • Platform: linux
  • Terminal: xterm-256color
  • Version: 2.0.33
  • Feedback ID: 6e01ccde-2760-4ba8-8dea-841bbb9c8a58

Errors

[{"error":"Error: 400 {\"type\":\"error\",\"error\":{\"type\":\"invalid_request_error\",\"message\":\"messages.2.content.1: unexpected `tool_use_id` found in `tool_result` blocks: toolu_01TFQZVdAgEdnmsGYZ3qZhs1. Each `tool_result` block must have a corresponding `tool_use` block in the previous message.\"},\"request_id\":\"req_011CUokNANXZnaviTWyswzPa\"}\n    at L4.generate (file:///home/kmcisaac/.npm-global/lib/node_modules/@anthropic-ai/claude-code/cli.js:204:83066)\n    at E_.makeStatusError (file:///home/kmcisaac/.npm-global/lib/node_modules/@anthropic-ai/claude-code/cli.js:689:2117)\n    at E_.makeRequest (file:///home/kmcisaac/.npm-global/lib/node_modules/@anthropic-ai/claude-code/cli.js:689:5341)\n    at process.processTicksAndRejections (node:internal/process/task_queues:105:5)\n    at async psA.model (file:///home/kmcisaac/.npm-global/lib/node_modules/@anthropic-ai/claude-code/cli.js:3394:14692)\n    at async psA (file:///home/kmcisaac/.npm-global/lib/node_modules/@anthropic-ai/claude-code/cli.js:1987:39781)\n    at async jn2 (file:///home/kmcisaac/.npm-global/lib/node_modules/@anthropic-ai/claude-code/cli.js:3394:14846)\n    at async file:///home/kmcisaac/.npm-global/lib/node_modules/@anthropic-ai/claude-code/cli.js:3394:8667\n    at async $10 (file:///home/kmcisaac/.npm-global/lib/node_modules/@anthropic-ai/claude-code/cli.js:3394:1970)\n    at async J8A (file:///home/kmcisaac/.npm-global/lib/node_modules/@anthropic-ai/claude-code/cli.js:3394:8637)","timestamp":"2025-11-04T23:52:21.441Z"}]

View original on GitHub ↗

11 Comments

github-actions[bot] · 9 months ago

Found 3 possible duplicate issues:

  1. https://github.com/anthropics/claude-code/issues/11017
  2. https://github.com/anthropics/claude-code/issues/10321
  3. https://github.com/anthropics/claude-code/issues/8484

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

rdhyee · 9 months ago

I'm experiencing the same issue. Here are my details:

Error message:

API Error: 400 {"type":"error","error":{"type":"invalid_request_error","message":"messages.66.content.0: unexpected `tool_use_id` found in `tool_result` blocks: toolu_01N6yTMe3b3JTVd1ovn4DXKk. Each `tool_result` block must have a corresponding `tool_use` block in the previous message."},"request_id":"req_011CUtnaSm6iVoWWkmpERKVx"}

Context:

  • Session ID: 011CUsD4ysC76c9bWy7xNjQq
  • Message count: 66+ messages with extensive tool use (Read, Write, Edit, Git operations, WebSearch)
  • Teleported from web → CLI
  • First prompt after teleport: "Hey, we just finished building the Zotero sync tool. Set it up and test it now."

Impact: Session completely unusable after teleport. Same behavior as described in original issue - the tool_use/tool_result blocks get desynchronized during the teleport process.

Reproducibility: Happened on first attempt at teleporting a long development session (creating tooling infrastructure, multiple commits, extensive file operations).

+1 for prioritizing a fix - teleport is a key feature but currently unreliable with longer sessions involving tool use.

github-actions[bot] · 8 months ago

This issue has been inactive for 30 days. If the issue is still occurring, please comment to let us know. Otherwise, this issue will be automatically closed in 30 days for housekeeping purposes.

attiasr · 7 months ago

Root Cause Analysis (Additional Detail)

I reproduced this bug systematically and traced the root cause in the transcript JSONL files:

The Mechanism

  1. Streaming splits one assistant message into multiple JSONL lines

When an agent streams a response with multiple content blocks (text + tool_uses), each block is logged as a separate JSONL line:

Line 3: assistant text "I'll help..."           (requestId: req_abc123)
Line 4: assistant tool_use (Read)               (requestId: req_abc123) ← SAME request
Line 5: assistant tool_use (Bash)               (requestId: req_abc123) ← SAME request  
Line 6: assistant tool_use (Glob)               (requestId: req_abc123) ← SAME request
Line 7: user tool_result for Read               
Line 8: user tool_result for Bash
Line 9: user tool_result for Glob
  1. Resume reconstruction doesn't merge them back

When reconstructing the conversation for resume, each JSONL line is treated as a separate message instead of merging entries with the same requestId into a single assistant message.

  1. Result: Invalid message structure

The tool_result in Line 7 references toolu_01... from Line 4, but the reconstructed "previous message" only contains one content block (not all the tool_uses), causing the API error.

Evidence

Transcripts are stored at: ~/.claude/projects/{project-path}/agent-{agentId}.jsonl

Working transcript (agent used 0 tools):

  • Simple user/assistant alternation
  • Resume works

Broken transcript (agent used 3 tools):

  • Assistant response split across 4 JSONL lines (text + 3 tool_uses)
  • Resume fails with 400 error

Fix Suggestion

The transcript reconstruction logic needs to:

  1. Merge consecutive assistant entries with the same requestId into a single message, OR
  2. Write the complete message after streaming completes instead of logging each streamed block

Reproduction Steps

# 1. Spawn agent that will use tools
Task(subagent_type="explore", prompt="Find Python files")
# Agent uses Glob/Read tools, returns agentId: abc123

# 2. Resume - FAILS
Task(resume="abc123", prompt="Continue")  
# API Error 400: tool_use_id mismatch

Version: 2.0.76 | Platform: macOS

sz-po · 7 months ago

I'm experiencing the same issue with Claude Code 2.0.76.

When resuming a custom subagent after it used the Bash tool in the first invocation, I get the same 400 error: unexpected tool_use_id found in tool_result blocks: toolu_01ReEgxs4QLRkPfWiHhKQmVS

The subagent works perfectly on first call but fails immediately on any resume attempt. Currently working around this by passing session data in prompts instead of using the resume parameter.

skerit · 7 months ago

So Claude says the error it gets is:

● The full error message is:

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

  That's all it returns. No additional details.

I'm unable to resume the subagent session. Because of this, I have to run the entire thing again, wasting precious tokens.

attiasr · 7 months ago
## Root Cause Analysis (Additional Detail) I reproduced this bug systematically and traced the root cause in the transcript JSONL files: ### The Mechanism 1. Streaming splits one assistant message into multiple JSONL lines When an agent streams a response with multiple content blocks (text + tool_uses), each block is logged as a separate JSONL line: `` Line 3: assistant text "I'll help..." (requestId: req_abc123) Line 4: assistant tool_use (Read) (requestId: req_abc123) ← SAME request Line 5: assistant tool_use (Bash) (requestId: req_abc123) ← SAME request Line 6: assistant tool_use (Glob) (requestId: req_abc123) ← SAME request Line 7: user tool_result for Read Line 8: user tool_result for Bash Line 9: user tool_result for Glob ` 2. **Resume reconstruction doesn't merge them back** When reconstructing the conversation for resume, each JSONL line is treated as a separate message instead of merging entries with the same requestId into a single assistant message. 3. **Result: Invalid message structure** The tool_result in Line 7 references toolu_01... from Line 4, but the reconstructed "previous message" only contains one content block (not all the tool_uses), causing the API error. ### Evidence Transcripts are stored at: ~/.claude/projects/{project-path}/agent-{agentId}.jsonl **Working transcript (agent used 0 tools):** * Simple user/assistant alternation * Resume works **Broken transcript (agent used 3 tools):** * Assistant response split across 4 JSONL lines (text + 3 tool_uses) * Resume fails with 400 error ### Fix Suggestion The transcript reconstruction logic needs to: 1. Merge consecutive assistant entries with the same requestId` into a single message, OR 2. Write the complete message after streaming completes instead of logging each streamed block ### Reproduction Steps # 1. Spawn agent that will use tools Task(subagent_type="explore", prompt="Find Python files") # Agent uses Glob/Read tools, returns agentId: abc123 # 2. Resume - FAILS Task(resume="abc123", prompt="Continue") # API Error 400: tool_use_id mismatch Version: 2.0.76 | Platform: macOS

v2.1.2 Works for me.

attiasr · 7 months ago
v2.1.2 Works for me.

Regression on v2.1.4

JasonBoy · 7 months ago

similar issue when resuming a custom subagent if the first subagent run has 3+ tool uses, most time hangs forever, still issues in v2.1.15+, with 400 error shows "tool use concurrency issues"

github-actions[bot] · 6 months ago

Closing for now — inactive for too long. Please open a new issue if this is still relevant.

github-actions[bot] · 5 months 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.