Skip to main content
Listen

Using Git Worktrees to Isolate Coding Agents

Instead of switching branches, you can create multiple working directories, each tied to a branch. This lets a coding agent work on one task while you (or another agent instance) work on another, avoiding stashing and accidental edits.

One caveat: I previously put worktrees under ./.worktree/feature-branch and added .worktree to .gitignore. That worked fine until coding agents started traversing to the Git root, at which point they discover other worktrees or the main project itself. Once that happens, isolation is gone.

The fix is simple: do not nest worktrees inside the repo directory. Instead, put them next to it.

cd ~/code/pipecat-core
git worktree add ../pipecat-new-stt feature/new-stt-v1
git worktree add ../pipecat-new-tts feature/new-tts-v1
cd ../pipecat-new-stt
codex
cd ../pipecat-new-tts
claude
# once the work is done, rm -rf
cd ~/code/pipecat-core
git worktree remove ../pipecat-new-stt
git worktree remove ../pipecat-new-tts

Each agent now sees only the files for its branch, and the main repo stays untouched. Branch isolation, enforced by the filesystem, turns out to be exactly what coding agents need.