Loading...
Loading...
By default, agents run one at a time. Agent A finishes, then Agent B starts. This is safe and simple, but slow. A 4-step workflow that takes 2 minutes per step finishes in 8 minutes sequentially. If those steps are independent, running them in parallel finishes in 2 minutes.
Sequential wins when steps have data dependencies — step B needs the output of step A. Parallel wins when steps are independent — writing tests, updating docs, and linting code can all happen at the same time because none depends on the others.
Claude Code's Agent tool supports a run_in_background parameter. When set to true, the agent spawns and returns immediately — you do not wait for its result. This is the foundation of parallel execution:
run_in_background: trueThe key insight: you do not poll or sleep. The system notifies you when each agent finishes. This is event-driven, not polling-driven.
Before parallelizing, you must determine which tasks are truly independent. Ask three questions about any pair of tasks:
A dependency graph helps. Draw tasks as nodes and dependencies as arrows. Tasks with no incoming arrows from other pending tasks can run in parallel.
Parallel agents produce separate outputs that must be combined. The merge strategy depends on the output type:
Design your workflow so agents write to separate files whenever possible. The additive pattern is the simplest and most reliable merge strategy.
The most common failure in parallel execution is two agents editing the same file simultaneously. This creates git merge conflicts or, worse, silent data corruption where one agent's changes overwrite another's.
git diff to detect overlapping changes and resolve manuallyPrevention is cheaper than resolution. Spend time upfront splitting work so agents operate on non-overlapping file sets.
More agents is not always better. Each concurrent agent consumes resources:
Start with 2-3 parallel agents. Measure the wall-clock speedup. Only add more if the bottleneck is execution time, not coordination.
Take a 4-step sequential workflow and parallelize it. The workflow: (1) write unit tests, (2) update API documentation, (3) run a linter, (4) generate a changelog entry. Steps 1-3 are independent. Step 4 depends on step 1 (it references test coverage).
You should see roughly a 3x speedup on the parallel portion. The sequential step 4 adds a fixed cost that cannot be parallelized — this is Amdahl's Law in practice.
Scale your agent swarms
The AI Brain Pro package includes a swarm orchestrator with automatic dependency analysis, parallel dispatch, and conflict-free result merging out of the box.
View Pricing →