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.

agents89git-worktree3parallel-execution5isolationantigravity-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-05-01
When Parallel Antigravity Agents Fight Over the Same File — Preventing Conflicts and Surviving Real-World Race Conditions
Running Antigravity agents in parallel surfaces five concrete kinds of conflict and three classic race conditions. This guide walks through each one with reproducible failures and the locking, optimistic, and queue-based fixes I actually run in production.
Agents & Manager2026-04-19
Antigravity Background Agent Advanced Guide — Task Design, Parallel Execution & CI/CD Integration
From Background Agent internals to task design, AGENTS.md optimization, git worktree parallel execution, GitHub Actions integration, and cost management — everything you need to transform Background Agent from a novelty into a production workhorse.
Agents & Manager2026-03-14
Autonomous Task Management with Claude AI Agents — TodoWrite & Parallel Execution Patterns
Learn how to implement autonomous task management with Claude AI agents. Detailed guide on TodoWrite, parallel execution patterns, and practical code examples.
📚RECOMMENDED BOOKS
Build a Large Language Model (From Scratch)
Sebastian Raschka
LLM Dev
Prompt Engineering for LLMs
Berryman & Ziegler
Prompting
AI Engineering
Chip Huyen
AI Eng
* Contains affiliate links
See all →