claude-code - 💡(How to fix) Fix [Bug] Anthropic API Error: 400 Invalid Request after /branch with concurrent tool use [1 participants]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…
GitHub stats
anthropics/claude-code#51977Fetched 2026-04-23 07:39:51
View on GitHub
Comments
0
Participants
1
Timeline
5
Reactions
0
Author
Participants
Timeline (top)
labeled ×5

Error Message

[{"error":"Error: 1: Command failed with ERR_STREAM_PREMATURE_CLOSE: code --force --install-extension anthropic.claude-code\nPremature close \n at YW1 (/$bunfs/root/src/entrypoints/cli.js:1705:4045)\n at async AW1 (/$bunfs/root/src/entrypoints/cli.js:1705:1435)\n at processTicksAndRejections (native:7:39)","timestamp":"2026-04-22T13:27:31.765Z"},{"error":"Error: 400 {"type":"error","error":{"type":"invalid_request_error","message":"messages.105: tool_use ids were found without tool_result blocks immediately after: toolu_01C1pd1qw8yJbP79vX5NbyxG. Each tool_use block must have a corresponding tool_result block in the next message."},"request_id":"req_011CaJtRpMWuvPSmBFSBLDiY"}\n at generate (/$bunfs/root/src/entrypoints/cli.js:11:54302)\n at makeRequest (/$bunfs/root/src/entrypoints/cli.js:50:4943)\n at processTicksAndRejections (native:7:39)","timestamp":"2026-04-22T13:27:38.539Z"}]

Code Example

[{"error":"Error: 1: Command failed with ERR_STREAM_PREMATURE_CLOSE: code --force --install-extension anthropic.claude-code\nPremature close \n    at YW1 (/$bunfs/root/src/entrypoints/cli.js:1705:4045)\n    at async AW1 (/$bunfs/root/src/entrypoints/cli.js:1705:1435)\n    at processTicksAndRejections (native:7:39)","timestamp":"2026-04-22T13:27:31.765Z"},{"error":"Error: 400 {\"type\":\"error\",\"error\":{\"type\":\"invalid_request_error\",\"message\":\"messages.105: `tool_use` ids were found without `tool_result` blocks immediately after: toolu_01C1pd1qw8yJbP79vX5NbyxG. Each `tool_use` block must have a corresponding `tool_result` block in the next message.\"},\"request_id\":\"req_011CaJtRpMWuvPSmBFSBLDiY\"}\n    at generate (/$bunfs/root/src/entrypoints/cli.js:11:54302)\n    at makeRequest (/$bunfs/root/src/entrypoints/cli.js:50:4943)\n    at processTicksAndRejections (native:7:39)","timestamp":"2026-04-22T13:27:38.539Z"}]
RAW_BUFFERClick to expand / collapse

Bug Description API Error: 400 due to tool use concurrency issues after /branch (fork) conversation

Environment Info

  • Platform: darwin
  • Terminal: vscode
  • Version: 2.1.117
  • Feedback ID: 15f674ec-8a03-44b2-8349-eb8ca6f1c954

Errors

[{"error":"Error: 1: Command failed with ERR_STREAM_PREMATURE_CLOSE: code --force --install-extension anthropic.claude-code\nPremature close \n    at YW1 (/$bunfs/root/src/entrypoints/cli.js:1705:4045)\n    at async AW1 (/$bunfs/root/src/entrypoints/cli.js:1705:1435)\n    at processTicksAndRejections (native:7:39)","timestamp":"2026-04-22T13:27:31.765Z"},{"error":"Error: 400 {\"type\":\"error\",\"error\":{\"type\":\"invalid_request_error\",\"message\":\"messages.105: `tool_use` ids were found without `tool_result` blocks immediately after: toolu_01C1pd1qw8yJbP79vX5NbyxG. Each `tool_use` block must have a corresponding `tool_result` block in the next message.\"},\"request_id\":\"req_011CaJtRpMWuvPSmBFSBLDiY\"}\n    at generate (/$bunfs/root/src/entrypoints/cli.js:11:54302)\n    at makeRequest (/$bunfs/root/src/entrypoints/cli.js:50:4943)\n    at processTicksAndRejections (native:7:39)","timestamp":"2026-04-22T13:27:38.539Z"}]

extent analysis

TL;DR

The issue can likely be resolved by ensuring that each tool_use block has a corresponding tool_result block in the next message to avoid concurrency issues.

Guidance

  • Review the API request payload to verify that tool_use ids are properly paired with tool_result blocks.
  • Check the code that generates the API request to ensure it handles concurrency correctly and doesn't send tool_use blocks without corresponding tool_result blocks.
  • Consider adding error handling to catch and retry failed requests that return a 400 error due to invalid_request_error.
  • Investigate the ERR_STREAM_PREMATURE_CLOSE error to determine if it's related to the concurrency issue or a separate problem.

Example

No code snippet is provided as the issue doesn't contain sufficient information about the code.

Notes

The provided error messages suggest a concurrency issue, but the root cause may be specific to the implementation of the API client or server. Further investigation is needed to determine the exact cause.

Recommendation

Apply workaround: Ensure that each tool_use block has a corresponding tool_result block in the next message to avoid concurrency issues, as this is the most likely cause of the error.

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING