How do I set up two coding agents to fix separate bugs in the same repo without their half-finished edits breaking each other’s tests, and what should manage the worktrees?

Run coding agents in parallel git worktrees

Give each agent its own git worktree on a new branch, then copy in your .env files, install dependencies and give each worktree its own port and database, or their test runs can still collide. For one maker’s agent alone, claude --worktree or codex --worktree makes the worktree. To run Claude Code and Codex side by side, pick Emdash Classic or Pane, which make a worktree for each agent, run your setup script in it and give it 10 ports, on Mac, Windows and Linux. Conductor does the same on a Mac, and in a terminal Worktrunk runs your setup hook and gives each branch its own port. Trek merges only into a project folder with no uncommitted changes, undoes a merge that conflicts and never deletes a worktree on its own. Orca, Parallel Code, T3 Code and Traycer also make a worktree for each agent.

Set up two coding agents in separate git worktrees

From your repository, make one worktree per agent, each on a new branch that starts from main.

git worktree add ../myapp-login -b fix-login main
git worktree add ../myapp-search -b fix-search main

The last word, main, is where each new branch starts. Leave it out and the branch starts from the commit you’re on now, which may be half-done work on another branch.

A new worktree holds only committed files. Open a terminal for each agent, copy your .env in, install dependencies, then start the agent in its own folder.

# terminal 1
cp .env ../myapp-login/
cd ../myapp-login && npm ci && claude

# terminal 2
cp .env ../myapp-search/
cd ../myapp-search && npm ci && codex

Each agent now edits files and runs tests in its own folder. While one is halfway through a change, the other’s test run doesn’t see it. This works with any agent, because each one only sees a folder. If both start a dev server or use a local database, give each worktree its own, as the fixes below show.

To see your worktrees, and to delete one once its branch is merged:

git worktree list
git worktree remove ../myapp-login
git branch -d fix-login

What a git worktree is

A worktree is a second checkout of the same repository, in its own folder and on its own branch. All of them share one .git, so a commit made in one worktree can be merged from any other at once, with no push or fetch.

Edits, staged changes, untracked files and build output stay in the folder they were made in. Put each agent in its own worktree and one agent’s half-done edits can’t reach the other’s files.

What breaks, and the fix for each

Your .env files are missing

A new worktree holds only what is committed. Ignored files such as .env and .env.local are never committed, so the app in the new folder starts without its settings. Copy them in by hand.

cp .env .env.local ../myapp-login/

Claude Code, the Codex app, Conductor and Orca can copy them for you from a .worktreeinclude file in your project root, written like .gitignore.

# .worktreeinclude
.env
.env.local

Dependencies aren’t installed

node_modules, a Python virtual environment and build output live in each folder, so a new worktree has none of them. Run your install step in every new worktree before the agent runs tests.

cd ../myapp-login
npm ci          # or pnpm install, or uv sync

Two dev servers want the same port

Both worktrees start the same app, so both ask for the same port. Give each one its own.

npx vite --port 5174 --strictPort
PORT=4000 npx next dev

Vite moves to the next free port by itself unless you pass --strictPort, so the address the agent opens may not be the one you expect. Next.js reads PORT or -p, and says PORT can’t be set in .env.

Git won’t check out one branch twice

If a branch is checked out in one worktree, git worktree add refuses to check it out in another. Give each agent a new branch with -b.

Worktrees inside the repository show up as changes

Claude Code keeps its worktrees in .claude/worktrees/, inside your repository. Its docs say to add that folder to .gitignore, so the worktrees don’t show as untracked files in your main checkout. Do the same for any worktree folder you keep inside the repository.

echo ".claude/worktrees/" >> .gitignore

Some things are still shared

A worktree separates files only. A local database, a Docker container or a cache outside the folder is the same for every agent. Point each worktree at its own copy when the agents change data.

Docker Compose keeps environments apart by project name, and puts that name in front of every container’s name. By default the name comes from the folder, so worktrees in differently named folders already get their own containers. A top-level name: in your compose file wins over the folder, and then every worktree shares one set. COMPOSE_PROJECT_NAME wins over name:, and Compose reads it from .env, so set it in each worktree’s own copy of that file, not a link to yours.

