[BUG] API Error: 400 "tool_use ids were found without tool_result blocks" in Claude Code
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?
- Open Claude Code in terminal
- Create a Python file with basic content (e.g.,
test.py) - When prompted for file access permissions, accept
- Observe the API error: "Unable to parse..." appears
- 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
- Open Claude Code in terminal
- Create a Python file with basic content (e.g.,
test.py) - When prompted for file access permissions, accept
- Observe the API error: "Unable to parse..." appears
- 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.
This issue has 3 comments on GitHub. Read the full discussion on GitHub ↗