You are running a coding agent on a feature branch. It takes eight minutes. You want to kick off a second agent on a different feature while the first one runs. So you `git stash`, switch branches, run the second agent, then switch back. You unstash, half your changes are gone, and the first agent's session is broken because it lost track of which file it was editing.
This is the wrong workflow. **Git worktrees** let you check out five branches from one repo into five working directories, all sharing the same `.git` database. Every agent gets its own working tree, its own index, its own uncommitted changes. They do not see each other. They do not stomp on each other. You run them in parallel terminals and merge the winners at the end.
Five minutes to set up. Half a day of agent throughput regained.
A worktree is a checked-out working directory tied to a specific branch. One repo, many worktrees:
~/code/myrepo/ ← main worktree, on `main`
~/code/myrepo/.worktrees/feat-a ← worktree on `feat/a`
~/code/myrepo/.worktrees/fix-b ← worktree on `fix/b`
~/code/myrepo/.worktrees/exp-c ← worktree on `exp/c`
All three secondary worktrees share the same `.git` directory, the same object store, the same refs. Branch updates in one worktree are visible to the others immediately. But each worktree has its own `index`, its own uncommitted edits, and its own agent process. That last point is the trick: each agent runs in its own filesystem, so file locks, build caches, and editor state never collide.
mkdir -p .worktrees
git worktree add .worktrees/feat-a -b feat/a
git worktree add .worktrees/fix-b -b fix/b
git worktree add .worktrees/exp-c -b exp/c
git worktree list
That is the whole install. No git plugins, no external tools, no daemon. Worktrees have been in core git since 2.5 (2015). If your `git --version` is below that, upgrade.
Open four terminals. In each, `cd` into a different worktree. Run your agent in each. They work in parallel, each on its own branch, none of them aware of the others.
cd ~/code/myrepo/.worktrees/feat-a && claude
cd ~/code/myrepo/.worktrees/fix-b && codex
cd ~/code/myrepo/.worktrees/exp-c && aider --model sonnet
When an agent finishes, review the diff in that worktree, push the branch, open a PR, and clean up:
cd ~/code/myrepo
git fetch .worktrees/feat-a feat/a # pull the branch ref
git worktree remove .worktrees/feat-a
git branch -d feat/a
git worktree prune # clean up any orphaned metadata
You can run as many worktrees as your disk and RAM will support. In practice, three to five parallel agents is the sweet spot before you start fighting for GPU tokens or hitting context-window limits on the review side.
.worktrees/
git worktree add --detach .worktrees/sandbox 8e2b7d4
Throwaway branches stay out of `git branch` until you decide to keep them. Use this for "let me see what the agent does without committing to the branch name yet" sessions.
git worktree list # should show all active worktrees
git -C .worktrees/feat-a status # should show clean tree on feat/a
git -C .worktrees/fix-b branch --show-current # should print 'fix/b'
If all three print what you expect, the setup is solid. Start your agents.
Worktrees are the only git-native way to run multiple agents on the same repo in parallel. There is no plugin, no `git-new-workdir` shim, no third-party tool that does it better — and there is a constant stream of "I tried to do this with `git stash` and it bit me" posts in every coding-agent Discord. Worktrees ship with git. The mental model is ten minutes. The time saved is a multiplier on every multi-agent session for the rest of the year.
If you run Claude Code, Codex, Aider, Cursor, or any of them — give each session its own worktree. You will not go back.
— *Mr. Technology*
*Worktrees have been in core git since 2.5 (July 2015). Tested June 2026 with `git 2.43+`, Claude Code 1.0, OpenAI Codex CLI 0.41, and Aider 0.71 on Linux and macOS. One branch per worktree is enforced by git, not by convention — `git worktree lock` exists for the rare case where you need to prevent a worktree from being removed while an agent is mid-edit. Reference: [git-worktree docs](https://git-scm.com/docs/git-worktree), Andrew Lock, [Working on two git branches at once with git worktree](https://andrewlock.net/working-on-two-git-branches-at-once-with-git-worktree/).*