echo "COMPOSE_PROJECT_NAME=myapp-login" >> ../myapp-login/.env
cd ../myapp-login
docker compose up -d

Two projects still can’t publish the same port on your machine, so give each worktree its own ports there too.

Give each worktree its own database too. If your app reads .env.local, as Next.js does, change the name in each worktree’s copy, since a copied file still names your main checkout’s database. Then create that database and run your migrations in the worktree.

# .env.local in ../myapp-login
DATABASE_URL=postgres://localhost:5432/myapp_login
createdb myapp_login

Next.js skips .env.local when NODE_ENV is test and reads .env.test.local, so put the test database’s name there.

The repository itself is shared too, which matters in a dev container. A worktree’s .git is a file, not a folder. It points back into the main repository’s .git, by default as an absolute path on your machine. A dev container that mounts only the worktree folder can’t reach that path, so git commands fail inside it. Mount the main repository into the container too, at the same path.

Cleanup refuses

git worktree remove only removes a clean worktree, with no changes and no untracked files. That protects work you haven’t committed. If you deleted a folder by hand, git worktree prune clears what git still remembers about it.

Merging is still your job

Each agent leaves a branch. Worktrees keep files apart. Two agents that change the same function in different ways can each pass their own tests and still clash once merged. Give the agents bugs in different parts of the code, merge one branch at a time, and run the tests again after each merge.

To see a clash before you merge, git merge-tree merges the two branches without touching any checkout or the index. It exits with status 1 when they conflict, and lists the conflicted files.

git merge-tree --write-tree fix-login fix-search

Claude Code worktrees, the --worktree flag

claude --worktree fix-login
  • This starts Claude Code in .claude/worktrees/fix-login at your repository’s root, on a new branch named worktree-fix-login. -w is the short form. Without a name, Claude Code makes one up.
  • New worktrees branch from your repository’s default branch on the remote. To branch from where you are now, set worktree.baseRef to "head" in your settings. It can’t be set to a branch name.
  • It copies the ignored files that a .worktreeinclude file names, and only those. That applies to --worktree, to sub-agent worktrees and to parallel sessions in the Claude desktop app.
  • While a session runs in its worktree, Claude Code blocks edits to files in your main checkout, unless you started it with --tmux.
  • It doesn’t install anything. Ask Claude to install dependencies, or run your setup yourself in the worktree.
{
  "worktree": {
    "baseRef": "head"
  }
}

When you exit an interactive session, Claude Code checks the worktree. If it’s clean, it removes the worktree and its branch by itself, unless you named the session, in which case it asks first. If it has changes or new commits, it asks whether to keep or remove it. Your ignored files don’t count as changes, so a copied .env can go with it. Runs with -p aren’t cleaned up at all, so remove those with git worktree remove.

To run several Claude Code sessions without a terminal for each, start them in the background. Before a background session edits files, Claude Code moves it into a worktree of its own under .claude/worktrees/, so each session writes only to its own folder. claude agents opens the list of them.

claude --bg "fix the login redirect"
claude --bg "fix the search ranking bug"

In the Claude desktop app, turn on Worktree before you start a session. It is off by default.

Codex worktrees

In the terminal, codex --worktree starts Codex in a new managed git worktree. It works for new interactive sessions, codex fork and codex exec, and needs local execution. Inside a session, /worktree starts or continues the chat in one.

codex --worktree
codex exec --worktree "fix the search ranking bug"

Since 9 July 2026, Codex’s desktop app is part of the ChatGPT desktop app. Pick Worktree under the composer and choose the branch to start from.

  • Codex keeps its worktrees in $CODEX_HOME/worktrees, on a detached HEAD rather than a branch. Create branch here, in the chat header, turns one into a branch.
  • Setup scripts run when Codex makes a worktree for a new chat, with a different script per OS if you need one. They live in the .codex folder at your project root.
  • It copies ignored files that .worktreeinclude names. The docs say this applies to worktrees the desktop app manages, not to ones you make yourself from the command line.
  • By default, Codex deletes all but the 15 most recent worktrees it manages, and deletes one when you archive its chat. It skips pinned chats and chats still running, and saves a snapshot of each worktree before it deletes it, so you can restore it later. You can change the limit or turn deletion off in settings.

