Articles
January 27, 2026

Running Multiple AI Agents at Once Using Git Worktrees

Cover image for: Running Multiple AI Agents at Once Using Git Worktrees

The Agent is the bottleneck

The Problem

Running a local agent effectively “locks” your workspace. While an agent is busy with code generation or long-running evaluations, you are tied to that specific branch. Switching branches to handle a separate task risks breaking the agent’s execution or creating a mess of uncommitted changes.

Cloning the repository into multiple separate folders is a common workaround, but it is inefficient. It duplicates the entire .git history, consumes excessive disk space, and makes managing synchronized updates between copies a logistical headache.

The Solution

Git Worktrees¹. Instead of cloning, worktrees allow you to attach multiple independent working directories to a single repository. Think of them as “parallel universes”: each agent gets its own folder and branch, enabling five agents to operate on five different tasks simultaneously from one source.

Once a task is complete, you simply merge the worktree branch into main. Deleting the worktree folder leaves no trace, no redundant clones, no configuration drift, and no idle time.

Simultaneous Agents with Git Worktrees

A worktree is a linked copy of your project that shares the same history but lives in a different folder. We will look at a more convenient way of managing this later, but first let’s look at how we can do this with Git natively.

The process is rather simple, first you need to create a new worktree from within your project

git worktree add ../agent-folder feature-branch

This commands creates a sibling folder agent-folder and in this folder checks out the branch feature-branch.

You can view all work trees with the list command:

git worktree list

And once you are done and have merged your PR, you use this for other tasks or simply remove the worktree folder:

git worktree remove ../agent-folder

Whenever you create a new worktree you need to manually install dependencies and set up the environment. Luckily there is an even easier solution.

A better approach

Worktrees solve the problem, but the UX is not fantastic. Luckily there is a package that comes with a great UX: @johnlindquist/worktree²

The package automates the tedious parts of native worktrees. It handles stashing your work, installing packages, and opening your editor in one step. And it can remove everything once you are done.

Installation

Setup is as simple as globally installing an npm package.

npm install -g @johnlindquist/worktree

Once done you are ready to use the wt command to manage your work trees.

If you want some more automation, you need to create a worktrees.json file in any repo you want to use this in. Now you can define the steps that should be run upon creating the new worktree so that you can immediately jump into prompting your agent.

{
  "setup-worktree": [
    "npm install",
    "cp $ROOT_WORKTREE_PATH/.local.env .local.env",
    "echo 'Setup complete'"
  ]
}

Git alias for more convenience

By default the worktrees.json setup script only runs when you run wt setup. However, if like me, you want this to run on wt new as well, simply create a function in your .zshrc or .bashrc .

wt() {
  if [[ “$1” == “new” ]]; then
    # run setup instead if new
    command wt setup “${@:2}” — trust
  else
    # fall back to original
    command wt “$@”
  fi
}

The workflow: Running Multiple Agents Simultaneously

With everything setup you can now enjoy the power of running multiple local agents on different branches at the same time. The workflow is fairly simple.

Using the terminal you navigate to your project and create a new worktree:

# navigate to project
cd projects/my-app

# create new worktree
wt new feature-darkmode

A new worktree folder named [folder-name]-[branchname] (e.g., my-app-feature-darkmode) is created automatically.

You can view the worktrees using wt ls, or via the standard git branch command. In your branch list, active worktrees are identified by a + prefix.

> git branch
 * main # current branch
 design-tokens
 + feature-darkmode # worktree

A new branch, feature-darkmode in this example, is created automatically.

You can manage this branch like any other, but Git prevents you from checking out a branch that is already active in another worktree. This safeguard prevents file conflicts.

Once your agent completes its task, simply push and merge the branch as usual. Since all worktrees share the same underlying repository history, your changes are immediately visible across all environments. After merging, you can safely delete the worktree folder using the wt rm command, the branch itself remains in your Git history until you choose to delete it.

wt rm feature-darkmode

PRs & existing branches

If you want to work on an existing PR or branch, you can do this as well.

To open a new worktree with an existing branch use extract followed by the branch name.

wt extract existing-branch

To open a PR (from GitHub by default, but you can change this in the settings) use pr followed by the PR number.

wt pr #357

TL;DR

Use Git Worktrees to run multiple local AI agents on different branches of the same repo. Use the @johnlindquist/worktree² package (wt CLI) for an improved UX to create an manage worktrees.

The worktrees.json file lets you automatically run npm install, copy .env files or do other setup tasks when creating the worktree.


  1. https://git-scm.com/docs/git-worktree
  2. https://www.npmjs.com/package/@johnlindquist/worktree