[BUG] API Error: 400 "tool_use ids were found without tool_result blocks" in Claude Code

Resolved 💬 3 comments Opened Sep 10, 2025 by chalatico Closed Sep 13, 2025

Preflight Checklist

  • [x] I have searched existing issues and this hasn't been reported yet
  • [x] This is a single bug report (please file separate reports for different bugs)
  • [x] I am using the latest version of Claude Code

What's Wrong?

When using Claude Code to create Python files, I'm getting an API error that prevents file creation. The error appears to be related to tool usage validation where tool_use blocks are not properly matched with tool_result blocks.

Error Message:
API Error: 400 {"type":"error","error":{"type":"invalid_request_error","message":"messages.22: tool_use ids were found without tool_result blocks

API Error: 400 {"type":"error","error":{"type":"invalid_request_error","message":"messages.22: tool_use ids were found without tool_result blocks"}}

Expected Behavior:
Claude Code should create Python script files successfully without API validation errors.

Actual Behavior:
The command fails immediately after accepting file write permissions with the above API error.

What Should Happen?

  1. Open Claude Code in terminal
  2. Create a Python file with basic content (e.g., test.py)
  3. When prompted for file access permissions, accept
  4. Observe the API error: "Unable to parse..." appears
  5. File creation fails

Note: The bug appears to occur specifically with Python files containing tool usage patterns.

Error Messages/Logs

This appears to be an API validation issue where the Claude Code client is sending malformed requests with tool_use blocks that lack corresponding tool_result blocks. This suggests an internal issue with how Claude Code structures its API calls when handling file operations.

The error occurs at message index 22, indicating this happens after some conversation history has been built up during the file creation process.

Steps to Reproduce

  1. Open Claude Code in terminal
  2. Create a Python file with basic content (e.g., test.py)
  3. When prompted for file access permissions, accept
  4. Observe the API error: "Unable to parse..." appears
  5. File creation fails

Note: The bug appears to occur specifically with Python files containing tool usage patterns.

Claude Model

None

Is this a regression?

Yes, this worked in a previous version

Last Working Version

1.0.110

Claude Code Version

Claude

Platform

Anthropic API

Operating System

Windows

Terminal/Shell

PowerShell

Additional Information

This appears to be an API validation issue where the Claude Code client is sending malformed requests with tool_use blocks that lack corresponding tool_result blocks. This suggests an internal issue with how Claude Code structures its API calls when handling file operations.

The error occurs at message index 22, indicating this happens after some conversation history has been built up during the file creation process.

View original on GitHub ↗

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