Git worktree managers for parallel coding agents

These run in your terminal and work with any agent you start in the worktree.

Worktrunk

Worktrunk is a CLI made for running agents in parallel. One command makes the branch and the worktree and starts the agent. wt list shows every worktree with its status. wt merge squashes, rebases, merges and removes the worktree in one go. Hooks in .config/wt.toml can run your install step when a worktree is made, and a hash_port filter gives each branch its own steady port. wt step copy-ignored copies ignored files such as .env. By default it copies every ignored file, node_modules included, unless a .worktreeinclude narrows it. New branches start from the default branch unless you pass --base. It is MIT or Apache-2.0, and installs with Homebrew, Cargo or, on Windows, winget, where the command is git-wt.

brew install worktrunk && wt config shell install
wt switch -c -x claude fix-login
wt switch -c -x codex fix-search

agent-worktree

agent-worktree wraps a whole agent run. wt run -i -- claude makes a worktree, starts the agent in it, and asks what to do when the agent exits. It cleans up a worktree with no changes, offers to merge one with commits, and offers to reopen the agent or keep the worktree when work is left uncommitted. Its config can copy files such as .env into new worktrees and run hooks such as pnpm install after one is made. It installs from npm, keeps worktrees in ~/.agent-worktree, and is MIT. Its command is also called wt, like Worktrunk’s.

npm install -g agent-worktree
wt run fix-login -i -- claude

gwq

gwq makes and finds worktrees with a fuzzy finder, across all your repositories. gwq status --watch shows every worktree’s changes and activity at once. Apache-2.0, installed with Homebrew or Go.

Claude Squad

Claude Squad is a terminal app that runs each agent in a tmux session and a git worktree on its own branch. It starts Claude Code by default, and Codex, Gemini or Aider with -p. It needs tmux and the GitHub CLI, and is AGPL-3.0.

CodeRabbit’s git-worktree-runner did similar work, but its GitHub repository is now archived.

cmux, a Mac terminal with notifications for agents, runs them in panes but leaves worktrees to you. Its docs show a custom command you write that runs git worktree add and then starts Codex and Claude Code in it. Trek, cmux and tmux compared.

Desktop agent managers that run each agent in its own git worktree

Each row comes from the app’s own site, docs, pricing page or repository, checked on 4 December 2026. Not stated means its pages don’t say.

