Sponsored by

Let's say you have two unrelated tasks, adding a payment checkout and rewriting the search endpoint, and neither one depends on the other.

Run them together and you get both back in the time of the slower one instead of the sum of the two, which is the whole appeal.

Nearly everyone tries this by opening a second terminal in the same folder and hoping for the best, and it fails in ways more annoying than a merge conflict.

Git worktrees clear the file collisions in one command but leave your environment and your ports as broken as before.

So this edition covers the rest, from the ownership map you write first to the order you merge in at the end.

Partner with us

DevTools of the Week

Dispatch several coding agents at once, each in its own worktree, review the diffs, merge the wins. Works across Codex CLI, Gemini CLI, and Copilot CLI. MIT licensed.

The successor to Crystal, which was deprecated in February. Parallel session management plus visual editing of markdown, mockups, and code in one workspace.

Agent development environment for running fleets of parallel coding agents from desktop or mobile. Built by Stably (YC W22).

AI Open Source 101

The big open model everyone's posting about, Kimi K3, can build a whole game from a single sentence, and this pack shows you how, step by step.

Every build from the walkthrough, a physics roulette wheel, a GTA-style open world, an exploding interactive guitar, each with the exact prompt behind it.

One prompt in, a working website out, published to a link you can share the same day.

What goes wrong when you just try it

Open two terminals in the same project folder and start an agent in each.

Neither agent has done anything unreasonable, and A's work is gone either way.

Both run pnpm install and both write pnpm-lock.yaml. Whichever finishes second overwrites the first, with no warning.

Each one starts a dev server on port 3000, so the second crashes with EADDRINUSE, and the agent usually reads that as a bug in your code.

The port crash is the only one of the three that announces itself, and the other two stay quiet until merge time.

What a worktree is

Think of it as one repository with several checkouts. Same history

git worktree add ../myapp-search -b feat/search creates a second folder on your disk, checked out to a different branch, connected to the same repository.

It is not a clone, your commit history lives in one place and both folders read from it, so creating and deleting worktrees is nearly free.

What it does not do

It gives each agent its own files and nothing else.

The new folder gets your tracked files and no .env, no node_modules. Meanwhile both agents still default to port 3000 and the same database.

Filesystem conflicts are solved in one command. Everything else is the rest of this guide.

The setup

Prereqs

Your app must read config from env vars, including the port. If the port is hardcoded, stop here and fix that first.

Use pnpm if you can. It symlinks from a global store, so five worktrees do not mean five full copies of node_modules. npm and yarn will install the whole tree per worktree.

You need a way to give each agent its own database. Separate SQLite file, separate Postgres database, or branching if your provider supports it.

Step 1: map file ownership before you spawn anything

Write down which files each task is allowed to touch. 

Two agents editing src/types/index.ts at the same time produces a conflict that is tedious to resolve and often means rerunning one of them entirely.

Rules that hold up in practice: shared type files, schema files, and route registries get exactly one owner per run.

If two tasks both need them, they are not parallel tasks. Run them in sequence.

Step 2: create the worktrees

Keep them beside the repo.

Each directory is now a full checkout on its own branch. git worktree list shows you what is live.

Step 3: bootstrap the environment

The new folder has your source. Before an agent can run anything in it, you need dependencies installed and a config file that Git never copied.

Script it once:

Copy the .env, do not symlink it. If one agent edits a symlinked env file, every other agent inherits the change without knowing.

Step 4: give every service a deterministic port

The formula:

Ten slots per worktree covers your app, database, and whatever else boots. 

Deterministic beats scanning for free ports, because you can reason about which agent owns which port when something misbehaves.

When agent B hits EADDRINUSE on port 3000, it does not conclude the port is taken. 

It reads the network error as a code bug and starts rewriting application logic to fix a flaw that does not exist. 

You lose the task and the tokens.

Step 5: isolate stateful services too

Filesystem isolation does not cover your MCP servers, and the distinction that matters is whether the server holds state.

