Engineering

Parallel Agent Worktree Sweep

Run more agents, but keep their blast radiuses separate.

Use when

You have multiple independent coding tasks and the human bottleneck is orchestration, not implementation speed.

difficultyAdvanced
categoryEngineering
sourceAdapted from public Claude Code and agent-orchestration discussions

Cadence

When several independent repo improvements can run at once

Verification

Each agent branch has isolated scope, passing checks, a summary, and no conflicting files before integration review.

Structured loop spec

FieldValue
NameParallel Agent Worktree Sweep
CategoryEngineering
TriggerWhen several independent repo improvements can run at once
ObjectiveRun more agents, but keep their blast radiuses separate.
Allowed inputsRelevant files, source notes, logs, tests, screenshots, metrics, or task state for this loop
Allowed actionsSplit the work into independent tasks with non-overlapping files or explicit conflict boundaries.; Create separate branches or worktrees and give each agent its own goal, commands, budget, and done contract.; Require each agent to return diff summary, verification output, known risks, and next-step recommendation.; Review branches in priority order, checking for overlapping files, duplicated abstractions, and integration risks.; Merge only the branches with passing evidence and clear product value; park or discard the rest.
VerificationEach agent branch has isolated scope, passing checks, a summary, and no conflicting files before integration review.
Stop conditionStop when the verifier passes, the budget is exhausted, no progress is made, a blocker appears, or approval is required.
BudgetSet a time, turn, token, retry, file, or dollar cap before running the loop.
Approval boundaryHuman approval required before publishing, sending, deleting, spending, changing accounts, touching production, or making reputational/legal/financial commitments.
Safe outputPull request, patch, report, or evidence log
Works withClaude Code, OpenAI Codex, Cursor, Gemini CLI, any tool-using coding agent

Steps

  1. Split the work into independent tasks with non-overlapping files or explicit conflict boundaries.
  2. Create separate branches or worktrees and give each agent its own goal, commands, budget, and done contract.
  3. Require each agent to return diff summary, verification output, known risks, and next-step recommendation.
  4. Review branches in priority order, checking for overlapping files, duplicated abstractions, and integration risks.
  5. Merge only the branches with passing evidence and clear product value; park or discard the rest.

Prompt

Run the Parallel Agent Worktree Sweep loop. Split the repo work into independent tasks with non-overlapping scope, then create one branch or worktree per agent. Give each agent a goal, commands, budget, and done contract. Require diff summary, verification output, risks, and recommendation. Review branches for conflicts, duplicated abstractions, and integration risk before merging anything. Park or discard weak branches instead of forcing a messy merge.

Run in Claude Code

Paste this into Claude Code (or any tool-using agent) to run the loop bounded: one change per round, the same verification every round, durable state files, and explicit stop conditions.

Run the "Parallel Agent Worktree Sweep" loop from AI Loop Library (https://ailooplibrary.com/loops/parallel-agent-worktree-sweep/) as a bounded loop.
Goal: Run more agents, but keep their blast radiuses separate.
Rules: one change per round; run the same verification every round (Each agent branch has isolated scope, passing checks, a summary, and no conflicting files before integration review.); append each round to docs/loops/parallel-agent-worktree-sweep/progress.md and update docs/loops/parallel-agent-worktree-sweep/state.json; stop on verifier pass, 8 rounds, 3 consecutive failed verifications, no progress, a blocker, or anything needing human approval (money, production, outbound, deletion). Finish with a proof report: rounds used, changes made, verification output, remaining risk, and the next human decision.

Get the MCP server + agent pack

Tags

parallel agentsworktreesorchestrationcode review

Related loops

Browse all 68 loops