Skip to content

Parallel agents in lpm

Git worktrees for Claude Code, Codex, and any coding agent.

Two agents in one folder overwrite each other. A worktree fixes that in one command — and then leaves you to rebuild the environment around it. This page covers what worktrees do for agents, what Claude Code and Codex now do natively, and the three levels of isolation you can choose between.

Jump to the comparison

Level 1

A linked worktree

Another checkout of the same repository. Isolates files. Carries nothing else.

Level 2

A managed worktree

The same checkout, created and torn down for you, with the agent already running in it.

Level 3

A standalone copy

The project as it exists on disk right now — local files, dependencies, uncommitted work — with its own Git repository.

The short answer

How do you run multiple AI coding agents on one repository?

Give every agent its own directory. A Git worktree is the cheapest way to do it: a second working directory on its own branch, backed by the same repository history.

One worktree per agent
git worktree add ../app-auth -b auth
cd ../app-auth
claude

Claude Code and Codex now do this for you: claude --worktree creates, enters, and cleans up a worktree per session, and the ChatGPT desktop app gives each Codex chat one. The rest is still yours to set up: copying your .env, installing dependencies, carrying over uncommitted work, and sharing the ports and databases every agent still uses.

That gap is why a second primitive exists. lpm creates worktrees too, and lpm Duplicate can instead copy the project as it sits on your disk into a standalone project with its own Git repository — then start the agent in each one.

Before you fan out

Five things a Git worktree does not carry

Creating the worktree is one command. These are the five reasons the agent inside it still cannot run your project.

  1. Your .env and other ignored files are gone:

    What you see Every environment variable is undefined

    Fix in a worktree List them in .worktreeinclude, or copy them by hand

    In a copy Comes along

    Why
    The agent starts, the app boots, and every environment variable is undefined.git worktree add checks out tracked files only. Anything in .gitignore — .env, .env.local, local certificates, editor settings — was never in the commit, so it is never in the worktree.
    What fixes it
    Claude Code and Codex both read a .worktreeinclude file and copy the gitignored files that match it into the worktrees they create. For everything else you copy them yourself, or start from a copy of the project instead of a checkout.
  2. node_modules is empty in every new worktree:

    What you see A full install per agent before any work starts

    Fix in a worktree Install per worktree, with a setup script

    In a copy Comes along

    Why
    A full install per agent, and another copy of every package on disk, before any work starts.Dependencies are ignored files too. A fresh checkout has none of them, and symlinking one shared directory breaks resolution in tools that walk the real path.
    What fixes it
    Install per worktree and accept the cost, with a setup script if your agent runs one, or duplicate the project so the already-installed dependencies come with it.
  3. The work in progress on your desk does not come along:

    What you see The agent starts from a commit you moved past

    Fix in a worktree Commit or stash first

    In a copy Comes along

    Why
    You ask an agent to continue what you were doing, and it starts from a commit you moved past hours ago.A worktree branches from a commit. Claude Code branches from your default branch by default, or from local HEAD when worktree.baseRef is set to head. Neither reproduces uncommitted edits or untracked files.
    What fixes it
    Commit or stash first, or copy the working project rather than checking one out.
  4. Two agents cannot try the same branch:

    What you see fatal: 'main' is already checked out

    Fix in a worktree One branch per agent

    In a copy Comes along

    Why
    fatal: 'main' is already checked out at '/path/to/repo'Linked worktrees share one repository, and Git refuses to check out a branch in two of them — a commit in one would leave the other pointing at a stale state of the same branch.
    What fixes it
    Give each agent its own branch, or give each one an independent repository so the restriction no longer applies.
  5. Ports, databases, and Docker volumes are still shared:

    What you see The second dev server can't bind its port

    Fix in a worktree Per-copy config, separate services or containers

    In a copy Still shared

    Why
    The second dev server cannot bind. Two agents run migrations against one database and corrupt each other's fixtures.Every isolation model on this page draws its boundary at the filesystem. Nothing about a separate directory reserves a port, namespaces a Postgres schema, or forks a Docker volume.
    Where this stands
    No worktree model solves this, and lpm does not either. What lpm does is catch it: it checks declared ports before a project starts, tells you which process is holding one, and can free it or stop the start. Real runtime isolation still means per-copy configuration, separate services, or containers.

