Why one folder is not enough
Giving one task to several coding agents at once is a good way to get a better fix, faster. But when they all work in the same checkout, they write over each other. A folder holds only one version of a file at a time: the last write wins, tests run halfway through another agent’s edit, and nobody can tell which change came from which agent. No agent does anything wrong. They are just sharing one folder.
The usual fix is a fresh clone for every agent. That stops the collisions, but now each agent clones the repo, installs packages and warms its build cache before it writes a single line. With many agents a day, most of their time goes to setup. And when they finish, you still have a pile of folders and no easy way to compare them.
The usual setup
What we’ll build
In this guide we’ll save the repo once, packages and all. Each agent gets its own branch, a copy of the repo that is ready the moment it’s made and that nobody else writes to. When the agents finish, you see exactly what each one changed and merge the one you trust.
What we’re building
By the end, you’ll have:
- Your repo saved once on a disk, packages and all.
- A fresh branch for every agent, ready at once, with nothing to install.
- Each agent’s work and test result saved as a commit on its own branch.
- A clear list of what each agent changed, so you can pick the right fix.
- Several tasks on the same files at once, merged without overwriting each other.
You’ll need a Skywake API key and Node. Set SKYWAKE_API_KEY, then install the SDK with npm i skywake.
Step 1
Save the repo once
Start from the repo as an agent needs it: code, tests and installed packages. Our example is a tiny shop with the login bug from the story. We ran npm install once, so its node_modules folder is already there.
shop/
- src/login.js# the bug lives here
- test/login.test.js# one test fails today
- node_modules/# installed once, saved with the code
- package.json
We’ll save it on a disk, which is a repository of files. Every disk starts with a branch called main. Each save is a commit, a version you can always go back to.
import { Skywake } from "skywake";
const sky = new Skywake();
const shop = sky.disk("shop");
await shop.upload("./shop", { message: "Shop, ready to test" });The whole folder is now on main, packages included. The .git folder is left out. The first write created the disk shop, so there was nothing to set up.
Step 2
Give each agent a branch
Now the three agents. Each gets a fork of main: a new branch that starts with exactly the same files. A fork copies nothing, so it’s ready right away, and a change on one fork never shows up on another.
const task = "Login fails when the email has capital letters.";
const tries = await Promise.all(
[1, 2, 3].map((n) => shop.fork(`try-${n}`)),
);You now have try-1, try-2 and try-3, each starting at the same commit as main.
Step 3
Let each agent work in its own folder
Agents are good at working in a normal folder, so we give them one. For each try we download its branch into a local folder, let the agent edit it, run the tests, and upload the folder back to the branch with the result in the message.
import { spawnSync } from "node:child_process";
import type { Disk } from "skywake";
async function runTry(branch: Disk, task: string) {
const dir = `./work/${branch.branch}`;
await branch.download(dir);
await yourAgent(dir, task);
const tests = spawnSync("npm", ["test"], { cwd: dir });
const passed = tests.status === 0;
await branch.upload(dir, {
message: passed ? "Tests pass" : "Tests fail",
});
return { branch, passed };
}
const results = await Promise.all(tries.map((t) => runTry(t, task)));yourAgent stands for your own coding agent: anything that takes a folder and a task and edits files. Each folder arrives with node_modules in place, so the tests run without an install. All three agents work at the same time, and main doesn’t change while they do.
Tip: put the test result in the commit
A commit message like “Tests pass” costs nothing and makes every branch easy to sort later. You can read it back with branch.log() without opening the files.
Step 4
See what each agent changed
Two of our agents say the tests pass. That isn’t enough to pick one. A diff lists the files a branch changed compared with another. Nothing changed main while the agents worked, so a diff against main shows only the agent’s own work.
for (const { branch, passed } of results) {
const changed = await branch.diff("main");
console.log(
branch.branch,
passed ? "pass" : "fail",
changed.map((c) => `${c.change} ${c.path}`),
);
}Here is what came back from our three tries:
The tests passed on try-2, but it didn’t fix the bug. It changed the test so the capital letters were gone. Only try-1 fixed the login code itself. The diff makes that plain in one line.
Step 5
Keep the best fix
Merge try-1 into main, then destroy all three tries. You don’t need them any more. If the merge hit a conflict, mergeInto would throw before any branch was destroyed.
await tries[0]!.mergeInto("main");
for (const t of tries) await t.destroy();main now has the fix, its tests pass, and it is the only branch left. The next agent you start will fork from the fixed code.
Step 6
Run different tasks side by side
So far every agent worked on the same bug. Most days they work on different tasks, and often in the same files. Let’s start three at once, all touching src/login.js, with the same runTry as before.
import { MergeConflict } from "skywake";
const jobs = [
{ name: "longer-sessions", task: "Keep people signed in 30 days." },
{ name: "trim-spaces", task: "Ignore spaces around the email." },
{ name: "ignore-case", task: "Saved emails may have capitals." },
];
const forks = await Promise.all(jobs.map((j) => shop.fork(j.name)));
await Promise.all(forks.map((f, i) => runTry(f, jobs[i]!.task)));
for (const fork of forks) {
try {
await fork.mergeInto("main");
console.log(fork.branch, "merged");
} catch (error) {
if (!(error instanceof MergeConflict)) throw error;
console.log(fork.branch, error.conflicts);
}
}A merge combines files line by line. Two agents can change the same file, and if they changed different lines, both changes land. When two agents change the same lines, the merge saves nothing and throws a MergeConflict that lists the file as a conflict, so no one’s work is quietly overwritten.
Into main · src/login.js
The first two tasks merged into the same file. The third rewrote the line that trim-spaces had just changed, so it was stopped. Its branch is still there, untouched. Fork again from the new main and let its agent try once more, with the other changes already in place.
Running it for real
The same code works for three agents or three hundred. A few things to know as you grow:
- Forks stay instant. A fork copies nothing, so it takes about 10 ms, even for a repo of 20,000 files.
- No setup per agent.
downloadwrites the files to the agent’s disk, packages included. There is no clone and no install. - Main stays clean. Agents write only to their own branches, so
mainchanges only when you merge. - Every try is kept until you delete it. You can open, diff and read any branch later, even after a long night of runs.
- It all stays yours. The repo and every agent’s branch live in your own bucket.