AppWorktree made for youSetup scriptIgnored files copiedPorts per worktreeAgentsPlatformsLicencePrice
Parallel CodeFor every taskYes, and a teardown scriptLinked or copied, your choiceA block of 10Claude Code, Codex, OpenCode, Copilot, Antigravity, any terminal agentmacOS, LinuxMITFree
ConductorFor every workspaceYes, and an archive scriptYes, a list or .worktreeincludeA range of 10Claude Code, Codex, Cursor, OpenCode, Muse Code, AntigravitymacOSProprietaryFree. Pro, Teams and Enterprise plans add cloud workspaces
Emdash ClassicFor every task, by defaultYes, with run and teardown scriptsYes, preserve patterns such as .envA range of 10Claude Code, Codex, Cursor, OpenCode, Amp, Devin, Qwen Code, Droid, Copilot and moremacOS, Windows, LinuxApache-2.0Free
NimbalystWhen you pick New Worktree, in Developer ModeNot statedNot statedNot statedClaude, Codex, others in alphamacOS, Windows, LinuxMITFree for individuals. Teams $20 a user a month, free during beta
OrcaFor every taskYes, commands on createYes, .worktreeinclude or shared pathsNot statedAny CLI agentmacOS, Windows, LinuxMITFree
PaneFor every paneYes, with run and archive scriptsYes, .env and other ignored filesA block of 10Any terminal agentmacOS, Windows, LinuxAGPL-3.0, with an attribution termFree
ParadevFor every task, by defaultYes, and teardownNo, a setup command does itNot assigned, it lists themAny CLI agentmacOS, Linux (experimental)MITFree for 1 user. Pro $20 a user a month, or $16 billed yearly
Vibe KanbanFor every workspaceYes, and cleanupYes, a Copy Files listNot assignedClaude Code, Codex, Copilot, Gemini CLI, Amp, Cursor, OpenCode and moremacOS, Windows, LinuxApache-2.0Free. Paid plans ended
T3 CodeWhen you pick New worktree, or by default per projectYes, in t3.jsonNot statedLists them, doesn’t assignClaude Code, Codex, OpenCode, Grok Build, Antigravity, any ACP agentmacOS, Windows, LinuxMITFree
TraycerWhen you pick New worktree for a workspace folderYes, and a teardown scriptNot statedNot stated22 agents, among them Claude Code, Codex, OpenCode, Cursor and CopilotmacOS, Windows, LinuxMITFree. Sync for teams $20 a user a month, or $16 billed yearly
Claude desktop appWhen Worktree is on, off by defaultNot statedYes, .worktreeincludePreview servers move to a free portClaude onlymacOS, Windows, Linux (beta)Not statedClaude Code needs Pro or higher, from $20 a month, or $17 billed yearly
ChatGPT desktop app, for CodexWhen you pick WorktreeYes, per OSYes, .worktreeincludeNot statedCodex onlymacOS, Windows, Linux (preview)Not statedCodex is in the Free plan. Paid plans from $8 a month
GitHub Copilot appWhen you pick New worktreeNot statedNot statedNot statedCopilotmacOS, Windows, LinuxNot statedEvery Copilot plan, Copilot Free included
CursorWhen you start or move an agent into oneYes, .cursor/worktrees.jsonThrough the setup scriptNot statedCursor’s own agentmacOS, Windows, LinuxNot statedFree plan with limited agent requests. Paid from $8 a month
TrekWhen you pick New worktree, or by default per projectNo, a project Action can run one.env and .env.local, list editableNot assignedClaude Code, Codex, OpenCode, Droid, Cursor, Copilot and Kimi, Qwen Code, Grok, Devin, Antigravity CLI, Goose, Amp and Pi, any ACP agent, API and local modelsmacOS, Windows, Linux (preview)Apache-2.0Free

Parallel Code

Parallel Code makes a branch and a worktree for every task and links node_modules, .env and other ignored entries into it, or copies them if you choose. Each task gets a block of 10 ports, the first in PARALLEL_CODE_PORT, and a setup script runs when the worktree is made and a teardown script before it is removed. It is free and MIT, on macOS and Linux, with no Windows build yet.

Conductor

Conductor makes a worktree for every workspace under ~/conductor/workspaces. It copies the ignored files you pick, or those in .worktreeinclude, runs a setup script when it makes a workspace, and gives each workspace a range of 10 ports in CONDUCTOR_PORT. Its desktop app runs on macOS only. Pro adds cloud workspaces. Its terms call it proprietary.

Its team announced on 4 November 2026 that Conductor is joining Meta, with Conductor Cloud to shut down on 20 November. On 13 November it withdrew that and wrote that Conductor isn’t shutting down. The Mac app can still be downloaded from its install page and used today, and 0.103.0 came out on 3 December 2026. Trek and Conductor compared.

Emdash Classic

Emdash Classic makes a worktree on its own branch for every task by default, under ~/emdash/worktrees. Preserve patterns copy ignored files such as .env into each one. Setup, run and teardown scripts can live in a shared .emdash.json, and EMDASH_PORT holds the first of a range of 10 ports. It finds the agent CLIs you have installed, among them Claude Code, Codex, Cursor, OpenCode and Copilot, and runs on macOS, Windows and Linux. It is free under Apache-2.0. New development has moved to Emdash 2.0, which runs agents for teams in the cloud. The open-source app is now Emdash Classic and still gets fixes.

Nimbalyst

Nimbalyst, formerly Crystal, is a visual workspace, with editors for Markdown, mockups and diagrams beside the agents. Worktrees are optional and need Developer Mode. Choose New Worktree from the menu beside New session, then review, commit and merge the branch back from the panel next to the session. Its docs describe no setup script, file copying or ports for worktrees.

Orca

Orca gives every task its own worktree, agent terminal and browser tab. It copies the ignored files that .worktreeinclude names, can share other paths from your main checkout, and runs commands you set when a worktree is made. Cleanup rules exist and are off by default. It runs any CLI agent. Trek and Orca compared.

