swarm
Skill0 starsChanged 5 days agoMITView on GitHub
Lead a team of cheap pi workers (OpenRouter models) on a large task that splits into parts: you plan, assign and judge, workers do the bulk in their own git worktrees, and a shared SQLite database is the only channel between you. Installs what it needs, checks the OpenRouter key and budget before anything starts, keeps credentials away from workers, audits what they ran, hands each worker only the skills its task needs, and merges only work that builds and passes tests. Use for big, splittable work (many files, many tests, a migration) where one strong agent doing it all costs too much. Run it only when the user asks for a swarm by name: it starts paid workers that spend on their own.
- Reads credentials
- Installs packages
92 other projects use a version of this.
Adopted by
Most recently taken up by
- sammyjoyce/prime-pstacktheir own version, first seen Nov 15, 2026
- pronvis/skillstheir own version, first seen Nov 15, 2026
- upamune/skillstheir own version, first seen Nov 15, 2026
- mdsmithaustin/pstacktheir own version, first seen Nov 15, 2026
- niksavis/basiclytheir own version, first seen Nov 8, 2026
- endqwerty/endstacktheir own version, first seen Nov 8, 2026
Used with
Projects with it also use poteto-help, make-bot-ui and 10 more.
Other files people use alongside this one.
Files found in the same public projects as a version of this one, more often than they turn up anywhere else. Each project counts once, large collections count for less, and this file's own repository is left out.
ianclearySkillpoteto-help
Guides users through pstack setup, /poteto-mode, and picking the skill, playbook, or principle for a task. Type /poteto-help with a question.
Also in 14 projects that use this
eryzerzSkillmake-bot-ui
Use when building a custom UI (page, dashboard, buttons) that should wake a Grok Bot over a webhook, when the user must provide a webhook sender key, or when exposing that UI on Tailscale.
Also in 19 projects that use this
ianclearySkillprinciple-explain-the-number
Apply before you trust, report, or act on a number you measured: a speedup, a regression, a throughput, a latency, or an eval result. Find what limits it, and rule out that it measured something other than the work you think.
Also in 27 projects that use this
bnemaSkillsetup-pstack
Configure which Pi models pstack uses per role. Detects available provider/model specs and writes pstack's user configuration. Use for /setup-pstack, "configure pstack models", or changing pstack model choices.
Also in 23 projects that use this
jaydubya818Skillprinciple-attack-the-premise
Apply when repeated fixes fail and a shared assumption may be wrong.
Also in 31 projects that use this
jaydubya818Skillpoteto-mode
Use when non-trivial work should follow the smallest rigorous Jstack workflow.
Also in 27 projects that use this
- +5 more from jaydubya818
Other versions92 projects use a version of this.
Word for word · 0
None found.
Edited · 0
None found.
Wrote their own version · 92
- backnotprop/pstack★ 3.8ksame name
- langchain-ai/langchain-skills★ 1.3ksame name
- moeru-ai/xsai★ 667same name
- zaxbysauce/opencode-swarm★ 519same name
- ZaxbyHub/opencode-swarm★ 518same name
- guaardvark/guaardvark★ 306same name
- iha2/superlite★ 249same name
- apple-ouyang/book-to-skill★ 148same name
- jtaroreh/agystack★ 128same name
- uzairansaruzi/p3-stack★ 126same name
82 more not listed
How matches are found. Word for word: the exact same text. Edited: shares passages with this file (“99% same” means 99% of its five-word phrases also appear here; 10% or more counts). Their own version: similar meaning, or, weakest, the same name. We can’t tell which project had it first. Projects are counted among the 200 most-starred candidates, and mentions are links to the repository we found, up to 50 per site, so both counts are a floor.
In this repository2 other files it gives its agents.
- AGENTS.mdAGENTS.md
- skills/swarm/workers/AGENTS.mdAGENTS.md
The file
We split this skill into the rules it gives an agent
9 rules. 0 are common, 6 are distinctive, and 3 are very specific to this project.
0
Common
Most of the 88 edited versions we read keep these.
6
Distinctive
This author's own choices. Worth a look.
3
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Very specific: line 22
Start each command with SW=~/.swarm.
- Distinctive: line 46
Ask the user before any command that needs a password.
- Distinctive: line 95
Never print or echo the key yourself.
- Very specific: line 118
Read enough of the repo to split the goal into tasks a worker can finish and test alone.
- Distinctive: line 152
Create it from the target repo:
- Distinctive: line 194
Start 2 or 3 workers. Check their first landed work before you start more: a bad plan multiplies with every worker you add.
- Very specific: line 218
Read notes and landed. Answer questions tagged @lead.
- Distinctive: line 252
A spec is the plan: When the repo has a spec or acceptance criteria for the work, or the work is big enough to write one first, make each …
- Distinctive: line 258
Check that two worktrees can run the same test file at once before you scale.
“Common” is measured: kept by at least 6 in 10 of the 88 edited versions of this file we could read. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
Swarm
You are the lead. You plan, assign and judge; cheap pi workers do the bulk of the work. You never hand off judgment: what gets merged is your call.
<skill> below is the absolute path of the folder holding this file. Write it
out in full: the commands run from the target repo, not from here. $SW is the
swarm's workspace (~/.swarm unless you choose another; pass it to the script
as --dir): it holds the database, logs, pid files and worker worktrees.
Start each command with SW=~/.swarm; (or your choice): a new shell does not
keep the variable.
Most steps are plain commands, so a failure shows its reason and you can adapt.
scripts/swarm.mjs holds only the rules that guard money, credentials and
safety (the key and budget check, which skills a worker may get, the worker's
environment and launch, the audit), because those are tested and must not
drift. Use it for those; never hand-run what it covers.
0. Where to run, and what it needs
Workers run shell commands on this machine with no sandbox around them. Their environment is stripped of credentials and you audit what they ran (step 5), but that is not isolation. Run a swarm in a disposable machine: a cloud session or a VM, not a laptop with your SSH keys and cloud logins. If you are on a personal machine, say so to the user and ask before you go on.
The user brings one thing: an OpenRouter API key with a credit limit. You install everything else.
Node.js first, since the script runs on it: node --version must be 22.18+
or 24.2+. If it is missing or older, install Node 24 LTS with the system's
package manager (brew install node@24 on macOS; on Debian or Ubuntu the
NodeSource repository, because the distro package is older), then check again.
Ask the user before any command that needs a password.
Hosts the setup and the run reach, for an environment with a network allowlist:
| Host | For |
openrouter.ai | the key check and every worker's model calls |
registry.npmjs.org | installing pi |
the OS package mirrors (e.g. archive.ubuntu.com, security.ubuntu.com; formulae.brew.sh and ghcr.io for Homebrew) | installing curl, git, sqlite3 |
deb.nodesource.com or nodejs.org | installing Node.js, only when it is missing |
Workers start with pi's startup network calls turned off, so while they work
they need openrouter.ai only, plus whatever the target repo's tests fetch.
The repo's own setup adds hosts: its git host (private submodules), its package
registry, whatever its tests download (a test database binary, browsers) and,
if it runs containers, their registries. Read them off the repo's setup docs or
CI config before you start; references/worktree-setup.md has a worked example.
1. Setup: check before anything costs money
Install what is missing, with the system's package manager (brew, apt-get,
dnf or apk; with sudo only when you are not root, and ask the user first
when it needs a password):
for t in curl git sqlite3 pi; do command -v $t >/dev/null && echo "ok $t" || echo "MISSING $t"; done- curl, git, sqlite3: the package of that name (
sqliteon brew, dnf and apk). - pi:
npm i -g @earendil-works/pi-coding-agent, thenpi --version.
Then the key and the budget, in one live call to OpenRouter:
node <skill>/scripts/swarm.mjs budgetThat call proves the key works wherever it comes from: the OPENROUTER_API_KEY
variable, or a secret the cloud environment's proxy adds (where the variable
may be absent or a dummy). It prints the spend and what is left. It fails when:
- the key is missing or wrong (401/403): tell the user to set
OPENROUTER_API_KEYor add the key as an environment secret. Stop. - OpenRouter cannot be reached: that is the network or an allowlist (step 0), not the key. Say so.
- the key has no credit limit: workers spend on their own, so a key without a limit has no ceiling. Ask the user to set one. Stop.
- less than $5 is left: start no workers and tell the user.
Never print or echo the key yourself.
Then the workspace, and what the machine can hold (every worker's builds and tests share it):
mkdir -p $SW/logs $SW/pids $SW/worktrees
nproc 2>/dev/null || sysctl -n hw.ncpu; free -g 2>/dev/null || vm_stat | head -2
sqlite3 $SW/swarm.db .tablesThen the database. If .tables prints nothing and an earlier session saved a dump,
import it first (references/persistence.md), because creating tables first would
clash with the dump. Then apply the schema; it only adds what is missing:
sqlite3 $SW/swarm.db < <skill>/assets/schema.sqlassets/schema.sql explains each table. Workers may add their own.
2. Plan
Read enough of the repo to split the goal into tasks a worker can finish and
test alone. Write them into subtasks (title, detail with the files and the
done check), post the plan in notes, and team-wide orders in announce. A
task too vague for you to check when it lands is too vague for a worker to do.
Shape the tasks so workers do not collide: one task, one set of files that builds and tests on its own. Two workers editing the same file is the most common way a parallel team loses work.
A big task becomes a tree: split it into children with parent_id, and let
a parent assume its children are done (a stub, an interface, a failing test the
child will make pass). Then many workers can build the parts at once instead of
waiting on each other. Workers may split further when a piece is too big.
3. Triage before you commit the team
Order the first workers to judge each top-level task's difficulty and post a
verdict in notes before they build. Put the team on what is doable first, and
set the rest aside, not away: once the doable part lands, there is no reason to
idle, so move workers onto what you set aside. Expect the early verdicts to be
too pessimistic; measured throughput beats a worker's guess.
4. Pick skills, then start small
node <skill>/scripts/swarm.mjs skillsIt lists the skills on this machine, each marked ✔ portable or ✘ with the reason.
Give a task the skills that fit it, usually none to two. Read
references/skills.md before the first pick: it says which skills help a worker
and which ones break the team (anything that commits, pushes or orchestrates).
Each worker works in its own git worktree on a branch named after its id. Create it from the target repo:
git -C <repo> worktree add -b w1 $SW/worktrees/w1 # existing branch: drop -bA new worktree holds only tracked files: no submodules, no dependencies, no
caches. Set it up now, in your own shell, so the worker never needs install
credentials or network. Workers also inherit your PATH: put the repo's Node
version first (its .nvmrc) before you spawn, or their builds and tests run on
the wrong one.
Set up your own checkout first, then reuse its caches so each worktree installs from disk, not the network. Run the repo's own install with its lockfile:
cd $SW/worktrees/w1 && git submodule update --init --depth 50 # if it has submodules
pnpm install --frozen-lockfile --prefer-offline # pnpm hard-links from its store: seconds
npm ci --prefer-offline # npm
uv sync --frozen # Python with uv
cargo fetch --locked # Rust (target/ is per worktree)Then run one quick test in the worktree yourself. If it downloads something
(a test database binary, a browser), copy or hard-link that cache from your
checkout into the worktree, or every worker downloads it again.
references/worktree-setup.md walks through a full example: a pnpm monorepo
with private submodules and an in-memory MongoDB, at 6 s per worker.
Then start the worker, with the skill folders swarm skills printed:
node <skill>/scripts/swarm.mjs spawn w1 --dir $SW --skill <folder of test-driven-development> \
"Judge the difficulty of subtasks #1-#4 and post a verdict for each in notes, then claim one you judged doable."The worker gets the team rules (workers/AGENTS.md), only the skills you
named, no MCP, and an environment with no credentials (the lead's tokens and
cloud keys stay out). Spawn checks the budget again, and refuses an id already
running, a missing worktree, or a skill that is not portable. The default model is deepseek/deepseek-v4.1-flash-1017 with
high reasoning; change it with --model / --thinking only when a task needs it.
Start 2 or 3 workers. Check their first landed work before you start more: a bad
plan multiplies with every worker you add. Scale to what the machine holds
(the cores and memory from step 1). When the team grows past a handful, form crews: a group of workers on
one area, with one of them as captain who posts the crew's plan in notes and
splits its work into subtasks. Name the crews and captains in assign.
5. Run the team
At each check-in:
node <skill>/scripts/swarm.mjs audit --dir $SW
node <skill>/scripts/swarm.mjs budget
for f in $SW/pids/*.pid; do id=$(basename $f .pid); kill -0 $(cat $f) 2>/dev/null && echo "running $id" || echo "ended $id"; done
sqlite3 $SW/swarm.db "SELECT status, count(*) FROM subtasks GROUP BY status"- Audit first.
auditscans every worker's log for attempts to gain privileges, read secrets, reach the network on their own, push, leave their worktree, or tamper with the team's tables or this script. Read each flag in context (the log is in$SW/logs/<id>.jsonl). A flag that is an attempt to get around a boundary, not a false match: stop all workers, tell the user what you saw, and do not restart until they have looked. A flag on one worker that is a mistake, not an attempt: stop that worker and do its task another way. - Read
notesandlanded. Answer questions tagged @lead. - Post the budget left and the next open work in
announce, so the team keeps going. Tell free workers not to wait for you: they take any open task. - Move workers off finished or stuck work onto open tasks.
- Workers tend to give up or overrate difficulty. Before you drop a task marked blocked, push back once with evidence (the file, the command, what to try). The same holds for you: do not stop the run because a task looks hard.
- A worker that ended with work left can be started again with the same id: its worktree and branch are kept, so skip the worktree step.
- Under $5 left: start nothing new and tell the user.
To stop a worker, end its whole process group (pi and the commands it started); its worktree and branch stay:
kill -TERM -- -$(cat $SW/pids/w3.pid) # one worker
for f in $SW/pids/*.pid; do kill -TERM -- -$(cat $f) 2>/dev/null; done # all6. Merge
For each landed row: check out the branch, read the diff, run the build and the
tests yourself. Merge only work that builds and passes; a worker's own "tests
pass" is a claim, not proof. Read the diff for changes outside the task too
(a test weakened, a check removed, a file the task did not name). Send rejected
work back with the reason as a new subtask. Only you merge and push.
Lead-only work: specs, the live app, the final review
Some work stays in your session, never in a worker: anything that needs Docker
or root, owns a resource there is one of per machine (a dev stack on fixed
ports), or needs subagents, which pi does not have. swarm skills refuses such
skills for workers.
- A spec is the plan. When the repo has a spec or acceptance criteria for the work, or the work is big enough to write one first, make each criterion a top-level subtask with its id in the title. The final review then checks the same list.
- Unit and integration tests run in the workers, as long as each run is isolated: random ports, temp directories, in-memory or per-run databases. Check that two worktrees can run the same test file at once before you scale.
- The live app is one per machine. A dev stack with fixed ports, fixed
container names or shared seed data cannot run once per worker, so workers
never start it. A worker whose task needs the running app marks the subtask
needs-liveand says what to check. You run those checks one at a time, after merging, on your own checkout. Restart the app there, reset its data between checks, and log each result inlanded. - Review once, at the end, on the merged branch. A review or attestation tied to a commit goes stale at the next merge, so run your review skill (or your own full review) after the last merge. Turn its findings into subtasks, let workers fix them, merge, and review the new head. Review notes stay uncommitted in your checkout, and workers never touch them.
7. Keep the state
The container may be temporary. After each merge, at milestones, and always
before you end: commit and push the merged work, and export the database
(references/persistence.md). A run can then restart from its last save.
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.

