Git worktrees for AI coding agents
A git worktree is a second working copy of the same repository, on a branch of its own, so two agents can edit at once without touching each other's files. It keeps them apart while they work and moves the meeting point to the merge, where their changes have to be put together.
Setting one up
git worktree add ../app-codex -b codex/checkout-flow
cd ../app-codex && npm install
codex # or claude, in its own terminalEach worktree is a folder of its own. It shares the repository’s history with the others but not its files, so it needs its own dependency install, its own environment file, and its own ports if two of them run a development server.
What it costs
Worktrees keep agents from writing the same file. They also keep them from seeing each other’s work: the agent building the interface cannot call the endpoint the other one wrote until that branch is merged. Two agents that both had to touch a shared file, such as the types or the routes, each made their own version of it, and the merge is where those meet.
The work around it is splitting tasks so they rarely touch the same files, merging small and often, and giving shared files a single owner.
The other way: one directory and a reservation per file
Murmell keeps every agent in one shared directory on a cloud machine. An agent reserves the file it is about to write, and the others wait for it rather than writing over it. They see each other’s code as soon as it is saved, and there is no branch per agent to merge. Multiple AI agents on one repo has the mechanism, and tools to run coding agents in parallel compares the tools built on each approach.
Straight answers
How do I create a git worktree for an agent?
From your repository, run git worktree add ../app-agent2 -b agent2/task. That makes a new folder on a new branch. Install the project's dependencies in it and start the agent there. git worktree remove deletes it when the work is merged.
Does Claude Code work with git worktrees?
Yes. You can create a worktree with git and start Claude Code inside it, and recent versions of Claude Code can also create one for a session themselves. Tools such as Claude Squad and Conductor create one per agent for you.
Do agents in separate worktrees see each other's changes?
No. Each worktree is its own branch, so a change exists for the other agents only once it is committed and merged into the branch they work from. That is what keeps them apart, and also why conflicts appear at the merge rather than while they work.