DEV Community

Cover image for Claude Code ran parallel tool calls in order, but nothing guarantees it
matsumotory
matsumotory

Posted on Originally published at aird.matsumoto-r.jp

Claude Code ran parallel tool calls in order, but nothing guarantees it

Summary

When several tool calls line up in a single response that an AI model returns through the API, the API documentation does not define the order in which they run. The order is decided by the program that receives the response and runs the tools. None of the four Claude Code documentation pages examined contains a statement that defines this order. For this reason, a call that uses the result of an earlier call is sent in the next response, after the AI agent checks that result.

On Claude Code version 2.1.221, five patterns were tried once each. Each pattern put calls including Edit or Bash in the same response. In all five, the result was the same as running the calls one at a time in the order they were listed. Even when a call that waits 3 seconds was listed first, the later call waited for the earlier call to finish. In the records the AI agent wrote about its past work as well, there were 4 cases where it put a call that uses an earlier result in the same response, and in none of them did the later call use a stale state.

Patterns that put only read-only tools together were not tried. The measured results are limited to the behavior on the version and combinations tried, and do not guarantee the order.

What you can take away

  • Who decides the execution order when a single response has several tool calls: the program that runs them, not the API
  • The results of trying five patterns that include Edit or Bash on Claude Code version 2.1.221, and the combinations that were not tried
  • A criterion for separating calls that may go in the same response from calls deferred to the next response
  • Why a rule scoped by the shape of an operation misses the combination of git commit and git push

Why dependent calls are deferred to the next response

A tool call that uses a result created by an earlier call is not put in the message the model returns at one time; it is sent in the next message after that result has been checked. A call that uses the result of an earlier call is referred to as a dependent call, and the assistant message the model returns at one time through the API is referred to as a single response. The model writes the inputs of all the calls in a single response before it sees the result of any of them. So, regardless of the order of execution, the input of a later call cannot contain a PR number or a commit hash created by an earlier call.

The order of execution is decided not by the API but by the program that receives the model's response and runs the tools. The Parallel tool use documentation has a statement that the calls in a response may be run concurrently, or one at a time in the order they appear. It also has a statement that the two may be combined. This program, which returns the results of running the tools to the model in the next request, is referred to as a harness. Claude Code is one harness.

The documentation published by Claude Code's provider also has no statement guaranteeing the order of execution on the four pages examined, which include the list of tools and the explanation of hooks. Because there is no statement guaranteeing the order, even if Claude Code changes the order depending on the version or the combination of tools, that does not contradict the documentation.

Deferring a dependent call to the next response lets the model write the input of the later call after seeing the result of the earlier one. In exchange, the number of times the model is called goes up by one.

Independent calls that may go in the same response

Whether to put tool calls in a single response is decided by whether the later call uses the earlier result. It is not decided by the shape of the operation. Independent calls, which do not use the results of other calls, may go in the same response. Dependent calls are deferred to the next response.

If the scope of a rule against putting calls in the same response is set by the shape of an operation, writing a file and then reading it, operations like git push, which use an earlier result without reading or writing a file, fall outside it. git push uses the commit that git commit created. If the scope is set by whether the later call uses the result of the earlier call, operations do not fall outside it even when their shape differs.

The Parallel tool use documentation also has a statement that independent read-only operations are usually safe to run concurrently. It also has a statement that, for tools with side effects, shared state, or ordering requirements, running them sequentially may be better. The following table shows how each combination of calls is handled.

Combination of calls Example Put in the same response?
Independent calls Reading several files, running several searches May be put together
Dependent calls Using the contents of a file just written, using a commit just made Not put together. Sent in the next response after checking the earlier result

What the documentation published by Claude Code's provider says about the order of execution

Of the documentation published by Claude Code's provider, the three pages examined have no statement defining whether the calls in a response the model returns at one time run concurrently or in order. The three pages are the list of tools, the list of environment variables, and the explanation of how Claude Code works. The full text of each page was searched for five terms: parallel, concurrent, sequential, in order, and one at a time.