The first four go away when you copy the whole project instead of a worktree: your .env, installed dependencies, and uncommitted work come along by default, and the copy has its own repository, so it can stay on a branch that is checked out elsewhere. The fifth holds for copies too.

What the agents already do

Claude Code and Codex create worktrees for you

Before adding a tool, check what your agent ships with. For a single session on a clean branch, the built-in flag is usually enough. Checked against each CLI's documentation in September 2026.

Claude Code

Built in

Pass --worktree (or -w) with a name and Claude creates the worktree, starts the session inside it, and offers to remove it on exit. Worktrees land under .claude/worktrees/<name>/ on a branch named worktree-<name>. Subagents can get the same treatment with isolation: worktree in their frontmatter.

claude --worktree feature-auth

# copy gitignored files into every new worktree
cat .worktreeinclude
.env
.env.local

New worktrees branch from your default branch unless you set worktree.baseRef to head. Anthropic's own documentation is explicit that a worktree is a fresh checkout and you still have to initialize the environment inside it. Claude Code worktree documentation

Codex

Built in

Codex in the ChatGPT desktop app can give each chat its own worktree, so several run in the same project in parallel. Worktrees are created under $CODEX_HOME/worktrees/ in a detached HEAD state rather than on a branch, leaving your main checkout untouched, and older ones are cleaned up automatically.

It reads a .worktreeinclude file too, and a local environment can run a setup script in each new worktree. Uncommitted work, ports, and databases are still yours to handle. Codex worktree documentation

GitHub Copilot, Gemini CLI, OpenCode, and the rest

Bring your own

Worktrees are a Git feature, not an agent feature, so any terminal agent works inside one. What varies is whether the agent creates and cleans up the directory for you, or whether you script it.

git worktree add ../app-copilot -b copilot-task
cd ../app-copilot
cp ../app/.env .env
pnpm install
copilot

This is the loop that agent-specific flags remove — and the loop that stays if the agent you use does not have one.

Isolation models

Five ways to isolate a coding agent, compared

Raw Git, the worktrees Claude Code and Codex create for you, and both lpm primitives, side by side, so you can see exactly where each boundary is drawn.

Isolated working directory

All five
Yes

Git repository

git worktree
shared
claude --worktree
shared
Codex worktrees
shared
lpm Worktree
shared
lpm Duplicate
independent

Created and removed for you

git worktree
No
claude --worktree
Yes
Codex worktrees
Yes
lpm Worktree
Yes
lpm Duplicate
Yes

Carries .env and other ignored files

git worktree
No
claude --worktree
.worktreeinclude
Codex worktrees
.worktreeinclude
lpm Worktree
No
lpm Duplicate
Yes

Carries installed dependencies

git worktree
No
claude --worktree
No
Codex worktrees
setup script
lpm Worktree
install
lpm Duplicate
Yes

Starts from your uncommitted work

git worktree
No
claude --worktree
No
Codex worktrees
No
lpm Worktree
No
lpm Duplicate
Yes

Two agents on the same branch

git worktree
No
claude --worktree
No
Codex worktrees
No
lpm Worktree
No
lpm Duplicate
Yes

Create many at once

git worktree
No
claude --worktree
No
Codex worktrees
one per chat
lpm Worktree
1–50
lpm Duplicate
1–50

Queue the same prompt on each

git worktree
No
claude --worktree
No
Codex worktrees
No
lpm Worktree
Yes
lpm Duplicate
Yes

Inherits the project's services and actions

git worktree
No
claude --worktree
No
Codex worktrees
No
lpm Worktree
Yes
lpm Duplicate
Yes

