Splitting AI agents into a team without letting them step on each other
A Leader, a Worker and a Reviewer in Claude Code, sharing one small project. How file ownership, role-scoped tools, a spec with proof items and one shared status file keep them out of each other's way.
When one AI agent writes the code and then tells you the code is done, you are trusting it to grade its own homework. The obvious fix is to split the work across several agents: one builds, one checks, one coordinates. The less obvious problem is that the moment you have more than one agent in the same project, they can overwrite each other’s files, “fix” each other’s work, and argue in circles.
I built a deliberately tiny demo to work out the rules that stop that from happening. It runs in Claude Code inside VS Code, with no framework and no dashboard. Three roles, one spec, one status file. This post is about the boundaries, not the code, because the boundaries are the part that carries over to real projects.
The team
| Role | Job | Who plays it |
|---|---|---|
| Leader | Reads the spec, assigns work, decides the next step, reports back | The main Claude Code session (the one I talk to) |
| Worker | Writes and fixes code to meet the spec | A subagent defined in .claude/agents/worker.md |
| Reviewer | Checks the Worker’s result against the spec by running tests | A subagent defined in .claude/agents/reviewer.md |
The task itself is small on purpose: a Python CLI, wordstats.py, with one function not yet implemented (top_words) and one function with a bug (unique_words was case-sensitive when the spec says it should not be). A small task makes it easy to see what each agent touched and why.
The project layout is the whole “system”:
agent-team-demo/
├── SPEC.md ← the task + acceptance criteria (written by me)
├── STATUS.md ← shared progress board
├── .claude/agents/
│ ├── worker.md
│ └── reviewer.md
└── project/
├── wordstats.py ← the only file the Worker may change
├── sample.txt
└── tests/
└── test_wordstats.py
Rule 1: every file has exactly one owner
Most collisions between agents are two agents editing the same thing. So before any agent runs, every file in the project has an owner, and the agent definitions say so.
| File or section | Owner | Everyone else |
|---|---|---|
SPEC.md | Me (the human) | Read only |
project/tests/ | Me | Read and run only |
project/wordstats.py | Worker | Read only |
STATUS.md → “Worker log” | Worker | Read only |
STATUS.md → “Reviewer verdict” and the PASS/FAIL column | Reviewer | Read only |
STATUS.md → header, round counter | Leader | Read only |
Two details matter here. First, the tests belong to the human, not the Worker. An agent that is allowed to edit the tests can make any failure go away. Second, the status file is shared, but split into sections with one writer each. Agents never write in each other’s section.
The Worker’s instructions:
---
name: worker
description: Implement and fix code per SPEC.md inside project/. Use when the Leader assigns coding work.
tools: Read, Edit, Write, Bash
---
1. Read SPEC.md and STATUS.md before doing anything.
2. Only change code in project/. Do not touch project/tests/ or SPEC.md.
3. Meet the acceptance criteria in the spec. Do not add features beyond it.
4. When done, run the tests once yourself: python -m pytest project/tests -q
5. Write what you changed and the test result under "Worker log" in STATUS.md.
6. Report back to the Leader.
Never declare the work "done" while tests fail.
Official acceptance belongs to the Reviewer, not to you.
The last line is the important one. The Worker may run the tests, but it does not get to say “accepted”.
Rule 2: tools match the role
Instructions say what an agent should do. The tools: line decides what it can do. The Reviewer’s job is to judge, not to repair, so it gets no Write tool:
---
name: reviewer
description: Independently verify the Worker's result against each criterion in SPEC.md by running tests.
tools: Read, Bash, Edit
---
You do not change code in any form. Your Edit tool is only for writing
the verdict into STATUS.md.
1. Read SPEC.md. It is the only acceptance standard.
2. Run the tests: python -m pytest project/tests -q
3. Run the CLI and compare its output with criterion 3 in the spec.
4. Write PASS or FAIL per criterion in STATUS.md, with the real output as evidence.
5. If anything fails, tell the Leader which file and which behaviour is wrong.
Judge only from output you just ran. No guessing, no leniency.
The Leader has the strictest rule of all, and it lives in the prompt I give it: you do not write code, you only coordinate. A coordinator that also codes will quietly fix things itself, and then nobody reviewed that fix.
Lesson. If a role does not need a tool, take the tool away. A rule in a prompt is a request; a missing tool is a guarantee.
I only half followed that lesson here. More on that below.
Rule 3: the spec is the contract, and it has proof items
Agents that share a project need something to agree on that is not each other’s opinion. In this demo that is SPEC.md, and the useful part is not the description but the acceptance criteria, written so a machine can check them:
1. top_words(text, n) returns the n most frequent words as list[tuple[str, int]].
Case-insensitive, returned in lower case. Ties are sorted alphabetically.
2. unique_words(text) counts distinct words case-insensitively.
3. CLI: python wordstats.py sample.txt prints exactly 3 lines:
total_words: 26
unique_words: 18
top_3: [('the', 5), ('fox', 3), ('dog', 2)]
The Worker builds against these. The Reviewer checks against these. The Leader decides the next step from these. Nobody has to interpret “make it work”, so there is nothing to argue about. If the Reviewer says FAIL, it has to point at a numbered criterion and a real output line.
Rule 4: take turns, and talk through a board
The agents never talk to each other directly. Every handoff goes through the Leader, and every result is written to STATUS.md. I keep that file open in the editor and watch it change.
Press a scenario. The left side is who is talking to whom; the right side is STATUS.md filling in, one color per owner.
Press a scenario.
STATUS.md
- · 1. top_words order + ties
- · 2. unique_words, any case
- · 3. CLI prints 3 lines
Two things keep this loop from going wrong:
- One agent works at a time. The Leader runs the Worker, waits, then runs the Reviewer. Because they never run at the same time, the shared status file cannot get two conflicting writes. Sequential is slower, but for one task in one file it costs very little.
- The QA loop has a cap. If the Reviewer fails the work, the Leader sends it back to the Worker, at most twice. After that it stops and reports to me. Without a cap, a Worker and a Reviewer who disagree about an ambiguous spec will loop until the quota runs out.
The prompt I gave the Leader:
You are the Leader of the agent team. Read SPEC.md and STATUS.md first.
Assign the implementation to the "worker" subagent. When the worker reports
done, assign the "reviewer" subagent to verify each acceptance criterion in
SPEC.md independently. If the reviewer FAILs, send it back to the worker,
at most 2 QA rounds. Update STATUS.md after every step. You do not write code
yourself, you only coordinate. When finished, summarise the result for me.
How the run went
It passed in the first QA round, so the “send it back” path was not exercised in this run.
Worker, round 1. It lower-cased tokens before putting them in a set (unique_words), and implemented top_words with a Counter sorted by (-count, word). It logged that it did not touch count_words, main, the tests or the spec, and that its own test run gave 5 passed.
Reviewer, round 1. This is the part I liked. It did not stop at “the test suite passes”:
- It ran the full suite (
5 passed) and the CLI, and compared the three output lines exactly against criterion 3. - It tried edge cases the tests do not cover: an empty string,
nlarger than the number of words, ties across mixed case ('Zeta zeta Alpha alpha beta'). - It checked the ownership rule. The project was not a git repo, so it compared file modification times:
SPEC.md,sample.txtand the test file still had their original timestamps, and onlywordstats.pyhad changed. - It noticed that the module docstring still said the functions were “buggy” and “not implemented”, which was now out of date. It wrote that down as a minor note and did not fix it, because that file is not its file.
That last point is the whole idea in one example. The Reviewer saw a problem outside its role, reported it, and left it for the owner.
What broke, or would break next
Nothing failed in this run, but the setup has weak spots I would not carry into a real project.
The Reviewer can still edit code. It needs Edit to write its verdict into STATUS.md, and Claude Code’s Edit tool is not limited to one file. So “the Reviewer never changes code” is enforced by its prompt, not by its tools. The fix is to give the Reviewer its own output file it is allowed to create (or a hook that blocks edits outside STATUS.md), and remove Edit entirely.
Timestamps are weak evidence. The ownership check used file modification times because there was no git history. With the project in git, the Reviewer runs git diff --stat and the evidence is exact: which files changed, and by how much.
The stale docstring had no owner. The spec said what the functions must do, not that comments must be kept accurate, so the Leader never assigned it and the Worker never touched it. Gaps in the spec become gaps in ownership. In a real project I add a line like “keep docstrings and README in sync with behaviour” to the Worker’s checklist.
The shared status file only works because agents take turns. Two Workers editing STATUS.md at the same moment would overwrite each other. Splitting into sections is enough for sequential work, not for parallel work.
Every subagent is its own session. Each one starts with a fresh context and uses its own share of the Claude quota. One Worker and one Reviewer is enough to learn the pattern; adding agents for the sake of it just costs more.
Going parallel: what I would change
The demo is sequential on purpose. To run several Workers at once without collisions, the same four rules still apply, they just get stricter:
- Ownership by area, not by file. Worker A owns
src/billing/, Worker B ownssrc/reports/. If two tasks need the same file, they are not parallel tasks; the Leader runs them one after the other. - Separate working copies. Each Worker gets its own git worktree and branch, so they cannot overwrite each other on disk. The Leader merges.
- One status file per Worker.
status/worker-a.md,status/worker-b.md. The Leader reads all of them and writes the summary. - The Reviewer reviews each branch on its own, against the criteria for that task, before anything is merged.
I have not built that version yet. It is the next step, and I will write it up when I have run it on a real codebase rather than a word counter.
Update. I have now run the team on a real codebase, and it did not go parallel. One Worker plus an area map turned out to be enough, and three of the rules above moved out of prompts into a hook, a workflow script and that area map. The write-up: The AI agent team on a real codebase.
Takeaways
- Splitting agents is easy. Keeping them apart is the actual design work. Decide who owns each file before the first agent runs.
- Take tools away from roles that should not use them. Prompts are requests; tool lists are limits.
- Give agents a contract they can check, not a goal they have to interpret. Numbered acceptance criteria with exact expected output end most disagreements before they start.
- Talk through a board, not through each other, and cap the review loop.
- The person who writes the tests should not be the agent who has to pass them.
None of this needs a framework. Two Markdown files in .claude/agents/, a spec and a status file are enough to copy the pattern into another project. If you want the bigger picture of where roles like these fit in a full delivery cycle, I keep a note on an AI-native SDLC with one agent per stage. For the earlier question of when one agent should become a team at all, see One agent, four tools.