When scaling complex software engineering across multiple autonomous AI agents, standard conversational prompts fail. Two coding agents running simultaneously on the same filesystem will overwrite files, clobber git branches, introduce merge conflicts, and make uncoordinated architectural choices.
Rather than standing up an external database, Redis lock coordinator, or distributed queuing infrastructure, we designed an offline-first, file-based collaboration system (PROTOCOL.md and collab.py). This protocol enables Claude Code and Antigravity to work concurrently across multiple git repositories with deterministic safety.
The Problem: Concurrency and Race Conditions
Modern coding agents possess substantial agency: they inspect repositories, execute terminal commands, edit multiple source files, and commit changes. However, when two agents run concurrently:
- Working Tree Contention: If Agent A modifies a file while Agent B is running a build or git rebase, both processes crash or produce corrupted artifacts.
- Review Deficits: Autonomous commits merged directly into trunk without peer review introduce regressions and silent failures.
- Escalation Ambiguity: An agent may make high-stakes product decisions—such as publishing sensitive data or altering verified career claims—without explicit human approval.
To eliminate these failure modes, we formulated three requirements:
- Zero external infrastructure: All state must reside directly within git-tracked markdown and lightweight script tooling.
- Exclusive repository locking: Only one agent may hold write permissions to a repository at any given time.
- Two-tier governance: Low-risk technical decisions proceed autonomously under strict rules; high-risk decisions pause for human sign-off.
Architecture: Shared State on Disk
The collaboration system centers on three core artifacts:
PROTOCOL.md: The operational contract defining rules of engagement, lock lifecycles, and commit standards.STATUS.md: The live status board containing the active task matrix, current repository lock holders, and unread agent message queues.collab.py: A deterministic Python CLI that mediates state transitions, handles lock acquisition, manages task dispatch, and formats messages.
+---------------------------------------------+
| Human |
| (Tier 2 Approvals & System Goal) |
+---------------------------------------------+
|
v
+---------------------------------+
| STATUS.md & collab.py State |
+---------------------------------+
/ \
v v
+-------------------+ +-------------------+
| Claude Code | | Antigravity |
| (CLI / Architect) | | (IDE / Fullstack) |
+-------------------+ +-------------------+
\ /
v v
[Repo Lock: Exclusive Git Working Copy]
Every state update is atomic. When an agent requests a lock via python collab.py lock <repo-id> --agent <agent-id>, the script inspects the locks table in STATUS.md. If held by another agent, the command exits with a failure code, preventing dirty read-write collisions.
Two-Tier Decision Governance
Not all engineering choices carry the same level of risk. We categorized decisions into two distinct tiers:
Tier 1: Routine Technical Decisions
Tier 1 covers implementation details that fall within established rules:
- Selecting a clean TypeScript pattern or React component structure.
- Choosing between standard styling utility classes matching design tokens.
- Refactoring test helpers or lint configurations.
Agents resolve Tier 1 decisions autonomously. Each decision is recorded in the task commit history and linked to the session handoff log.
Tier 2: Reserved High-Stakes Decisions
Tier 2 covers actions with potential irreversibility or policy impact:
- Public exposure of previously private repositories.
- Changes to verified career claims, credentials, or timeline dates.
- Data schema models touching user or learner attributes.
- Altering baseline performance thresholds or security rules.
When an agent encounters a Tier 2 decision, it writes a structured proposal document (D-xxxx-<topic>.md) specifying:
- Context: The technical problem and constraints.
- Options Considered: 2 to 3 distinct options with trade-offs.
- Recommendation: The agent's proposed path with supporting technical rationale.
The agent transitions the task to blocked and yields execution. No code modifying that surface may land until human approval is committed.
Task Lifecycle and Peer Review
Each work unit follows a strict four-state finite state machine:
[todo] --> [in_progress] --> [review] --> [done]
- Claiming: The agent acquires the repository lock and transitions the task from
todotoin_progress. - Branch Isolation: Work occurs strictly on an isolated feature branch named
feat/<agent>-<task-id>-<short-name>. Direct commits tomainare prohibited. - Verification Gate: Before submitting for review, the authoring agent executes the repository verification suite: unit tests, linter, type checker, and production build.
- Handoff and Peer Review: The authoring agent transitions the task to
review, releases the repository lock, and logs the diff in a session handoff note. - Merge Gate: The reviewing agent (or human) checks out the branch, verifies test execution, checks for conformance with system truth rules, and merges into
main.
# Example agent lifecycle commands via collab.py
python collab.py lock repo-portfolio-project --agent antigravity-1
python collab.py set-status T-0015 in_progress --agent antigravity-1
# ... work performed on isolated branch ...
npm test && npm run lint && npm run build
python collab.py set-status T-0015 review --agent antigravity-1 --note "Blog MDX engine and seed posts"
python collab.py unlock repo-portfolio-project --agent antigravity-1
Measured Outcomes
Operating two independent coding agents under this protocol produced verifiable engineering gains:
- Zero Merge Collisions: Across dozens of completed tasks spanning multiple repositories, no branch experienced an accidental overwrite or file-level lock contention.
- Auditable History: Every decision, status transition, and lock release is preserved in git commit history, providing a complete audit trail.
- Deterministic Handoffs: Structured handoff logs eliminate context degradation between consecutive agent invocations.
Autonomous agent swarms do not require complex distributed systems. Clear operational contracts, atomic file locks, and rigorous gate validation provide the stability necessary for multi-agent software engineering.