Home→Glossary→Worktree

Worktree

Worktree

An isolated working copy of a repo, checked out on its own branch

✓ Runtime & Session
Talk to AY Automate ↗
Isolated by directoryOwn branchGit-nativeMergeable back

What is a Worktree

A worktree is a linked working directory that git can check out on its own branch, separate from the main checkout, without duplicating the whole repository's history. For an agent, this means it can be given its own worktree, work inside it freely, edit files and run commands, without any risk of colliding with a different agent or process working in the same repo elsewhere.

This is the mechanism that makes running several agents on the same codebase safe at the same time. Each one gets its own directory and its own branch. File edits in one worktree cannot corrupt or race against edits in another, because they are, at the filesystem level, genuinely different directories, even though they share the same underlying git history.

A worktree is not a permanent fixture, it exists for the life of the task. Once the work is committed and the branch is merged back into main, or the attempt is abandoned, the worktree is removed. Stale worktrees left behind after a task finishes are a common cleanup job in multi-agent setups.

How an agent stays isolated in its own worktree

The isolation is real, not just conventional: two worktrees are two different directories on disk, so a bug or a collision in one literally cannot touch files in the other.

AY Automate

Build your own agent skills, not just prompts.

We design, build, and ship the Claude Code skill libraries production teams actually run on.

Talk to AY Automate ↗

Key properties

✓A real, separate directory, not a copy of the whole repo
✓Lives on its own branch, isolated from main until merged
✓Removed once the work is committed and merged, or abandoned