Parallel Development with Git Worktrees and AI Agents
Discover the power of Git Worktrees for running parallel development streams. Learn how tools like Claude, Cursor, Antigravity, and Kilo Code leverage this feature to boost your productivity.
Introduction
As AI coding assistants evolve from simple autocomplete into autonomous agents capable of performing complex tasks, the traditional single-threaded development workflow is becoming a bottleneck.
Imagine this: You have one AI agent fixing a bug in the auth module, another refactoring the
database schema, and you want to continue working on the frontend feature. In a standard Git
setup, this is a nightmare. You can't have multiple branches checked out in the same folder
simultaneously. Switching branches changes the files for everyone.
Enter Git Worktrees.
What are Git Worktrees?
Git Worktrees are a native feature of Git (available since version 2.5) that allow you to manage multiple working trees attached to the same repository.
Instead of cloning your repository multiple times to work on different branches (which wastes disk
space and requires fetching multiple times), worktrees allow you to check out different branches
into separate directories, all linked to the same main .git history.
Why it Matters for AI Development
For AI-assisted development, this is a game-changer. It enables Parallel Agent Execution:
- Isolation: Each AI agent runs in its own directory (worktree).
- No Conflicts: Updates to file A in Worktree 1 don't touch file A in Worktree 2.
- Shared History: All commits go to the same repository immediately.
Under the Hood: How it Works
When you run git clone, you get a standard repository with a .git folder containing all your
history and a "working tree" (your current files).
When you create a worktree, Git doesn't clone the repo again. Instead, it creates a new directory
that points back to the original .git folder.
- Main Repo: Contains the object database (commits, trees, blobs).
- Worktree: A lightweight directory containing only the checked-out files and a small
.gitfile pointing to the main repo.
This means worktrees are instant to create and take up almost no extra disk space (beyond the size of the checked-out files).
cheat sheet: Managing Worktrees
Here are the essential commands you need to manage your parallel workflows.
1. Create a Worktree
To start a new feature in a separate folder:
# Syntax: git worktree add <path> <branch>
git worktree add ../feature-login feature/login-pageThis creates a folder named feature-login one level up from your current repo and checks out the
feature/login-page branch.
2. List Worktrees
To see all your active parallel sessions:
git worktree listOutput:
/Users/me/dev/my-app (main)
/Users/me/dev/feature-login (feature/login-page)
/Users/me/dev/bug-102 (fix/auth-bug)3. Merging
Merging works exactly the same as usual. Since all worktrees share the same repository database, you can merge a branch from any directory.
From your main folder:
# You are in /Users/me/dev/my-app (main)
git merge feature/login-page4. Remove a Worktree
When you're done with a task, simply remove the worktree. This deletes the directory but keeps the branch and commits safe in the repository.
git worktree remove ../feature-loginPro Tip: If you just delete the folder using
rm -rf, Git will get confused. Always usegit worktree removeor rungit worktree pruneto clean up stale entries.
Tool Integrations: Who Can Leverage This?
Modern AI coding tools have recognized the power of worktrees and are integrating them into their "Agent" workflows.
1. Claude Code
Parallel Coding Sessions
Claude Code officially recommends Git Worktrees for running parallel tasks. By analyzing your request, Claude can spin up a new terminal session, create a worktree for a specific feature branch, and execute changes there without interrupting your main coding flow.
2. Cursor
Parallel Agents
Cursor uses worktrees to parallelize its "Agent" mode. When you ask Cursor to "fix bugs in the payment service" while you work on the UI, it can spawn a background process in a separate worktree. This ensures that the AI's file modifications don't clash with your active editor state.
3. Antigravity (Google DeepMind)
Agent-First Architecture
Antigravity is built as an "agent-first" IDE. Its architecture is fundamentally designed to handle multiple concurrent tasks. By leveraging worktrees, Antigravity allows its agents to plan and execute multi-file refactors in the background. You might have three "Deep Learning" agents optimizing different parts of your system simultaneously, each consistently isolated.
4. Kilo Code
Agent Manager & Parallel Mode
Kilo Code's Agent Manager features a specific "Parallel Mode." This mode automatically spins up ephemeral worktrees for each assigned task. You can dispatch a "Review Agent," a "Test Agent," and a "Feature Agent" all at once. Kilo Code manages the lifecycle of these worktrees, cleaning them up once the PRs are created.
5. RooCode
Multi-Branch Workspaces
RooCode provides explicit support for managing worktrees directly from its interface, allowing you to treat different branches as separate, instantly accessible workspaces.
A Day in the Life: The Worktree Workflow
Here represents a mature "Agentic" workflow pattern:
- Triage: You start your day reviewing issues.
- Dispatch:
- You tell Kilo Code to "Fix issue #102" -> Spawns
worktree/fix-102. - You tell Claude to "Refactor the logging service" -> Spawns
worktree/refactor-logging.
- You tell Kilo Code to "Fix issue #102" -> Spawns
- Focus: You stay in your
mainworktree, building the new dashboard feature in Cursor. - Review:
- Kilo Code pings you: "PR created for #102."
- Claude pings you: "Refactor complete, running tests."
- Merge: You review the PRs from the agents and merge them into
main.
Moves development from "Single-Threaded" to "Multi-Process," with you as the orchestrator.
Ready to start? Check out the documentation for your favorite tool and try creating your first
worktree today: git worktree add ../my-feature-branch feature/my-new-feature