With the PostToolUse hook, the user's script runs once per tool each time a tool call succeeds. With the PostToolBatch hook, the user's script runs only once, after all the calls in a single response have finished and before the model is called next. The hooks documentation describes how these two hooks behave, on the premise that parallel tool calls happen. The hooks documentation also has no statement of which combinations of tools are run concurrently. The statements in the four documents are shown in the following table.

Material Statement about the order of execution
List of tools No statement
List of environment variables No statement
Explanation of how it works No statement
Explanation of hooks When Claude makes parallel tool calls, PostToolUse hooks run concurrently, and the PostToolBatch hook runs only once after the whole set has finished. There is no statement of which combinations run concurrently

Five measurements on Claude Code version 2.1.221

In the five patterns tried on Claude Code version 2.1.221, the result was in every case the same as running the calls one at a time in the order they were listed. In the 3 patterns that put a call waiting 3 seconds first, the call listed later ran after waiting for the earlier call to finish. In all five, calls including at least one Edit or Bash were put in the same response the model returns at one time. Patterns that put only read-only tools together, such as Read with Read or Read with Grep, were not tried.

The tests were run on 2026-11-28, with Claude Code version 2.1.221 running on macOS and the claude-opus-5-5 model. Each response had 2 or 3 calls, and the files read and written were files made for the measurement. In the 2 patterns without a wait, Edit rewrote a value, and cat, Read, or both, listed after it in the same response, returned the value after the rewrite. The following table lists the 3 patterns that put a call waiting 3 seconds first.

Trial Calls put in one response Result
A call that reads was put after a Bash that waits 3 seconds and then writes The first Bash waits 3 seconds and writes v3. The second Bash's cat and the third call, a Read, read the same file cat and Read both returned v3
A Bash that writes was put after a Bash that waits 3 seconds and then reads The first Bash waits 3 seconds and then runs cat. The second Bash writes v4 cat returned v3. The second Bash's write came after the first Bash's read
A Bash that prints the time was put after a Bash that waits 3 seconds The first Bash prints the start time, waits 3 seconds, and prints the end time. The second Bash prints the time once The second Bash's time was about 0.13 seconds after the first Bash's end time

git commit and git push, which fell outside the scope of the rule

The AI agent wrote one rule into a memory file, where it records its working rules. The rule was not to put a call that writes a file and a command that reads that file in the same response. The AI agent set the scope of this rule by the shape of the operation, reading and writing a file. Both the change that wrote this rule and the change that widened its scope remain as commits in a personal repository. This repository records changes to the AI agent's memory files and rules documents.

In early October 2026, the AI agent was creating and updating a PR for a service under development at my own company. The AI agent put a call that edits the file for the PR body and a gh command that passes that file as the PR body in the same response. It arranged them this way 3 times, and all 3 times the PR got the content after the edit. After these 3 times, the AI agent wrote the rule into memory.

Later in the same work, after writing the rule, the AI agent put git commit and git push in the same response. git push uses the commit that git commit creates, but it does not have the shape of writing and reading a file, so it did not fall within the scope of the rule.

After that, in the same work, the AI agent widened the scope of the rule to all dependent calls, which use the result of an earlier call. The rewritten rule listed five steps: creating a commit, pushing to the remote, opening a PR, merging, and deploying. In these five steps, the next operation is sent after checking the result of the previous one. An example in which a rule went unapplied in a different scene because its scope was written in the shape of one scene is also covered in another article, Rules in CLAUDE.md that were extended with the scene of each failure went unapplied in a different scene.

Of the 4 times, the 3 in the PR work and the 1 with commit and push, the number of times a later call used a stale state from before the earlier call ran was 0. In all 4, the PR and the remote got the content after the earlier call, so the order problem did not show in the output of tests or checking commands. When the order is swapped, the content before the edit remains in records visible from outside, such as the PR body or a commit.

Materials I referred to


Originally published at The Future of Humans, AI, and the Web, a site where my research and development is recorded and analyzed by a human and an AI.

Top comments (0)