Anything stateless is safe to share across every worktree, because a pure function with no persistent storage behind it cannot be corrupted by two agents calling it at the same time.

A stateful server is where this breaks, since 2 agents writing through the same database MCP server into the same schema is the original collision problem moved one layer up the stack.

Give each worktree its own connection string and its own database

Step 6: run, then integrate in order

Point one agent at each directory with a bounded task and the file ownership list in its instructions.

For integration, use a lead-and-worker split, where the workers own bounded tasks inside their own worktrees and a single lead handles architecture decisions and does the merging.

Merge in dependency order and the task that touches shared types goes first.

If two agents both changed dependencies, reinstall in the remaining worktrees before merging or you will fight a lockfile conflict on top of everything else.

Step 7: clean up

Removing the worktree deletes its node_modules, its .env, and anything else untracked.

A working example

Setup: next.js app / Postgres / two tasks: add Stripe checkout, and rewrite the search endpoint.

The ownership map comes first, giving checkout src/app/api/checkout/* and src/lib/stripe.ts, and search src/app/api/search/* and src/lib/query.ts.

Both need src/types/index.ts, so checkout gets it and search is told to write its types locally and merge them in later.

Two terminals, one agent per directory. 

Each prompt ends with its file list and a line that says: if a port is already in use, stop and report it, do not change application code.

Both finish. Merge checkout first because it owns the shared types file.

Search rebases onto the new types, resolves its own local additions, and goes in second, after which you tear both worktrees down.

Total conflicts if the ownership map held: zero.

If you skipped the map, you are hand-merging index.ts right now.

My Take

The part that stuck with me is the port collision. 

An agent hits EADDRINUSE, decides it's a bug, and starts rewriting your application logic to fix something that was never broken. 

It cannot tell a bad environment from bad code, so it guesses, and the guess looks reasonable enough that you might merge it.

That reframed the setup work for me. 

Copying env files and computing ports feels like overhead you can skip but It's the only thing standing between an agent and a confidently wrong refactor.

Scott Chacon's Grit, a full rewrite of Git in Rust built with agents, burned roughly 45 billion tokens across three tools.

The post-mortem is worth reading if you want to see this at scale.

Until next time,
Vaibhav 🤝🏻

If you read till here, you might find this interesting

# Partner 1

His Father Got Parkinson's. He Built Robots Instead.

Clint Brauer grew up on his family's Kansas farm. His dad sprayed the same chemicals every American farmer sprays. Years later: Parkinson's. Clint walked away from a tech career to build a different way. Today his company, Greenfield Robotics, runs a patented fleet of autonomous bots that slice weeds with centimeter precision, day or night, herbicide-free. 

Greenfield is now opening shares to everyday investors under Reg A+. Reserve during Test the Waters and you lock in a 5% bonus that can grow to 20% the week the round goes live. The US has 250 million acres at stake.

Greenfield Robotics is Testing The Waters under tier 2 of Regulation A. No money or other consideration is being solicited, and if sent in response will not be accepted. No offer to buy the securities can be accepted and no part of the purchase price can be received until the offering statement filed by the company with the SEC has been qualified by the SEC. Any such offer may be withdrawn or revoked, without obligation or commitment of any kind, at any time before notice of acceptance given after the date of qualification. An indication of interest involves no obligation or commitment of any kind. “Reserving” shares is simply an indication of interest. There is no binding commitment for investors that reserve shares in this manner to ultimately invest and purchase the shares reserved of the company, or to purchase any shares of the company whatsoever.

# Partner 2

Think You Know What AI Does Next?

Which model leads the next benchmark? Which AI lab ships the next major breakthrough?

Kalshi lets you trade on real-world AI and technology events as the industry moves. If you follow launches, model updates, and benchmarks closely, put that knowledge to work.

Bonus credit varies from $15 to $500. Terms apply.

Reply

Avatar

or to participate

Keep Reading