Pane

Pane makes a worktree, a branch and a block of 10 ports, in $PANE_PORT, for every pane. It copies .env and other ignored files in, and runs the setup, run and archive scripts from pane.json, or from a conductor.json you already have. It removes the worktree when you archive the pane, uncommitted changes included, and keeps the branch. From the command line, runpane panes archive refuses uncommitted, untracked or unpushed work unless you pass --force. It runs on Windows, x64 and ARM64, as well as macOS and Linux, and is free under AGPL-3.0 with an added attribution term.

Paradev

Paradev, formerly Superset, gives every task its own worktree and branch by default. Setup commands in .paradev/config.json run when it makes a workspace and teardown commands when you delete one. It doesn’t copy .env or assign ports. Its docs suggest a setup command for the copy, and it finds the ports each workspace listens on. It has been MIT since 4 November 2026, on macOS with an experimental Linux build.

Vibe Kanban

Vibe Kanban makes a worktree for each workspace and starts the agent in it, with setup and cleanup scripts per repository and a Copy Files list for files such as .env. It runs in your browser from npx vibe-kanban, or as a desktop app with --desktop. The company behind it shut down in April 2026, and the project is now maintained by its community under Apache-2.0.

T3 Code

T3 Code runs a thread in the project’s checkout or, when you pick New worktree, in a worktree of its own. A t3.json file can make worktrees the default and run scripts when one is made. It lists the ports your terminals and agents listen on. MIT, on macOS, Windows and Linux.

Traycer

Traycer asks, for each workspace folder, whether an agent runs in the folder itself, in a new worktree on a new branch, or in a worktree you already have. A setup script in .traycer/environment.json runs in each new worktree, and a teardown script before one is removed. It runs 22 coding agents, among them Claude Code, Codex and Cursor, on macOS, Windows and Linux. It is MIT, and free with your own agents, with a paid Sync plan for teams.

The Claude, ChatGPT, Copilot and Cursor apps

Each runs its maker’s own agent. The Claude desktop app and the ChatGPT desktop app, for Codex, are covered above. The GitHub Copilot app runs each session in a worktree on its own branch when you pick New worktree, from the base branch you choose. Cursor’s Agents Window makes a separate checkout when you start or move an agent into a worktree, and .cursor/worktrees.json holds setup commands, per OS if needed, such as npm ci and copying .env. A banner on Cursor’s site says Cursor is now Grok Build, and its docs now open on docs.grok.com.

Trek

Trek makes a worktree when you pick New worktree for a thread, or for every new thread in a project set to it. It copies .env and .env.local in, and leaves installs and ports to you. Each thread picks its own agent. With Trek, below, has the details.

Which worktree manager to pick for Claude Code and Codex

  • If you use one agent, use its own option. That is claude --worktree or claude --bg for Claude Code, codex --worktree or Worktree in the ChatGPT app for Codex, and New worktree in the Copilot app.
  • If you live in the terminal, Worktrunk covers hooks, a status list and merging, agent-worktree cleans up after each agent run, and Claude Squad suits a tmux setup.
  • If each worktree needs a setup script and its own ports, Conductor does both on a Mac, Emdash Classic and Pane on macOS, Windows and Linux, and Parallel Code on macOS and Linux. In a terminal, Worktrunk’s hooks and hash_port do the same.
  • To have the merge and cleanup checked for you, pick Trek. It merges a thread’s branch only when the project folder is on the base branch with no uncommitted changes, undoes a merge that conflicts and names the files, and never removes a worktree on its own. A thread can also use a model through an API key, or a local one such as Ollama.
  • On Windows, Emdash Classic, Pane, Orca, T3 Code, Traycer, Nimbalyst, Vibe Kanban, Trek and the Claude, ChatGPT, Copilot and Cursor apps all run. Conductor, Paradev and Parallel Code don’t yet. Worktrunk installs with winget.
  • To run agents from different makers side by side, such as Claude Code on one bug and Codex on the other, use an app that runs both, such as Conductor, Emdash Classic, Nimbalyst, Orca, Pane, Parallel Code, Paradev, T3 Code, Traycer, Vibe Kanban or Trek, or make the worktrees with a terminal manager and start each agent yourself.