Works with any terminal agent

git worktree
No
claude --worktree
Claude only
Codex worktrees
Codex only
lpm Worktree
Yes
lpm Duplicate
Yes

Isolates ports, databases, Docker volumes

All five
No

The last one is worth reading twice. Nothing above reserves a port, namespaces a database, or forks a Docker volume, including both lpm entries. Filesystem isolation is where all five stop, and shared ports and databases are where parallel agents usually collide. lpm catches the port half of it when a project starts: it tells you which process holds a declared port and can stop it or cancel the start. Giving each copy its own ports is up to your configuration.

One prompt, three agents

Both primitives, the same fan-out

lpm does not ask you to give up worktrees. Pick the kind from the project menu, and both share the same fan-out form for queuing the work.

lpm Worktree

Linked worktrees, created in a batch

Each one is a real Git worktree on a new branch from your current commit, sharing the repository. Uncommitted and ignored files stay behind, the same as raw Git. Tick Install dependencies when the worktree needs them.

  • Deleting one also deletes its branch, so merge or push anything you want to keep first
  • Needs a Git repository with at least one commit, with the project at its root

lpm Duplicate

Standalone copies of the project you have now

A copy of the folder with its own Git repository, carrying uncommitted work, ignored files, and installed dependencies; on APFS it is a copy-on-write clone. Regenerable build caches are left behind.

  • Pulls the latest commits by default; optionally keep committed work only or reinstall dependencies
  • Each copy is independent, so several can sit on the same branch
  1. 01

    Right-click a project and choose Duplicate for standalone copies or New worktree for linked worktrees, then set how many, up to 50.

  2. 02

    Label them, group them in the sidebar, and pick the action or command each one should run, with the prompt to send. Each copy can get its own.

  3. 03

    Watch every copy's agent status from the sidebar, review the diffs, and delete the copies you do not keep. Deleting is permanent.

The agents can drive this themselves. lpm installs skills for Claude Code, Codex, Gemini CLI, and OpenCode, so an agent asked to try three approaches can create its own copies, run the work in them, wait for the others to settle, and clean them up when you have merged the one you want. Already typing the prompt? Choose Run in duplicates from the composer’s send menu to run it here and in fresh copies at once, or read the full guide to running Claude Code in parallel.

Pick one

Which isolation model do you actually need?

Work down the list and stop at the first line that describes your repository.

  • One agent, one clean branch, and setup is cheap

    Your agent's built-in flag

    claude --worktree, or a worktree chat in the ChatGPT desktop app for Codex. Nothing to install, and the agent cleans up after itself.

  • Several agents, and your repository needs no local setup

    Git worktree, or lpm Worktree for the batch

    The checkout is all the agent needs, so the lightest primitive wins. Use lpm Worktree when you want several at once with a prompt queued on each.

  • The agent needs your .env, your dependencies, or your uncommitted work

    lpm Duplicate

    A checkout cannot reproduce state that was never committed. A standalone copy of the working project can.

  • Several agents should attempt the same branch and you keep the best

    lpm Duplicate

    Linked worktrees refuse a branch that is already checked out. Independent repositories have no such restriction.

  • You are running agents with approvals turned off

    A container or a VM

    None of these models is a security boundary. A separate directory does not contain a command that decides to touch the rest of your machine.

FAQ

