Git worktree
Definition
An extra working directory attached to the same Git repository, with its own branch checked out, created with `git worktree add`.
In more detail
Worktrees let several coding agents work in parallel on separate branches without overwriting each other's files, and without cloning the repository again. For example, git worktree add -b fix-login ../app-fix-login creates a new branch in a sibling folder.
All worktrees share one .git object store, so creating one is fast and uses little disk. Each has its own checked-out files, so an agent running tests in one folder does not see half-finished edits from another. git worktree list shows them all and git worktree remove ../app-fix-login deletes one when its branch is merged.
Two worktrees cannot check out the same branch at once. Untracked files such as .env and installed dependencies are not copied, so each new worktree needs its own install step.
Related terms
Dev container
A container defined by a devcontainer.json file that gives a project a reproducible environment, often used to sandbox agents.
Headless mode
Running a coding agent non-interactively from a script or CI job, passing the task as an argument and reading the result from output.
Multi-agent system
An application in which several agents, often with different roles, tools or instructions, cooperate or hand work to each other.
Sandbox
An isolated environment that limits what an agent or its code can read, write or reach on the network, so any mistakes stay contained.
Subagent
A separate agent instance with its own context window, launched by a main agent to handle a focused task and report back a short result.
Read more about Git worktree
- Refactor in parallel with git worktrees and two agents
Use git worktrees to run Claude Code and Codex in parallel on the same refactor from one written plan, compare tests, diff size and readability, then merge one.
- AI-assisted coding
Working with coding agents: tasks, instruction files, review and verification.
- Subagents in Claude Code: delegate without losing control
Define Claude Code subagents with their own tools, model and permissions, keep noisy work out of your main context, and avoid conflicts in parallel runs.
- Git commands for working with coding agents
Checkpoint before an agent runs, see what it changed, restore files, stash, run agents in worktrees, bisect and undo a bad commit.