With Trek

In Trek, a worktree is a choice you make when a thread starts. On a new thread in a git project, click the Local chip in the composer. The menu New thread runs in offers Local, the project folder, and New worktree, a branch of its own. To make New worktree the default for a project, set Project Settings › New threads › Runs in.

Trek's menu for where a new thread runs: Local, the project folder, or New worktree, a branch of its own.
Where a new thread runs.

Trek runs git worktree add on a new trek/ branch named from the first words of your first message. The branch starts from the branch your project folder is on, and the worktree goes in Trek’s own data folder, not in your repository.

  • .env and .env.local are copied in, if they exist and git ignores them. Change the list for each project under Copy into new worktrees. A folder works, globs don’t.
  • Trek doesn’t install dependencies or assign ports. A project Action, such as an install step or a dev server on another port, runs in the worktree of the thread you’re in.
  • Each thread has its own agent, so Claude Code can fix one bug in one worktree while Codex fixes another in a second.
  • The Git tool shows the branch against its base, then Commit all, Push, Create pull request, and Merge into main, or whatever your base branch is called. Create pull request needs the GitHub CLI signed in and a GitHub remote. The merge happens in the project folder, and Trek refuses it unless that folder is on the base branch with no uncommitted changes, and the thread’s changes are committed. If the merge conflicts, Trek runs git merge --abort and names the files that clashed, so the project folder is left as it was.
  • Trek never removes a worktree by itself. Remove worktree… lists what would be lost, and keeps a branch with unmerged commits unless you choose Remove with branch.
  • Worktrees that Conductor, T3 Code or Orca left on disk can come across under Settings › Import Threads. Trek leaves them where they are.

It works the same on macOS, Windows and Linux, where Trek is a preview. Worktrees in Trek covers each step and button.

Questions

How much disk does each worktree take?

Each worktree holds a full copy of your tracked files, but all of them share one history in .git, so it costs far less than a second clone. What grows is what you install and build in each one, such as node_modules, a virtual environment or a build folder. pnpm keeps one store of packages and links them into each folder. Remove a worktree once its branch is merged.

Can two worktrees use the same branch?

No. Git stops with fatal: 'fix-login' is already used by worktree at … unless you add --force. Make a new branch for each agent. The Codex app avoids the problem by starting its worktrees on a detached HEAD.

Do I need a desktop app for this?

No. Git and one terminal per agent are enough for two agents. A manager or an app starts to help when you lose track of which folder holds which task, or you want the worktree, the copied files and the merge done for you.

How many agents can I run at once?

Git’s documentation sets no limit on the number of worktrees. Review runs out first, because every agent hands you a branch to read, test and merge. Start another agent only when you can keep up with the branches you already have.

Does Claude Code’s --worktree flag work with Codex?

No. The flag belongs to Claude Code and starts Claude Code. Codex has its own codex --worktree. To run both on one repository, make the worktrees with git or a manager such as Worktrunk, then start whichever agent you like in each. One .worktreeinclude file serves Claude Code and the worktrees the Codex app makes.

Sources

Every agent. One trail.

Free and open source, for macOS, Windows and Linux (a preview). No Trek account.

Download TrekWaiting on you

Your system
Download for macOS

Apple silicon · macOS 13 or later Other chip: Intel

The first time you open it, go to System Settings, Privacy & Security and click Open Anyway.

Download for Windows

Installer, x64 · Windows 11 Other file: Zip, no installer

The first time, SmartScreen asks. Click More info, then Run anyway.

Download for Linux

x86_64 AppImage · Preview Other files: .debArm AppImageArm .deb

Runs on Ubuntu 22.04, Debian 12, Fedora 36 or later. Make the AppImage executable, then run it.

  • Homebrew (macOS)brew install --cask dokyit/trek/trek
  • npmnpx trek-desktop
  • Shell (macOS, Linux)curl -fsSL https://trekdesktop.com/install.sh | sh
  • PowerShell (Windows)irm https://trekdesktop.com/install.ps1 | iex

Every release, on GitHub

Trek is a desktop app. Open this page on your computer to get it.