◉ANTIGRAVITY LABJP
Articles/Agents & Manager
◈ Agents & Manager/2026-06-13Advanced

Running Multiple Agents on One Repo Breaks It — Isolating Work Areas with Worktrees

When you run several Antigravity 2.0 agents against the same repository, you hit index.lock collisions and half-staged commits. Here is an isolation design using git worktree and projects that gives each agent its own work area, drawn from an incident I ran into in production.

agents152git-worktree3parallel-execution7isolationantigravity-2

✦ Premium Article

I once watched one of two parallel agents sweep up the other agent's commit and push it.

Because I run several sites and apps in parallel as an indie developer, it is tempting to fire off many Antigravity 2.0 agents at once — one adding articles, another bumping dependencies. But when I ran both on the same clone, the dependency agent's git add -A scooped up article files that the other agent had not yet staged, and unintended content landed on main.

I reverted it quickly, but tracing the cause led to a design flaw: I had run agents in parallel while they shared a single work area. This article lays out an isolation design for running multiple agents safely against one repository.

Why sharing a working tree breaks under parallelism

A git repository is made of three parts: the .git directory that holds history, the working tree where the files you are editing live, and the index (staging area) that records what goes into the next commit. The problem is that a clone has exactly one index and one working tree.

When parallel agents share a clone, three kinds of collision occur.

The first is the index.lock collision. git creates .git/index.lock while it rewrites the index. If agent B starts an add while agent A is mid-commit, B fails with Unable to create '.git/index.lock': File exists. In unattended VM runs, that failure tends to be swallowed silently, leaving you "thinking you committed" while nothing happened.

The second is working-tree contamination. Agent B's checkout overwrites files agent A is editing, or wipes them with git checkout ..

The third is the branch mix-up. A working tree can only point at one branch. The moment A switches to a feature branch, B is also working on that branch, and the changes tangle.

Give each agent its own work area with worktrees

All three share one root cause: a shared index and working tree. git worktree lets you keep multiple independent working trees and indexes while sharing a single .git (history). Assign one worktree per agent and you cut the collisions off at the root.

# Derive per-agent worktrees from a normal (non-bare) clone
REPO="$HOME/repos/antigravitylab.net"
cd "$REPO"
 
# Create a dedicated branch + dedicated working tree per agent
git worktree add "../wt-agent-articles"  -b agent/articles  origin/main
git worktree add "../wt-agent-deps"      -b agent/deps      origin/main
 
# Each worktree has its own index
#   ../wt-agent-articles  … article-adding agent only
#   ../wt-agent-deps      … dependency-update agent only

Now the article agent stages and commits only inside ../wt-agent-articles, and the dependency agent works only inside ../wt-agent-deps. Even a git add -A is scoped to that worktree's files. The incident I opened with simply could not happen with this separation in place.

Because worktrees share history, disk use is only the size of each working tree (tens of MB) — far lighter than holding two full clones.

✦

Thank you for reading this far.

Continue Reading

What follows includes implementation code, benchmarks, and practical content we hope you'll find useful. This site runs without ads — server and development costs are supported entirely by members like you. If it's been helpful, we'd be truly grateful for your support.

WHAT YOU'LL LEARN
✦Understand the mechanism behind the three collisions parallel agents hit on one repo: index.lock, working-tree contamination, and branch mix-ups
✦Take home a per-agent worktree layout plus a lifecycle script that covers cleanup, not just creation
✦Learn where to draw the operational boundary so you can safely run up to four parallel agents by combining Antigravity 2.0 projects with worktrees
Secure payment via Stripe · Cancel anytime
✦

Unlock This Article

Get full access to the rest of this article. Buy once, read anytime. This site is ad-free — your support goes directly toward keeping it running.

or
Unlock all articles with Membership →
Share

Thank You for Reading

Antigravity Lab is ad-free, supported entirely by members like you. We publish practical guides daily with implementation code, benchmarks, and production-ready patterns. If you've found it useful, we'd love to have you on board.

  • ✦Copy-paste ready implementation code
  • ✦New advanced guides published daily
  • ✦$5/mo or $10 for lifetime access
View Membership →

Related Articles

◈ Agents & Manager2026-04-19
Antigravity Background Agent in Production — Task Specs, git worktree Parallelism, and the Interactions API
From the sandbox VM to task specifications, AGENTS.md, git worktree parallelism, CI/CD wiring through the Interactions API, and realistic cost estimates — including the mistakes that shaped each one.
◈ Agents & Manager2026-10-22
17 Dead References in My Handover Docs Turned Out to Be 2 Files, and the Real Risk Was a Different Site's Playbook Mixed In
The full Python script I use to check the root .md files an agent reads. My naive version counted 17 dead references; fixed, it was 7 across 2 files. Then it missed the real problem. Here is how I found it.
◈ Agents & Manager2026-10-21
Hooks Load but Never Run — Isolating the Antigravity CLI 1.2.x Report with a Three-Line Canary
A reported problem in Antigravity CLI 1.2.1 and 1.2.2: hooks load and show up in /hooks, yet no hook process ever starts. Here is a three-line canary setup that tells a config mistake apart from an executor problem.