Short answer (November 2026): to run AI coding agents in parallel without conflicts, give every agent that might touch the same files its own git worktree: git worktree add ../app-auth -b auth-refactor opens a second branch of the same repository in its own folder, with shared history. Claude Code can now do this itself with claude --worktree <name>, and OpenAI’s ChatGPT desktop app runs Codex chats in optional worktrees. Each worktree needs its own dependencies, its untracked .env files and its own dev server port. Merge each branch through a normal pull request, and remove worktrees with git worktree remove when you’re done.
We make AgentVera, which appears below as one way to manage worktrees and undo agent turns; the git commands work everywhere.
What is a git worktree?
A git worktree opens a different branch of the same repository in a separate folder, at the same time. Each folder has its own working files, but the .git data is shared. A commit made in one worktree is visible from the others right away.
Compared with a clone:
| Worktree | Separate clone | |
|---|---|---|
| Disk usage | Small (history is shared) | The whole repository |
| Commit visibility | Immediate | Needs fetch/push |
| Same branch in two places | Blocked (safe) | Possible (risk of confusion) |
| Setup | One command | Clone and configure |
Basic commands
Create a worktree on a new branch:
git worktree add ../acme-web-auth -b auth-refactor
Open a worktree from an existing branch:
git worktree add ../acme-web-billing billing-v2
List, lock and remove worktrees:
git worktree list
git worktree lock ../acme-web-billing
git worktree remove ../acme-web-auth
git worktree prune
lock stops a worktree from being pruned or removed by accident, remove refuses to delete a worktree with uncommitted changes unless you add --force, and prune cleans up records of worktrees whose folders were deleted by hand.
One tree per agent
The rule for parallel agents is simple: give every agent at risk of conflicts its own worktree.
An example layout:
| Agent | Task | Worktree | Branch |
|---|---|---|---|
| Architect (Claude Code) | Auth restructuring | ../acme-web-auth | auth-refactor |
| Frontend (Gemini CLI) | Settings page | ../acme-web-settings | settings-ui |
| Tester (Codex) | Auth tests | ../acme-web-auth | auth-refactor |
Tester shares Architect’s worktree because it tests Architect’s change and works only under tests/. The frontend agent works on something else entirely, on its own branch.
What this buys you:
- Agents never see each other’s half-written files.
- Each piece of work merges through its own branch and pull request.
- Dropping a piece of work is as easy as deleting its branch.
For how to split the work itself, see parallel coding agents.
Worktrees built into the agents
Since this guide first came out in September 2026, the agents and their apps have taken over much of the setup.
Claude Code. claude --worktree feature-auth (or -w) creates a worktree under .claude/worktrees/feature-auth/ at the repository root, on a new branch named worktree-feature-auth, and starts the session in it. Without a name, Claude picks one. Useful details from Anthropic’s docs:
- New worktrees branch from the repository’s default branch; set
worktree.baseRefto"head"to branch from your current work instead. - A
.worktreeincludefile in the project root, in.gitignoresyntax, copies gitignored files such as.envor.env.localinto every worktree Claude Code creates. - When you exit, a clean worktree of an unnamed session is removed with its branch; if it has changes, Claude asks whether to keep it.
- Subagents can run in their own worktree with
isolation: worktreein their frontmatter. - Add
.claude/worktrees/to.gitignoreso the worktrees don’t show up as untracked files.
Codex. OpenAI’s ChatGPT desktop app runs several Codex chats at once, each optionally in its own git worktree, with Handoff to move a chat between the worktree and your checkout. With the Codex CLI on its own, create the worktree with git and start codex inside it.
Desktop apps. Most apps that run several agents now create a worktree per agent or task for you; we compare them in the best apps to run Claude Code and Codex in parallel. Such apps are often called an agentic development environment.
Whichever creates the worktree, the git rules below still apply.
Managing worktrees in AgentVera
You can manage worktrees from the command line, but it gets hard to follow as agents multiply. In AgentVera, the Worktrees tab in the right panel lets you:
- Create a worktree from a new or existing branch.
- See each worktree’s change count, how far ahead or behind the main branch it is, and its last commit.
- Start an agent directly in a worktree.
- Lock, prune, force-remove a worktree and delete its branch.
When you create a new agent you can also pick a worktree as its workspace, and the agent’s pane shows its branch in a small tag. Markdown files agents change in worktrees are listed in the Specs panel as plans and docs.
Keep every turn reversible
Worktrees separate agents from each other. But what if an agent heads the wrong way inside its own worktree?
The traditional answer is to commit often, but committing every agent step clutters history. AgentVera’s turns take another route:
- At the start of every turn, a snapshot of the working folder goes to a hidden git ref.
- Your branch, index and stash are untouched.
- The last 60 turns are kept per agent.
- From Turns in the pane’s Options menu, you see the files a turn changed.
- Undo this turn reverts that turn’s changes, and you can undo the undo too.
So you can let an agent try things freely: if you don’t like the result, you’re one click from the previous state.
Before you merge
Before bringing finished work from parallel branches into the main branch:
- Run the tests in each worktree.
- Review the diffs; automatic code review speeds this up.
- Tidy commit messages. AgentVera’s Git panel can write a message in your repo’s style from the staged diff with Claude Haiku.
- Push the branch and open a pull request; the GitHub card in the Git panel shows the current branch’s pull request or opens a new one.
Common mistakes
- Opening the same branch in two worktrees. Git won’t allow it, and that’s a safeguard.
- Leaving records of deleted folders. Clean them with
git worktree prune. - Forgetting node_modules. Each worktree needs its own dependencies installed.
- Forgetting untracked files.
.envand other gitignored files don’t appear in a new worktree; copy them, or list them in.worktreeincludefor Claude Code. - Treating agent turns as commits. Turns are for undo; still commit for lasting history.
A sample day: three agents, two branches
Let’s make this concrete with a working day.
Morning: setup
The main folder has main checked out. There are two jobs: an auth restructuring and a settings page. You open two worktrees:
git worktree add ../acme-web-auth -b auth-refactor
git worktree add ../acme-web-settings -b settings-ui
Install dependencies and copy the env file in each:
cd ../acme-web-auth && pnpm install && cp ../acme-web/.env .
cd ../acme-web-settings && pnpm install && cp ../acme-web/.env .
Architect and Tester start in the auth-refactor worktree; the frontend agent starts in settings-ui.
Midday: a turn goes wrong
While editing the settings page, the frontend agent also changes the styling of a shared component. That’s out of scope. In the Turns list you see the files the last turn changed, undo the turn and tell the agent not to touch the shared component. The branch history stays clean, because undoing isn’t a commit; it’s a return to the snapshot on the hidden ref.
Evening: merging
When the auth work is done, you run the tests, check the review and push the branch. If the settings page isn’t finished, its worktree stays open and the agent continues in the same folder the next day. When you quit and reopen the app, AgentVera brings Claude and Codex agents back to the same conversation from the CLI history.
Environment details to watch in worktrees
The most common snags with parallel worktrees are about the environment, not the code:
- Port clashes: if you run a dev server in two worktrees at once, don’t let both ask for the same port. Give them different ports through environment variables.
- Env files: files that aren’t in git, like
.env, don’t appear in a new worktree by themselves; copy them. - Database: if two branches carry different migrations, sharing one local database can cause trouble.
- Windows paths: deep
node_modulesfolders can hit the 260-character limit; setgit config --global core.longpaths trueand keep worktrees under a short root. More in coding agents on Windows.
AgentVera’s Ports panel shows listening ports and which agent started each, so you can track which worktree opened which server.
Copying an agent and forking the conversation
Sometimes you want to try the same problem two ways. When you copy an agent in AgentVera, its tool, account, model, effort, role, group and worktree are copied exactly, and you can fork the conversation history too (--fork-session for Claude, fork for Codex).
Combined with worktrees, that gives you a strong experiment setup: run two agents forked from the same conversation in two worktrees, compare the results and merge the branch you like. Deleting the other branch cleans up the experiment without a trace.
Checklist
- Does every agent at risk of conflicts have its own worktree?
- Are dependencies installed and env files copied in each worktree?
- Does each dev server have its own port?
- Do the agents’ roles say which folders they work in?
- Were tests and a review done before merging?
- Did you remove finished worktrees and run
git worktree prune?
Wrapping up
Git worktrees keep agents physically apart, and turns keep each agent’s own changes reversible. Claude Code and the agent apps now create worktrees for you, but the basics are the same: one tree per agent, its own environment, and a pull request to bring the work home.
AgentVera puts worktrees, turns and the Git panel in one window. Read it alongside parallel coding agents, or start on the free plan.