Title: API Error 400 (invalid_request_error) on follow-up message during parallel sub-agent plan execution
Description
When running a complex debugging task, Claude Code initiated a multi-agent plan with four parallel sub-agents. After the sub-agents completed their investigation and I approved the final consolidated plan, I sent a follow-up message while Claude was beginning to execute the plan. This resulted in a 400 invalid_request_error from the API, citing mismatched tool_use and tool_result blocks.
The error seems to stem from a race condition or state management issue where a tool_use call from a parallel sub-task was included in the API request context for the follow-up message before its corresponding tool_result was available.
Steps to Reproduce
- Start a complex task that prompts Claude to use multiple parallel sub-agents and generate a plan. (e.g.,
kill all daemon processes. why is statusline not working in this new terminal window? use parallel sub-agents to find out why...).
- Allow the parallel sub-agents to complete their investigation and present their plans.
- Approve the final, consolidated plan for execution.
- Immediately after Claude acknowledges the plan approval and begins execution (e.g., updates its
Todo list), send a new follow-up message.
- Observe the API error.
Expected Behavior
Claude should gracefully handle the follow-up message, either by queuing it until the current step is complete or by integrating it into the ongoing execution without causing an API error.
Actual Behavior
A 400 invalid_request_error is returned from the API with the following message:
{
"type": "error",
"error": {
"type": "invalid_request_error",
"message": "messages.8: `tool_use` ids were found without `tool_result` blocks immediately after: toolu_01Qu2dmLfdZPZRMYT4ntdMgG. Each `tool_use` block must have a corresponding `tool_result` block in the next message."
}
}
This error occurred twice when I repeated the follow-up message.
Environment
- Claude Code Version: 1.0.80
- OS: macOS
- Model: claude-opus-4-1-20250805
Session Log
Click to expand the full terminal session log
╭─────────────────────────────────────────────────────────╮
│ ✻ Welcome to Claude Code! │
│ │
│ /help for help, /status for your current setup │
│ │
│ cwd: /Users/user/Desktop/2025-08-09-statusline │
╰─────────────────────────────────────────────────────────╯
> kill all daemon processes. why is statusline not working in this new terminal window? use parallel
sub-agents to find out why. ultrathink. analyze this annoying ongoing problem.
✻ Thinking…
The user wants me to:
1. Kill all daemon processes
2. Figure out why the statusline is not working in the new terminal window
3. Use parallel sub-agents to investigate
4. "Ultrathink" - they want me to think deeply about this problem
5. Analyze this ongoing annoying problem
Since I'm in plan mode, I cannot execute anything yet. I need to:
1. First investigate the current state
2. Use parallel sub-agents to analyze the problem
3. Present a comprehensive plan
Let me start by understanding the current situation and then launch parallel agents to investigate
different aspects of the problem.
⏺ I'll investigate why the statusline isn't working in the new terminal window. Let me launch parallel
sub-agents to thoroughly analyze this issue from multiple angles.
⏺ Task(Analyze daemon processes)
⎿ Done (19 tool uses · 33.2k tokens · 2m 37.4s)
⏺ Task(Debug statusline configuration)
⎿ Done (31 tool uses · 39.9k tokens · 2m 37.9s)
Task(Analyze terminal environment)
⎿ Done (37 tool uses · 45.8k tokens · 5m 53.3s)
⏺ Task(Review recent changes)
⎿ Done (24 tool uses · 33.9k tokens · 2m 35.6s)
✻ Thinking…
Good! All four agents have completed their analysis and provided approved plans. Now I'm out of plan mode
and can start implementing the fixes. Let me create a comprehensive todo list based on all the findings
and then start executing the fixes.
The key issues identified:
1. Multiple orphaned daemon processes running (15+)
2. Missing .claude/bin directory in PATH
3. Shell integration missing for new terminals
4. Cache validation issues (too strict)
5. Complex IPC/daemon startup issues
6. Stale lock files and IPC channels
Let me create a todo list and start implementing the fixes.
⏺ Based on the parallel investigation, I've identified the core issues. Let me create a comprehensive action
plan and fix the statusline problems.
⏺ Update Todos
⎿ ☐ Kill all orphaned daemon processes
☐ Clean up stale IPC channels and lock files
☐ Create missing .claude/bin directory
☐ Fix cache validation issues (revert to simpler logic)
☐ Simplify daemon startup mechanism
☐ Add shell integration for new terminals
☐ Test statusline in new terminal window
☐ Run tmux test suite to validate fixes
✻ Thinking…
Now let me start implementing the fixes. First, I'll kill all the orphaned daemon processes.
⏺ Let me start by killing all daemon processes and cleaning up the system.
Update Todos
⎿ ☐ Kill all orphaned daemon processes
☐ Clean up stale IPC channels and lock files
☐ Create missing .claude/bin directory
☐ Fix cache validation issues (revert to simpler logic)
☐ Simplify daemon startup mechanism
☐ Add shell integration for new terminals
☐ Test statusline in new terminal window
☐ Run tmux test suite to validate fixes
✻ Thinking…
Now let me kill all the daemon processes. I'll use a combination of commands to find and kill them.
> make sure to use multiuple sub-agents to do this in parallel (i possible)
⎿ API Error: 400 {"type":"error","error":{"type":"invalid_request_error","message":"messages.8: `tool_use`
ids were found without `tool_result` blocks immediately after: toolu_01Qu2dmLfdZPZRMYT4ntdMgG. Each
`tool_use` block must have a corresponding `tool_result` block in the next message."}}
> make sure to use multiuple sub-agents to do this in parallel (if possible)
⎿ API Error: 400 {"type":"error","error":{"type":"invalid_request_error","message":"messages.8: `tool_use`
ids were found without `tool_result` blocks immediately after: toolu_01Qu2dmLfdZPZRMYT4ntdMgG. Each
`tool_use` block must have a corresponding `tool_result` block in the next message."}}
⏺ Bash(ps aux | grep -E "statusline.*daemon|claude.*daemon|state_daemon|claude-stop-hook" | grep -v grep)
⎿ user 2896 0.1 0.0 410758576 1760 ?? S 3:59PM 0:20.76 /bin/bash /Users/konstan
tin/.claude/claude-stop-hook.sh
user 29944 0.0 0.0 410768304 6368 s000 S+ 1:09AM 0:00.12 bash /Users/user/D
… +26 lines (ctrl+r to expand)
⏺ Bash(pkill -f "statusline.*daemon" 2>/dev/null; pkill -f "state_daemon" 2>/dev/null; pkill -f
"claude-stop-hook" 2>/dev/null; echo "Killed daemon processes")
⎿ Killed daemon processes
⏺ Bash(rm -f /tmp/claude_ipc_* /tmp/claude_daemon_* 2>/dev/null; echo "Cleaned up IPC files")
⎿ Running hook PreToolUse:Bash...
⎿ Running…
Title: API Error 400 (
invalid_request_error) on follow-up message during parallel sub-agent plan executionDescription
When running a complex debugging task, Claude Code initiated a multi-agent plan with four parallel sub-agents. After the sub-agents completed their investigation and I approved the final consolidated plan, I sent a follow-up message while Claude was beginning to execute the plan. This resulted in a
400 invalid_request_errorfrom the API, citing mismatchedtool_useandtool_resultblocks.The error seems to stem from a race condition or state management issue where a
tool_usecall from a parallel sub-task was included in the API request context for the follow-up message before its correspondingtool_resultwas available.Steps to Reproduce
kill all daemon processes. why is statusline not working in this new terminal window? use parallel sub-agents to find out why...).Todolist), send a new follow-up message.Expected Behavior
Claude should gracefully handle the follow-up message, either by queuing it until the current step is complete or by integrating it into the ongoing execution without causing an API error.
Actual Behavior
A
400 invalid_request_erroris returned from the API with the following message:{ "type": "error", "error": { "type": "invalid_request_error", "message": "messages.8: `tool_use` ids were found without `tool_result` blocks immediately after: toolu_01Qu2dmLfdZPZRMYT4ntdMgG. Each `tool_use` block must have a corresponding `tool_result` block in the next message." } }This error occurred twice when I repeated the follow-up message.
Environment
Session Log
Click to expand the full terminal session log