Running one coding agent is straightforward. You describe a task, watch it work, and read the diff. The trouble starts when you open a second terminal, point another agent at the same folder, and expect twice the output.
Within a few minutes one agent reformats a file the other is editing. A test run picks up half-written code from the neighbouring task. A commit contains changes nobody asked for, and you spend the saved time untangling them.
The fix is isolation at three levels: files, runtime and scope. This guide walks through each, then covers the part that usually decides whether parallel work pays off, which is merging and review.

Photo by Oscar Chan on Pexels
Why a shared checkout fails
A working directory has one set of files, one index and one checked-out branch. Every process inside it sees the same state. People manage this by being aware of what they are doing, and agents have no such awareness of each other.
An agent reads a file, plans an edit and writes it back. If another process changed the file in between, the plan is based on content that no longer exists. Some tools detect this and re-read, but the second agent's intent can still be lost.
Shared state also corrupts feedback. An agent decides whether it succeeded by running tests, a type checker or a build. When those results include someone else's unfinished work, it may "fix" a failure that was never its own, widening the diff and confusing the history.
Branch switching makes it worse. One agent checking out another branch changes the ground under every other session at once.
What a git worktree gives you
A git worktree is an additional working directory attached to the same repository. Each one has its own checked-out files, index and HEAD, while sharing the object database and branches. Creating one is quick because history is not copied.
git fetch origin
git worktree add ../app-invoice-export -b agent/invoice-export origin/main
git worktree add ../app-rate-limits -b agent/rate-limits origin/main
git worktree list
Each agent now starts in its own directory, on its own branch, from a known commit. Git refuses by default to check out the same branch in two worktrees, which prevents the most obvious way of stepping on each other.
Place the directories outside the main checkout so that search tools, file watchers and test discovery do not walk into them. A sibling folder with a predictable name works well.
Know what is still shared. Branches, tags, remotes, the stash list and, by default, repository configuration and hooks are common to all worktrees. Tell agents not to use the stash, rewrite shared branches or change configuration.
Bootstrap each worktree the same way
A fresh worktree contains tracked files only. Installed dependencies, build caches, local environment files and generated code are missing. If an agent has to work that out for itself, it will improvise, and each session will improvise differently.
Write a setup script that is committed to the repository and run it for every new worktree. It should install dependencies from the lockfile, generate whatever the build needs, create a local environment file from a template and run a fast smoke test.
Package managers with a shared content store, such as pnpm, make repeated installs cheaper in disk and time. Avoid symlinking one dependency folder across worktrees, because an agent that upgrades a package would change it for everyone.
Never copy production credentials into these folders. Use development values with narrow permissions, since an agent that can read a file can also send it into a prompt or a log.
Finish the script by printing the branch, the base commit and the assigned ports. That output makes a good first block of context for the session.

Photo by Letícia Alvares on Pexels
Isolate the runtime, not just the files
Separate folders do not separate ports, databases, caches or queues. Two development servers will fight over the same port, and two test runs against one database will delete each other's fixtures.
Assign each worktree a small number, then derive everything from it. Worktree 2 might serve on port 3002, use a database called app_wt2 and prefix cache keys with wt2:. Keeping these values in environment variables follows the long-standing twelve-factor advice on configuration.
For services that run in containers, set a distinct project name per worktree. Docker Compose then creates separate containers, networks and volumes, provided the file does not hard-code container names or fixed host ports.
Look for the less obvious shared resources: temporary directories with fixed names, local object storage buckets, mail catchers, browser profiles used by end-to-end tests and third-party sandbox accounts. Anything with a single global name needs either a per-worktree suffix or a rule that only one task touches it.
Scope tasks so they cannot meet
Isolation stops live interference, but it does not stop two branches from changing the same lines. That is a planning problem, and it is cheapest to solve before any agent starts.
For each task, write down which directories it may change and which it must leave alone. Check the lists against each other. If two tasks need the same module, run them one after the other.
Some files attract every change: route tables, dependency manifests, lockfiles, translation catalogues, shared type definitions and database migration folders. Treat them as single-owner resources. Make the shared change first on the main branch, then start the parallel tasks from that commit.
Migrations deserve special care. Two branches that each add a migration may apply cleanly alone and conflict in ordering or meaning once combined. Allow only one schema-changing task at a time.
Good parallel candidates have a clear boundary and their own tests: a new export format, an isolated bug with a reproduction, documentation for a stable module, or coverage for code nobody is currently editing.
Find conflicts before they pile up
The longer branches live apart, the more expensive they become to combine. The practices described in Martin Fowler's article on continuous integration apply with more force when several writers produce code quickly.
You can test whether two branches would conflict without touching any working directory. Recent versions of git provide merge-tree, which performs the merge in memory and reports the result.
git merge-tree --write-tree --name-only agent/invoice-export agent/rate-limits \
&& echo "clean" || echo "needs attention"
Run it across every active pair on a schedule or when a task finishes. A reported conflict tells you to merge one branch soon and rebase the other while the context is still fresh.
A clean textual merge is not proof of compatibility. One branch can rename a function while another adds a new call to the old name in a different file. Only building and testing the combined result catches that.

Photo by Anna Shvets on Pexels
Merge one branch at a time
Choose an order. Merge the smallest or most foundational change first, run the full test suite on the main branch, then update the next branch against the new head and test again.
Resolve conflicts with a person involved. An agent asked to resolve them may keep one side and quietly drop the other, and the build can still pass if the lost behaviour had thin coverage. Ask for a short explanation of what each side intended before accepting a resolution.
Require every branch to arrive with the same evidence: a summary of the change, the commands run, their output and a list of files touched outside the declared scope. A file outside scope is not automatically wrong, but it should be explained.
Delete finished worktrees with git worktree remove. It refuses to delete a directory with uncommitted or untracked files unless forced, which is a useful moment to look before discarding anything. Drop the matching database and containers in the same cleanup script.
Set the limit by review capacity
It is easy to start six sessions. It is much harder to read six diffs carefully in an afternoon. When review falls behind, branches age, conflicts multiply and approvals become skims.
Start with two. Measure how long a finished branch waits before someone reads it, how often a merge needs rework and how many defects trace back to parallel tasks. Add a third only when those numbers stay healthy.
Keep each diff small enough to understand in one sitting. If a task keeps growing, stop it and split it, even though the agent could continue.
"Parallel agents multiply whatever process you already have. If review and merging are deliberate, you get more finished work. If they are not, you get more unfinished work, faster." - Dennis Traina, founder of 137Foundry
A short setup to try this week
Pick two tasks with no files in common. Create two worktrees from the same commit, run the bootstrap script in each and confirm both test suites pass before any agent edits anything.
Give each agent its scope in writing. When the first finishes, review and merge it, rebase the second, rerun the tests and note every point where isolation leaked. Those notes become the next version of your script.
Teams that want help turning this into a repeatable pipeline can look at our AI automation services, which cover agent workflows, guardrails and review gates. Where the blocker is an application that only runs on one machine with one database, our web development services can untangle the local environment first. You can also browse all 137Foundry services or start from the homepage.