Git worktrees for parallel AI agents
Git worktrees let you check out multiple branches at the same time in separate folders โ ideal for running several coding agents in parallel.
The problem without worktrees
Normally, a Git repository has only one branch checked out at a time. If you have a coding agent working on Feature A and want a second one to work on Feature B at the same time, they get in each other's way in the same folder โ switch the branch, and suddenly all the files change out from under the running agent.
What worktrees solve
A git worktree is an additional, standalone working folder that checks out a different branch of the same repository โ all worktrees share the same Git history and object database, but don't need a full second clone. Each folder has its own file state.
Why this is handy for AI agents
This lets each agent work in its own folder on its own branch, independently of the others โ no overwriting each other's files, clean separate diffs, and normal Git merges at the end. The official Claude Code documentation describes exactly this pattern as a way to run multiple Claude Code sessions in parallel for different tasks.
Basic commands
git worktree add <path> <branch> creates a new worktree, git worktree list shows all active ones, git worktree remove <path> removes one again.
EXAMPLE
git worktree add ../project-feature-a feature-a git worktree add ../project-feature-b feature-b # Now an agent can work on Feature A in ../project-feature-a, # while a second agent works on Feature B in ../project-feature-b at the same time.
QUICK QUIZ
What is the main advantage of Git worktrees for parallel coding agents?
SOURCES
- Git-Doku: git-worktree โ git-scm.com
- Claude Code Doku: Common Workflows (Worktrees) โ code.claude.com