[Bug] Anthropic API Error: Missing Tool Result Blocks

Resolved 💬 3 comments Opened Sep 26, 2025 by erangross27 Closed Sep 30, 2025

Bug Description
GitHub Issue Template:

# Bug: Missing tool_result blocks cause API 400 errors (v1.0.126)

## Environment

  • Version: 1.0.126
  • Platform: Linux/Node.js
  • Installation: npm install -g @anthropic-ai/claude-code

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

## Reproduction Steps

  1. Use Claude Code to read a PDF file (or any tool operation)
  2. Error occurs when tool_use calls are made in longer conversations
  3. API returns 400 error about missing tool_result blocks

## Technical Analysis
Root Cause: Message construction pipeline fails to add tool_result blocks after executing tools.

Evidence from installed code analysis:

  • ✅ Tools execute correctly and have mapToolResultToToolResultBlockParam functions
  • tool_use blocks are created properly in assistant messages
  • Message sequencer fails to call mapToolResultToToolResultBlockParam and add tool_result blocks

Code Pattern Found:
Each tool has a function like this:
```javascript
mapToolResultToToolResultBlockParam(result, toolUseId) {
return {
tool_use_id: toolUseId,
type: "tool_result",
content: / processed result /
}
}

Fix Required:
Ensure the message builder calls each tool's mapToolResultToToolResultBlockParam function and adds the result as a tool_result block in a user message immediately after every
tool_use block.

Impact

High - Breaks core functionality when using tools, especially PDF reading.

Workaround

Use Esc+Esc to rewind conversation before error occurs.

## 🔧 If You Want to Attempt a Fix

If Claude Code ever becomes open source or you find another way to access the source, the fix would be in the message construction logic:

```typescript
// Find the code that does this:
messages.push({
role: "assistant",
content: [toolUseBlock]
});

// Make sure it also does this immediately after:
const toolResult = await executeTool(toolUseBlock);
const toolResultBlock = tool.mapToolResultToToolResultBlockParam(toolResult, toolUseBlock.id);

messages.push({
role: "user",
content: [toolResultBlock]
});

Environment Info

  • Platform: linux
  • Terminal: gnome-terminal
  • Version: 1.0.126
  • Feedback ID: 22539fe0-25f8-4b86-a97e-5f932d7de2ff

**Note:** Error logs were truncated.

View original on GitHub ↗

This issue has 3 comments on GitHub. Read the full discussion on GitHub ↗