3 AI Agents, 3 Worktrees, 1 Repository
How a solo developer uses git worktree to run three AI coding agents in parallel — each working on a separate feature, all sharing the same Git history.
The Challenge
You have three features to build for the Acme app: an authentication system, an analytics dashboard, and a public API. Each feature is independent, and you want to leverage AI coding agents to work on all three simultaneously.
The problem: AI agents need their own working directory. They read files, write files, and run commands. If two agents share the same checkout, they will overwrite each other's changes and produce conflicts. You need isolation — but you also want a single repository so merging is straightforward.
The Setup
Starting from the main worktree at ~/projects/acme, create three worktrees — one per feature:
# Create a worktree for each feature branch
git worktree add -b feat/auth ../acme-auth main
git worktree add -b feat/dashboard ../acme-dashboard main
git worktree add -b feat/api ../acme-api mainEach worktree is a full working directory with its own branch, but they all share the same .git object store. Install dependencies in each:
# Install dependencies in each worktree
(cd ../acme-auth && npm install) &
(cd ../acme-dashboard && npm install) &
(cd ../acme-api && npm install) &
waitRunning the Agents
Now point each AI agent at its own worktree:
Claude Code → acme-auth
Open a terminal, cd into the auth worktree, and start Claude Code. It will read, write, and test within this isolated directory.
cd ~/projects/acme-auth
claude "Implement JWT authentication with refresh tokens"Cursor → acme-dashboard
Open the dashboard worktree in Cursor. Its AI features work on the files in this directory only.
cursor ~/projects/acme-dashboardCodex → acme-api
Run Codex in the API worktree to scaffold the public REST endpoints.
cd ~/projects/acme-api
codex "Build a RESTful API with rate limiting and OpenAPI docs"The Result
After the agents finish, check the state of all worktrees:
$ git worktree list
~/projects/acme a1b2c3d [main]
~/projects/acme-auth d4e5f6a [feat/auth]
~/projects/acme-dashboard b7c8d9e [feat/dashboard]
~/projects/acme-api f0a1b2c [feat/api]Each agent committed its work to its own branch. Merge them into main one by one:
cd ~/projects/acme
git merge feat/auth
git merge feat/dashboard
git merge feat/api
# Clean up
git worktree remove ../acme-auth
git worktree remove ../acme-dashboard
git worktree remove ../acme-apiKey Takeaways
- Full isolation. Each AI agent has its own working directory, branch, and node_modules. No agent can interfere with another.
- No merge conflicts during development. Because each feature branch starts from the same commit on main, and agents work on separate parts of the codebase, conflicts are minimized.
- Shared Git history. All worktrees share the same object database. Commits made in one worktree are immediately visible to
git login another. - Disk efficient. Unlike cloning the repo three times, worktrees only duplicate the working files — the Git objects are stored once.