Several agents, one repository: ownership rules from real incidents
When more than one agent works in the same repository, the common failures are overwriting each other's files and committing each other's unfinished work. Give every agent its own worktree, add only named paths, and edit shared control files one record at a time.
π― For A team lead who runs more than one coding agent against the same repository
- Three incidents that happen when agents share a working tree
- Rules: one worktree per agent, explicit paths, one record at a time
- A test that catches a shrinking control file
π₯ What goes wrong
One agent on a repository behaves like one careful colleague. Several agents behave like several colleagues editing the same document at the same time with no names on it. Three things happen. They overwrite each other. A commit picks up someone else's half-finished change. And nobody can say afterwards who made a change, so nobody can fix the cause.
π Two incidents
On 21 September 2026 an agent wrote a stale copy of a shared control file over a fresh one. The file held the registry of running initiatives. It lost fifteen keys and three pipeline entries, including a reference to an accepted architecture decision.
On 26 September 2026 two agents edited the same temporary worktree at the same time. A commit by one of them would have captured the other's unfinished changes. The second agent also changed the owner of the folder, which broke the first one's test run.
π The rules we wrote
- One worktree per agent. Each agent creates its own folder named after itself and the task, and writes a small owner file in it: agent, process id, time, task. If you find an owner file that is not yours, stop and tell a person.
- Explicit paths only. Add files by name. Never use "add all", because the shared tree always holds changes that are not yours.
- Control files are edited one record at a time. Re-read the file immediately before writing. If your tool cannot make a point edit, return the proposed text to the owner instead of writing the file.
- Every initiative has an owner. The owner implements it. Others propose changes in a report.
- Finish with a commit. A change left uncommitted in the shared tree when the task ends is a defect: nobody will accept it, someone else's commit may capture it, or it will be lost.
π§ͺ A test for shrinking files
The 21 September loss could have been caught by a cheap test. Ours compares the control files in the working tree with the committed version and fails when a record that existed in the commit has disappeared. The failure message starts with a fixed word so that it is easy to search for. The test file holds 4 tests and runs in the nightly gate.
π οΈ Practice: set it up in one hour
- Create a worktree per agent with a script that also writes the owner file.
- Make "add all" fail by a wrapper or a pre-commit check that lists staged paths and asks for each to be named in the task.
- Choose the three files that control your system: a registry, a pipeline list, a configuration. Write them down.
- Write a test that loads each from the commit and from the tree, and fails when a key or record is gone.
- Add an owner field to each initiative.
- Add a rule: the task is not finished until the commit and the push are done.
β Check yourself
- Start two agents on two tasks. Their folders are different and each holds an owner file.
- Delete a record from a control file and run the test. It fails and names the record.
- Try to stage everything. The check stops you and lists what it saw.
- At the end of a task,
git statusin the shared tree shows nothing of yours.
π§ When this does NOT work
- Merge conflicts remain. Separate worktrees move the conflict to the merge. The owner rule is what keeps it small.
- Generated files. Files that every agent regenerates will always conflict. Keep them out of git or serialise them.
- Disk and build cost. Each worktree needs space and a build. Use shallow setups for light tasks.
- Agents that ignore the instructions. A rule in a file is not enforcement. Put the important ones into checks.
- Human edits. People who write into the shared tree break the model. Give them a worktree too.
π Evidence
| What we measured | Records lost from a control file on 21 September 2026; test count of the guard |
| When | Incident records read on 3 November 2026, 22:06 UTC |
| Artifact | Our agent rules file and the test file for shrinking control files (4 tests) in a private repository |
| Limit | Two incidents in one team. We have no count of how many would have happened without the rules |
β‘οΈ Next
Learn how to split work between agents in Splitting work across agents, and when not to, and how to hand work over with criteria in Spec-driven development.
Sources
- Splitting work across agents, and when not to: swarm design.
- Spec-driven development with existing task packets: handover with criteria.
- AGENTS.md and rules files: where the rules live.
- An AI usage policy and register a small team can enforce: ownership in the register.
π Article connections
Open the full knowledge graph βPublished article links. Select a node to open its article at the heading.
Article links Β· keyboard / text view
Same topic
- A vector base is a map, not a source: what we learned from retrieval
- When you cannot tell what a model call cost: freeze, then reconcile
- Splitting a big task for a cheap model: the 24,000-byte lesson
- Skills, MCP tools and rules: three ways to give an agent capabilities
- Eight shell and git mistakes our agents made, and the rule for each
- Keep provider keys out of the agent: one gateway, one token per task
Next steps
Related reading
A vector base is a map, not a source: what we learned from retrieval
A vector base finds passages that are close in meaning to your question. It does not know which are true or current. Treat every hit as a pointer: open the file it names, check the hash, and take numbers from the artifact, never from the retrieved paragraph.
AI agents and MCP explainedWhen you cannot tell what a model call cost: freeze, then reconcile
Sometimes a model call times out and you do not know whether the provider charged you. Never record that as zero. Mark it uncertain, stop new paid calls, and let a named person reconcile it with the provider's statement. Refusals before generation are the exception.
AI agents and MCP explainedSplitting a big task for a cheap model: the 24,000-byte lesson
A cheap model does well on one small, well-defined job and badly on a big pile. We cap a task at 24,000 bytes and refuse larger ones before any model is called. Split by unit, one file or one country per task, and check the size before you start.
AI agents and MCP explainedSkills, MCP tools and rules: three ways to give an agent capabilities
Agents get abilities in different ways. A rule constrains what they do, a skill tells them how to do a job, and an MCP tool lets them call a function. Each has its own risk, so declare all three in a register and test that nothing exists unlisted.
π¬ Comments