Agent Mail + Beads = Coordinated AI Coding Agents – How Git Worktrees Make It Practical
As AI coding agents move from experimental scripts to production-grade engineers, coordination has become the primary bottleneck. When multiple agents...
Author’s note:
Question: What is Agent Mail? How does Beads package help?
Context: Context:
Also https://x.com/bholmesdev/status/2010189144123998669?s=46
Why aren’t worktrees ideal? What are git worktrees and why do so many agent workflows use them?
Executive Summary
As AI coding agents move from experimental scripts to production-grade engineers, coordination has become the primary bottleneck. When multiple agents work on the same codebase simultaneously, they risk overwriting each other’s changes and losing context.
Agent Mail and Beads have emerged as the standard stack for solving this problem. Agent Mail provides a “Gmail-like” coordination layer that allows agents to communicate intent and reserve files before editing 1 2. Beads complements this by providing a persistent, Git-backed issue graph that gives agents long-term memory and task tracking capabilities 3 4.
To make this practical, developers are increasingly adopting Git worktrees. Worktrees allow multiple agents to operate on different branches of the same repository simultaneously without the overhead of full cloning 5 6. However, this approach introduces new complexity, particularly around file system overhead and branch management 7.
This report details how these three technologies—Agent Mail, Beads, and Git worktrees—combine to create a robust environment for multi-agent software development.
What Is Agent Mail?
Agent Mail is an open-source coordination layer designed specifically for AI coding agents. It functions as an HTTP-only FastMCP server that provides agents with a structured way to communicate, register identities, and avoid conflicts 1 2.
Purpose & Design Goals
The primary goal of Agent Mail is to act as “Gmail for your coding agents” 1. In a multi-agent environment, agents often lack a shared context. Without coordination, they may:
- Overwrite each other’s edits.
- Miss critical context from parallel workstreams.
- Require human intervention to pass messages between tools 1.
Agent Mail solves this by providing:
- Identity Management: Agents register memorable “adjective+noun” names (e.g.,
GreenCastle) to establish persistent identities 1. - Async Messaging: An inbox/outbox system backed by Git for human-auditable history and SQLite for fast indexing 1.
- Conflict Avoidance: A file reservation system that allows agents to “lease” files before editing them 2.
Core API Quick Reference
Agent Mail exposes its functionality through a set of MCP tools. Key tools include:
| Tool Name | Signature | Description |
|---|---|---|
register_agent | register_agent(project_key, program, model, name?,...) | Creates or updates a named identity and persists the profile to Git 1. |
send_message | send_message(project_key, sender, to, subject, body,...) | Writes a canonical message to the messages/ directory and updates recipient inboxes 1. |
fetch_inbox | fetch_inbox(project_key, agent_name, since_ts?,...) | Retrieves recent messages for an agent, preserving thread IDs 1. |
file_reservation_paths | file_reservation_paths(project_key, agent_name, paths,...) | Records an advisory lease on specific files to signal intent to other agents 1. |
File-Reservation “Leases”
One of Agent Mail’s most critical features is its file reservation system. Agents can request an “exclusive” lease on a file or directory for a specific Time-To-Live (TTL) 1.
- Advisory by Default: The system records the lease in a database and writes a JSON artifact to Git. If another agent tries to reserve the same file, the system reports a conflict 1.
- Optional Enforcement: For stricter control, teams can install a pre-commit hook (
install_precommit_guard) that blocks commits if they conflict with an active exclusive reservation held by another agent 1 2.
Web UI & Observability
While agents interact via API, humans need visibility. Agent Mail includes a server-rendered Web UI that allows developers to:
- Browse project inboxes and read agent conversations.
- View active file reservations and their expiration status.
- Perform full-text searches across all messages using SQLite’s FTS5 engine 1.
The Beads Package – A Memory Upgrade for Agents
While Agent Mail handles communication, Beads handles memory and planning. It is a distributed, Git-backed issue tracker designed to give agents a persistent graph of tasks 3.
Architecture Overview
Beads replaces fragile markdown plans with a structured database.
- Git as Database: Issues are stored as JSONL files in a
.beads/directory within the repository. This means issues are versioned, branched, and merged exactly like code 3 4. - Local Caching: To ensure speed, Beads maintains an invisible SQLite cache that allows for sub-second queries, while a background daemon handles synchronization 3.
Issue Graph & Dependency Links
Beads structures work as a graph rather than a flat list. Issues can have parent/child relationships (epics) and blocking dependencies 4. This allows agents to:
- Break down large tasks into “beads on a string.”
- Identify “auto-ready” tasks that are unblocked and ready for execution 3.
- Maintain context over long horizons without getting lost in a massive plan 3.
Conflict-Free IDs & Merging
A major challenge in distributed agent work is ID collision. If two agents on different branches create “Issue #5,” merging becomes a nightmare.
- Zero-Conflict IDs: Beads generates hash-based IDs (e.g.,
bd-a1b2) instead of sequential numbers. This ensures that issues created on separate branches never collide during a merge 3. - Intelligent Merging: Because the data is just JSONL lines in Git, standard Git merge strategies (often aided by AI) can resolve updates from multiple agents seamlessly 4.
Compaction & Memory Decay
To prevent the agent’s context window from overflowing with history, Beads includes a “compaction” feature. It semantically summarizes old, closed tasks, effectively implementing a form of “memory decay” that keeps the active context lightweight 3.
Git Worktrees – Mechanics & Why Agents Love Them
To allow multiple agents to work on the same repository effectively, developers use Git worktrees.
Basic Commands
A standard Git repository has one working directory. git worktree allows you to check out multiple branches at once in separate directories, all linked to the same repository history 5 8.
- Add a worktree:
git worktree add <path> <branch>creates a new directory with the specified branch checked out 8. - List worktrees:
git worktree listshows all active worktrees and their paths 5. - Remove a worktree:
git worktree remove <path>deletes the worktree directory and updates Git’s internal state 8. - Prune:
git worktree prunecleans up stale administrative files if a worktree was deleted manually 8.
Benefits for Parallel Agents
Worktrees are ideal for agent workflows because:
- Isolation: Each agent gets its own directory. Agent A can run tests on
feature-Awhile Agent B editsfeature-Bwithout their file systems clashing 6. - Efficiency: Unlike cloning the repo multiple times, worktrees share the
.gitobject database. This saves disk space and means an object fetched in one worktree is instantly available in others 7. - Context Switching: Agents don’t need to
git stashandgit checkout. They simply operate in their assigned directory 5.
Limitations & Gotchas
Despite their utility, worktrees have constraints that can trip up agent workflows:
- Same-Branch Rule: You cannot check out the same branch in two different worktrees simultaneously. Git enforces this to prevent state corruption 7 9.
- Folder Overhead: Each worktree is a full directory of files. For massive monorepos, creating 50 worktrees can consume significant disk space and hit OS file handle limits 7.
- Tooling Compatibility: Some tools expect the
.gititem to be a directory, but in a worktree,.gitis a file pointing to the main repository. This can break older scripts or tools 7.
Putting It All Together – A Full-Stack Coordination Pattern
By combining these three technologies, you can create a “Beads Village” where multiple agents collaborate autonomously 10.
Repository Layout
A typical setup involves a main repository and transient worktrees for agents.
/my-project /.git # Shared object database /.beads # Shared issue graph (synced via Git) /mail # Agent Mail storage (synced via Git) /worktrees /agent-frontend # Worktree for frontend agent /agent-backend # Worktree for backend agentAgent Bootstrap Script
When an agent starts, it needs to set up its environment. A bootstrap script might look like this:
# 1. Create a unique branch and worktree for the agentAGENT_ID="agent-$(date +%s)"git branch $AGENT_ID maingit worktree add./worktrees/$AGENT_ID $AGENT_ID
# 2. Register with Agent Mail# (Pseudo-code for calling MCP tool)call_mcp_tool "register_agent" --name "BlueBuilder" --project "my-project"
# 3. Reserve critical filescall_mcp_tool "file_reservation_paths" \ --agent "BlueBuilder" \ --paths '["src/frontend/*"]' \ --exclusive true
# 4. Pull tasks from Beadsbd issue list --status readyCI Pipeline Integration
In a CI environment, this stack allows for dynamic parallelism.
- Trigger: A new issue in Beads is marked
ready. - Spin-up: CI allocates a new worktree for an agent.
- Execution: The agent reads the issue, reserves files via Agent Mail, implements the fix, and pushes the branch.
- Merge: Because Beads IDs are hash-based, the agent’s update to the issue graph merges cleanly with other agents’ updates 3.
Comparison of Coordination Strategies
| Strategy | Persistence | Conflict Handling | Scaling (Agents) | Setup Complexity |
|---|---|---|---|---|
| Agent Mail + Beads + Worktrees | Git + SQLite (Local & Distributed) | Hash-ID + Advisory Leases (Enforced via hook) | High (Native Git branching, unlimited per-branch agents) | Medium (Requires MCP wrapper & pre-commit hooks) |
| Plain File Locking | Filesystem only | OS-level lock files (Prone to stale locks) | Low (Hard to coordinate >10 agents) | Low (No extra deps) |
| External MQ (Kafka/RabbitMQ) | Remote Broker | Exactly-once semantics (Requires config) | Very High (High throughput) | High (Requires infra & client libs) |
Best Practices & Common Pitfalls
- Enforce Reservations: Do not rely solely on advisory leases. Enable
FILE_RESERVATIONS_ENFORCEMENT_ENABLED=trueand install the pre-commit guard to prevent “silent” conflicts where an agent ignores a reservation 1 2. - Prune Aggressively: Worktrees can accumulate rapidly. Automate
git worktree prunein your CI scripts to remove stale entries and free up disk space 8. - Monitor SQLite Latency: Beads relies on a local SQLite cache. Ensure your agents have fast local disk access; running this on high-latency network mounts can degrade performance 3.
- Unique Branches: Always create a unique branch for every new worktree. Attempting to reuse a branch name will cause the
git worktree addcommand to fail 7.
Bottom Line
The combination of Agent Mail, Beads, and Git worktrees creates a self-contained, audit-friendly ecosystem for AI development. Agent Mail prevents agents from stepping on each other’s toes 1, Beads ensures they remember what they are doing 3, and Git worktrees provide the physical isolation needed to execute tasks in parallel 6. For teams building multi-agent systems, this stack transforms chaos into a coordinated engineering process.
References
Footnotes
-
Beads Best Practices. Beads continues to grow momentum. When… | by Steve Yegge | Nov, 2025 | Medium ↩ ↩2 ↩3 ↩4 ↩5 ↩6 ↩7 ↩8 ↩9 ↩10 ↩11 ↩12 ↩13 ↩14 ↩15 ↩16
-
Guide: Sending & Receiving Email | AgentMail | Documentation ↩ ↩2 ↩3 ↩4 ↩5 ↩6 ↩7 ↩8 ↩9 ↩10 ↩11
-
GitHub - steveyegge/beads: Beads - A memory upgrade for your coding agent ↩ ↩2 ↩3 ↩4
-
Multi-Agent Orchestration for Parallel Work — Tools & … ↩ ↩2 ↩3
-
How to Work on Multiple Branches Simultaneously with Git Worktree | Learn Version Control with Git ↩
Other Ideas