Skip to content

Orchestrating Multiple Parallel Agents

You have a two-week sprint with eight tickets. Working them sequentially means finishing five if you are lucky. Working them in parallel — with three Codex agents running on worktrees, two cloud tasks handling refactors, and you reviewing and merging results — means finishing all eight with time to spare. Multi-agent workflows are how teams multiply their output without multiplying their headcount.

  • A framework for decomposing work into parallelizable agent tasks
  • Concrete patterns for running agents across worktrees, cloud, and local threads simultaneously
  • Merge strategies that prevent conflicts when combining results from multiple agents
  • Guardrails that prevent runaway token consumption

Not all work parallelizes well. Use this decision tree:

Parallelize when:

  • Tasks modify different files or directories
  • Tasks are independent (no data dependency between them)
  • Each task can be verified independently (its own tests, its own lint check)

Serialize when:

  • Tasks modify the same files
  • Task B depends on the output of Task A
  • You need human judgment between steps

Best for: Feature implementation, bug fixes, and any work that needs Git isolation.

Open multiple Worktree threads in the App, each based on the same branch:

Thread 1: "Implement the /api/v2/orders endpoint with Zod validation"
Thread 2: "Add database indexes for the orders table queries"
Thread 3: "Write integration tests for the orders API using the test helpers in tests/utils"

Each runs in its own worktree. When all complete, sync each to the same feature branch using “Apply.”

When multiple agents complete work on the same project, you need a strategy for combining results:

Sync worktrees to your feature branch one at a time, resolving conflicts as they arise:

  1. Sync the most foundational change first (e.g., database migration)
  2. Sync the next dependent change (e.g., API implementation)
  3. Sync the least dependent change last (e.g., tests, docs)
  4. Run the full test suite after all syncs

Each agent creates its own branch. Open PRs from each branch to the feature branch. Use GitHub’s merge queue to combine them.

For the same task, run 3 attempts and pick the best:

Terminal window
codex cloud exec --env ENV_ID --attempts 3 "Optimize the database query in orders.ts"

Review all three solutions and choose the one with the best performance characteristics.

Multi-agent workflows multiply both productivity and cost. Set these guardrails:

  • Limit concurrent threads: 3-5 worktree threads is practical; more creates review bottleneck
  • Use GPT-5.1-Codex-Mini for simple tasks: Reserve GPT-5.3-Codex for the complex work
  • Monitor with /status: Check remaining limits before launching a batch of tasks
  • Set timeouts for exec: Long-running tasks may indicate the agent is stuck
  • File conflicts between agents: Two agents edited the same file. The “Apply” sync method attempts a patch; if it fails, use “Overwrite” for one and manually merge the other.
  • Context window exhaustion: Each thread has its own context window. If a thread gets slow, start a new one and reference the previous thread’s output.
  • Rate limit errors: Too many concurrent cloud tasks can hit your plan’s per-5-hour limit. Stagger submissions or prioritize.
  • Inconsistent results: Agents do not share context. If Agent B needs to know what Agent A did, either serialize them or include the relevant context in Agent B’s prompt.