Git worktrees and AI agents, answered

  • Does Claude Code support Git worktrees?

    Yes. Pass --worktree or -w with a name and Claude Code creates the worktree, starts the session in it, and offers to remove it when you exit. Worktrees are created under .claude/worktrees/<name>/ on a branch named worktree-<name>, and subagents can be pinned to their own worktree with isolation: worktree in their frontmatter.

  • Does a Git worktree copy files like .env or node_modules?

    No. git worktree add checks out tracked files from the commit you point it at. Anything ignored by Git — .env files, node_modules, virtualenvs, local certificates — is absent from a new worktree. Claude Code and Codex can copy selected ignored files into the worktrees they create if you add a .worktreeinclude file, and lpm Duplicate carries them because it copies the project folder instead of checking one out.

  • Should every Claude Code session get its own worktree?

    Only if two sessions could touch the same files. A worktree hands each session a separate checkout on its own branch, so their edits cannot collide; sessions working in unrelated parts of the repo can share one checkout. Whatever directory you pick — a worktree, a standalone copy or a container — sessions on one Claude account still share its plan limits, so the ceiling is usually how many diffs you can review.

  • Can two Git worktrees check out the same branch?

    No. Git refuses with 'fatal: <branch> is already checked out at <path>', because a commit in one worktree would leave the other pointing at a stale state of the same branch. If you want several agents to attempt the same branch and then keep the best result, each one needs an independent repository rather than a linked worktree.

  • Does Codex support parallel agents and worktrees?

    Yes. Codex in the ChatGPT desktop app can run each chat in its own Git worktree, created under $CODEX_HOME/worktrees/ in a detached HEAD state, so several chats work in parallel and your main checkout stays untouched. It can copy files listed in .worktreeinclude and run a setup script in each worktree, but as with Claude Code, ports and databases are still shared.

  • Do Git worktrees isolate ports, databases, or Docker volumes?

    No, and lpm does not isolate them either. Every model on this page draws its boundary at the filesystem, so two agents in two worktrees will still fight over port 3000 and still run migrations against the same database. lpm checks declared ports before a project starts and tells you which process is holding one, so the collision surfaces immediately instead of halfway through a run. Isolating runtime state needs per-copy configuration, separate services, or containers.

  • Can I use Git worktrees with GitHub Copilot, Gemini CLI, or OpenCode?

    Yes. Worktrees are a Git feature, so any terminal agent runs inside one. What differs is whether the agent creates and cleans up the directory for you. Claude Code and Codex do; for the others you run git worktree add yourself, or use a tool that does the batch for you.

  • Is there a Git worktree MCP server or agent skill?

    lpm installs skills for Claude Code, Codex, Gemini CLI, and OpenCode that teach the agent how to drive lpm directly. An agent can then create its own isolated worktrees or copies, run work in them, wait for the others to settle, and remove them, without you translating each step yourself.

  • What is the difference between lpm Worktree and lpm Duplicate?

    They are separate items in a project's right-click menu. New worktree creates real linked Git worktrees, each on a new branch from your current commit, sharing your repository. Duplicate creates standalone folders with their own Git repository, starting from the project exactly as it is on disk. Both create up to 50 at a time, inherit the project's services, actions, and pinned Claude account, and can queue an action or command with a prompt on each one.

  • Does lpm Worktree copy my .env file and dependencies?

    No. lpm Worktree creates a real Git worktree, so it has the same blind spot as raw Git: uncommitted and ignored files are not carried over. Tick Install dependencies to install them fresh in each worktree. If the copy needs your local files and current state, use lpm Duplicate instead.

  • What happens when I delete an lpm worktree or copy?

    lpm deletes the folder outright and skips the Trash, and removing a worktree also force-deletes its branch, so push or merge anything worth keeping first.

  • How much disk does each copy use?

    A linked worktree is very compact because the repository data is shared. On APFS, a Duplicate begins as a clone whose unchanged blocks stay shared on disk, and it only grows as each copy changes; where the disk can't clone, as on ext4 or Windows, it is a full copy. Regenerable build caches such as .next, dist, and target are skipped rather than cloned.

  • How many parallel agents should I run?

    Fewer than you can create. Spinning up five agents takes one command; reviewing five diffs and landing five branches does not scale the same way, and every session draws on the same plan limits. The bottleneck is usually review, not isolation.

Worktrees when a checkout is enough. Copies when it is not.

Download lpm and fan one prompt out to Claude Code, Codex, or any terminal agent — in linked worktrees or standalone project copies, whichever the task needs.