orchestrate-parallel-agents
Skill0 starsChanged 2 days agoMITView on GitHub
Run several coding agents on one repo at once without merge chaos: one git worktree per writer, briefs with owned and forbidden paths, a verifier per 2-4 workers, expiring leases for shared resources, managed headless runners that resume and rotate, and one serial merge queue. Use when the user wants to "parallelise", "run agents in parallel", "split this across workers", "swarm", set up runners or lanes, land several branches safely, report what runners cost, or debug a lane that was denied, built on the wrong base, or cannot land.
In this repository9 other files it gives its agents.
- AGENTS.mdAGENTS.md
- brainstormSkill
- gotchaSkill
- repo-healthSkill
- repo-onboardingSkill
- sdlcSkill
- sdlc-statusSkill
- session-handoffSkill
- taskSkill
The file
Show its rules and text
We split this skill into the rules it gives an agent
20 rules. About 0 are common, 8 are distinctive, and 12 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈8
Distinctive · estimate
This author's own choices. Worth a look.
12
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Distinctive: line 30
Check this first. Parallel work costs more tokens (each agent pays for its own context.
- Very specific: line 38
The pieces would touch the same files: If waves (below) cannot put them in separate lanes, run them in sequence.
- Distinctive: line 44
If any of these hold, say so in one line and route the work by its shape:
- Distinctive: line 70
Cost guidance: Start with 2-3 writers, not more.
- Very specific: line 80
Run bash scripts/close-tasks.sh waves --file TASKS.md when the work is in TASKS.md.
- Distinctive: line 99
Keep lanes short-lived: one task, landed within a sitting or a day.
- Very specific: line 174
If you must test whether a process is alive, never pgrep -f <name>: it matches its own command line and reports "still running" forever.
- Very specific: line 194
Every lease expires, so a crashed agent cannot hold one forever.
- Very specific: line 201
When a lane reports ready-for-review, the verifier for its group reads git diff <target>...lane/<name>, runs the lane's fast test command …
- Very specific: line 223
Do not pass
--test-cmdnarrower than the configured gate: Leave it off; the queue uses the project's gate. - Very specific: line 238
After each verdict run lanes.sh reviewed <name> <sha> [--verdict fix].
- Very specific: line 247
After a landing: bash scripts/lanes.sh remove <name> (it also accepts a lane that landed combined with other changes, when every path the …
- Distinctive: line 253
Commit hooks fire in lanes too.
- Very specific: line 296
No landing on the target except through merge-queue.sh (no git merge, no git reset, no hand-made update-ref).
- Distinctive: line 298
No automatic conflict resolution, anywhere.
- Distinctive: line 299
No database writes and no other project-side effect the project's rules reserve for a human.
- Very specific: line 301
No polling loops or unbracketed pgrep -f (section 7).
- Distinctive: line 302
No relaying of one agent's messages or denied actions to another agent.
- Very specific: line 303
No agent teams; no daemon.
- Very specific: line 306
No writes by lanes to shared bookkeeping (TASKS.md, decision logs): lanes report, you write.
≈ “Common” is an estimate: at least 1 in 5 of the 408,460 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
Orchestrate parallel agents
You are the orchestrator. You plan, brief, route and land. You do not do the technical work yourself: the moment you start editing code, nobody is watching the lanes, and your context fills with one lane's detail while the others wait.
Toolkit paths. Every toolkit script or template path cited here resolves, first hit wins, against: a repo-local copy installed by
setup.sh; else the plugin root (this skill's base directory two levels up,<base>/../..) when it holds that path; else~/.claude/brainstorm-toolkit/(the global shell install).
Project rules (which database, which ports, which paths are protected, what may never be
written) live in the project's CLAUDE.md / AGENTS.md. Read them first and quote the
relevant ones into every brief. This skill carries none of them.
1. When not to parallelise
Check this first. Parallel work costs more tokens (each agent pays for its own context; multi-agent work runs several times the cost of one agent) and moves the bottleneck to the one human who reviews everything. Do not parallelise when:
- One writer is enough. The change is small, or one linear agent finishes it in a sitting.
- The parts are not independent. Steps that share files, a schema, or a design decision still being made. Parallel agents make clashing implicit decisions; split only after the decision is written down.
- The pieces would touch the same files. If
waves(below) cannot put them in separate lanes, run them in sequence. - Nobody can review the output. Writers beyond what the human can review only grow a queue.
- It is read-only work. Research, review and measurement need no lanes, no worktrees and no queue.
If any of these hold, say so in one line and route the work by its shape:
| The work is | Run it as |
| one small, bounded change | /task |
| one plan whose steps build on each other | /sdlc on the plan: one writer, steps in order |
| a backlog nobody can review in parallel | /sdlc --queue, a row at a time |
| the same fixed steps every time | a script, no agent |
| research, review, measurement | background subagents in the shared folder |
| disjoint files, every shared decision written down | lanes (the rest of this skill) |
Dependent steps run serially. A step that needs the last step's result (its code, its decision, its migration number) goes to the same writer next, never to a second agent at the same time: that agent would wait or guess.
2. Roles
| Role | Who | Does |
| Orchestrator | you | splits work, writes briefs, opens lanes, reads results, runs the merge queue, escalates |
| Worker (writer) | one named agent per lane (@api, @ui-1) | edits only its owned paths, in its own worktree, commits on its lane branch |
| Verifier | one per 2-4 workers, read-only | reads each lane's diff, runs its tests, sends problems back to the writer that owns them |
| Read-only helper | any number | research, review, measurement in the shared folder |
Give every agent a name and use it everywhere: brief, board, branch (lane/<name>), runner.
Cost guidance. Start with 2-3 writers, not more. Workers run on Sonnet; the verifier
on a stronger model (Opus) because it is the independent check. Headless runners take their
model from models.runner in .claude/project.json (default sonnet, lowered by
models.cap); runner.sh start --model M overrides it for one runner. Idle workers cost nothing:
a background subagent that finished, or a headless runner between calls, holds no tokens.
Resolve each dispatch's model through skills/sdlc/templates/models.md when the project
sets models.*; the defaults above apply when it does not.
3. Plan the lanes
- Run
bash scripts/close-tasks.sh waves --file TASKS.mdwhen the work is inTASKS.md. It already groups open rows into parallel waves by their_lane:,_conflicts:and_after:tags, and warns when a row's files are dirty in another worktree. Use itsnowwave as the lane list; do not invent a second planner. For ad-hoc work, list the files each piece touches and group by disjoint file sets yourself. - For each lane write down owned paths (the only files it may change) and forbidden
paths (everything another lane owns, plus shared files only you edit:
TASKS.md, lock files, migrations, changelogs, version numbers). Overlap between two lanes' owned paths means they are one lane. Before splitting by directory, grep the tests for the strings the lanes change (labels, messages, fixture names). A pinned string or shared fixture makes two lanes one lane, or two lanes that must land together (merge-queue.sh land lane/a lane/b). List the tests that pin a lane's files as that lane's owned paths in its brief, or the writer cannot update them. - Confirm each item is still open before you brief it. A task list goes stale: in the first trial a lane was briefed on a row whose work had already landed, and the runner spent its whole budget rediscovering that. Spend one or two reads checking the code (does the function, route or test the row asks for already exist?). If it looks done, close or re-scope it yourself; if you cannot tell, say in the brief "if this is already done, prove it with the tests and change nothing".
- Keep lanes short-lived: one task, landed within a sitting or a day. A long-lived branch is where large conflicts grow.
- Cap writers at
pipeline.parallel.max_writersfrom.claude/project.json(default 2).
4. Pick the driver
| Work | Driver | Isolation |
| Writes code, fits one sitting | background subagent (Agent tool, run_in_background) | a lane from scripts/lanes.sh create, or isolation: "worktree" with the tip check below |
| Writes code, longer than a sitting or must outlive this session | managed headless runner, scripts/runner.sh | a lane from scripts/lanes.sh create |
| Read-only | background subagent, no isolation | shared folder |
Agent teams are out: they add live chatter and token cost, not isolation. So are hand-kept
runner terminals: use runner.sh.
A background subagent's permission prompts surface in your session; a headless runner has
nobody to ask. Read references/runners.md before starting the first runner of a session.
Prefer lanes.sh create for every writer. It bases the lane on the main worktree's HEAD
and prints that sha (base=). The harness's isolation: "worktree" picks its own base, and
in one measured case it handed a subagent a worktree 517 commits behind the current branch
tip, so everything the agent did was wasted. If you do use isolation: "worktree", put the
expected tip sha in the brief (the template has a slot) and make the agent's first step
git log --oneline -1, stopping with blocked unless it matches.
5. Open a lane
bash scripts/lanes.sh create <name> # branch lane/<name>, sibling worktree
# -> lane=<name> branch=lane/<name> base=<sha> path=<dir>A new worktree holds tracked files only, so create copies what .worktreeinclude lists
(never large or private data), then runs pipeline.parallel.lane_setup there (exit 3 if it
fails; the lane is kept). Read references/lanes-and-hooks.md before a project's first
lane: what to list, why dependency folders are built and never copied, and why these checkouts
run with project git hooks off. A test that needs a gitignored input only the main folder has
is a project fix: name it in your report and never count it against a lane.
Then take any lease the lane needs (section 8) and write its brief. All four scripts keep their
state in .claude/parallel/ of the main worktree; make sure the project gitignores it before
the first lane.
6. Brief every writer
Read references/brief-template.md now and fill it for each lane. The non-negotiables:
the expected base sha, owned paths, forbidden paths, the lane's test command, the
test-integrity rule, the leases it may take, the shell rules below,
the "cannot undo / protected resource" slot, and the 40-line final message
(a runner's is saved as its last-result.md; see skills/sdlc/templates/output-verbosity.md).
Narrowing a gate or ratchet needs a human
ruling before the lane starts. If the lane runs /sdlc, say that Stage 2's
separate implement agent is required: a delegated run that skips stages while reporting a
full run is a measured failure.
One command per Bash call. Permission rules such as Bash(uv run:*) match a single
command. A chained call (cd engine && uv sync | tail; uv run pytest) matches none of them,
so a headless runner is denied every time; in the first trial every Bash call was refused
this way and the run ended with nothing done. The brief therefore tells writers: no cd, no
&&, ;, pipes or redirection; run each tool from the worktree root with its own directory
flag (uv run --directory engine pytest ..., npm --prefix portal test); plain git status
works as is, since the worktree root is the cwd. Allowlists that fit this rule are in
references/runners.md.
Gate tiers. A lane runs pipeline.parallel.fast_test_command: targeted or sampled tests
that finish well under 10 minutes, because an agent's Bash call is killed at 10 minutes (a
full suite that ran longer was killed mid-baseline in the second trial). The full suite,
pipeline.parallel.gate_command, runs only in the merge queue. Without a fast command, name
the targeted tests for the lane's owned paths in the brief yourself.
7. Run, wait, and the board
- Dispatch all lanes of a wave in one message. Then wait for the background-task
notification. Never poll: no
sleeploops, nowatch, no re-reading an output file to see if it is done. - If you must test whether a process is alive, never
pgrep -f <name>: it matches its own command line and reports "still running" forever. Use the bracket trick:pgrep -f "[m]y-script.sh". - One shared board, no private relays. Each lane appends status lines to
.claude/parallel/board.md(<ts> @<name> <state> <one line>);stateisstarted,blocked,ready-for-review,landedorabandoned. Workers never message each other, and you never forward one agent's message to another: if lane A needs something from lane B, that is a planning error you fix by re-briefing, in writing, on the board.
8. Leases for what worktrees cannot isolate
A shared database, a fixed port, a cron window, the CPU-heavy full test suite:
bash scripts/lease.sh acquire db port-8080 --holder @api --ttl 900 # all or nothing
bash scripts/lease.sh renew db --holder @api
bash scripts/lease.sh release db port-8080 --holder @api
bash scripts/lease.sh list # who holds what, and until whenEvery lease expires, so a crashed agent cannot hold one forever. A refused acquire prints
the holder; the lane reports blocked on the board and you re-dispatch it later, rather than
it waiting in a loop. Put the resource names in the brief; the project's CLAUDE.md says which
resources exist.
9. Verify
When a lane reports ready-for-review, the verifier for its group reads git diff
<target>...lane/<name>, runs the lane's fast test command in the lane folder, and checks the
diff touches owned paths only: bash scripts/lanes.sh verify <name> --owned 'src/*' 'tests/x.py'
exits 1 and names every changed file outside the globs (* crosses /). Problems go back to the writer that owns those files, as a
new turn on its session (runner.sh resume, or a re-dispatched subagent), never fixed by the
verifier or by you. Keep one verifier per wave as a named runner resumed per lane
(references/runners.md). A lane that fails review twice escalates (section 13).
Read references/verifier-brief.md now and brief the verifier from it. It adds what a
green run cannot show: no test weakened, no code that detects the tests, and every cited
path:line opened. A miss on any of them is a fix.
Accepted variant: a one-off review agent per lane (Opus or Sonnet) instead of the
standing verifier. Fixes still resume the owning writer; never start a new *-fix
runner, so each lane's cost stays under one name.
10. Land through the merge queue
bash scripts/merge-queue.sh land lane/<name> [lane/<name2> ...] [--target main] [--verify-tests <slug>]Do not pass --test-cmd narrower than the configured gate. Leave it off; the queue uses
the project's gate. An override prints a WARNING and is logged (test_cmd_override). Several
branches in one call are rebased in order, gated once and landed all-or-none.
One landing at a time. It rebases the lane in a clean throwaway checkout, seeds it like a
lane, runs the full test command
(pipeline.parallel.gate_command, else test.unit, else refuses), and fast-forwards the
target only if it has not moved since (compare-and-swap). Run it with run_in_background: it
can outlast a 10-minute foreground call.
Uncommitted work in the target's folder blocks a landing only on a path the lane changes
(exit 6). Read references/merge-queue.md now the first time you land in a session: exit
codes, opt-in checks and the conflict path. On a conflict
it names the files; you hand them back to the owning lane (lanes.sh sync <name>,
then re-land) or decide yourself; nothing is ever auto-resolved.
After each verdict run lanes.sh reviewed <name> <sha> [--verdict fix]; fixes after an
accept need a short re-review. A lane adding a migration gets its number from
lanes.sh reserve-migration <name>.
Tell lanes to rebase early (bash scripts/lanes.sh sync <name>) after each wave landing,
before review, never after an accept. Mark a lane that must wait with
lanes.sh held <name> --until <YYYY-MM-DD|lane> (cleared by unheld; list shows it; it
does not block a landing). list also marks a lane STALE when its branch has not moved for
an hour and it is not held: read it when a lane is overdue, never poll.
After a landing: bash scripts/lanes.sh remove <name>
(it also accepts a lane that landed combined with other changes, when every path the lane
changed already matches the target; a lane whose content is missing is still refused).
11. Interaction with project commit hooks
Commit hooks fire in lanes too. The merge queue is the gate; a lane runs its fast tests. If a hook runs on lane commits, tell the human its cost per commit (exempting lanes
is the project's decision). Do not edit, disable or bypass a project hook (edit only per section
13), and never brief a lane to use --no-verify. Test one lane commit before a wave. Until the
project decides, keep lane commits few and say in the brief that a commit may take as long as
the hook. Read references/lanes-and-hooks.md first in a project with a commit hook.
12. Long runners: resume and rotate
runner.sh stores each runner's session_id and resumes it for the next task. When the last
turn's context passes the threshold (default 180k tokens, set 150k-250k with --rotate-at),
the next resume asks the old session for a hand-off note, starts a fresh session seeded with
it, and records the new id; resume --fresh does it now. Re-use a warm runner for the next
step of a series (resume --task <next>). To rotate by hand, or to write a hand-off for a subagent lane,
read references/handoff-note.md. Details and flags: references/runners.md.
Pass --task <id> (the TASKS row or plan step) on start and whenever a runner moves to new
work, so bash scripts/runner.sh report totals cost and denials by task. Never pipe
runner.sh (| tail): the pipe hides its exit code, so read verdict.json.
13. Escalation chain
Worker → orchestrator → advisor → human.
- The worker reports
blockedwith the reason (a refused lease, a denied tool, an ambiguous brief, a conflict, a worktree on the wrong base) and stops. It does not work around it. - You resolve what a re-brief, a re-plan or a lease can resolve.
- A question for the human first goes to an advisor pass (the
question-advisoragent, orskills/sdlc/templates/operator-gate.mdwhen the project enables it), which drops what the code or the decision log already answers. - What is left goes to the human, with the options and your recommendation. Every permission denial goes here unchanged: a runner's denied action is never handed to another agent to perform.
No laundering through the orchestrator. Protected paths are the project's hooks, its network guard, the runner allowlist, its commit gate and env files. When a runner was refused a change to one of them, you apply it only after the human approves that exact diff, and you record the approval in the project's decision log. A changed diff needs a new approval. Approval of the goal alone does not cover it.
14. What this skill must not do
- Lanes and workers never push; the orchestrator pushes only under the project's push rule. No force-push.
- No landing on the target except through
merge-queue.sh(nogit merge, nogit reset, no hand-madeupdate-ref);/sdlckeeps its no-git-writes rule inside lanes. - No automatic conflict resolution, anywhere.
- No database writes and no other project-side effect the project's rules reserve for a human; quote those rules into the brief and leave them to the human.
- No polling loops or unbracketed
pgrep -f(section 7). - No relaying of one agent's messages or denied actions to another agent.
- No agent teams; no daemon; nothing wired into
setup.shor hooks; no edits to the project's own hooks. The one exception to the hook rule: a hook edit is allowed only for a diff the human approved under section 13. - No writes by lanes to shared bookkeeping (
TASKS.md, decision logs): lanes report, you write.
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

