Branchwell

Become a Pro / website · becomeapro.ai / content / lessons / knowledge-work / using-ai / run-a-team-of-agents.mdx

1---
2title: "Be the operator: run a team of Claude Code agents"
3description: "How one person runs several Claude Code agents at once: the rules file, the brief, parallel sessions, review steps and guardrails, and steering it all from your phone."
4level: Advanced
5minutes: 15
6updated: 2026-12-03
7order: 7
8sources:
9 - https://code.claude.com/docs/en/worktrees
10 - https://code.claude.com/docs/en/sub-agents
11 - https://code.claude.com/docs/en/hooks-guide
12 - https://code.claude.com/docs/en/remote-control
13 - https://code.claude.com/docs/en/computer-use
14 - https://code.claude.com/docs/en/chrome
15 - https://code.claude.com/docs/en/agent-teams
16 - https://code.claude.com/docs/en/permission-modes
17 - https://code.claude.com/docs/en/claude-projects
18 - https://code.claude.com/docs/en/agent-view
19 - https://code.claude.com/docs/en/commands
20 - https://code.claude.com/docs/en/permissions
21---
22
23AI is a force multiplier. With the right setup, one person can get through work that used to need a small team. We call that person the **operator**.
24
25The operator doesn't type most of the code. The operator splits the work into tasks, gives each task to its own Claude Code agent, and reviews what comes back. It uses a lot of tokens. In the hands of a skilled operator, it's worth it.
26
27This guide is the setup we use: a rules file every agent reads, a brief for each task, several sessions running side by side, and review steps before anything is merged.
28
29## What you need
30
31- Claude Code, signed in with a Pro, Max, Ultra, Team or Enterprise plan
32- A project in git with at least one commit, because parallel sessions use git worktrees
33- A test, build or lint command Claude can run to check its own work
34- About 30 minutes to set it up the first time
35
36Each agent uses its own tokens, so five agents use up your plan's limits roughly five times as fast as one. Start with two or three.
37
38## How the pieces fit
39
40<Diagram caption="You write the rules once and a brief per task. Each agent works in its own worktree, and you review before anything is merged.">
41 <svg viewBox="0 0 600 300" role="img" aria-label="CLAUDE.md rules and hooks apply to three agents, each in its own worktree, each with a brief from you, and all results come back to you for review">
42 <rect x="160" y="15" width="280" height="44" rx="8" className="soft" stroke="currentColor" strokeWidth="2" />
43 <text x="300" y="43" fontSize="15" textAnchor="middle" fill="currentColor">Rules (CLAUDE.md) and guardrails (hooks)</text>
44 <rect x="20" y="105" width="170" height="64" rx="8" fill="none" stroke="currentColor" strokeWidth="2" />
45 <text x="105" y="133" fontSize="15" textAnchor="middle" fill="currentColor">Agent 1</text>
46 <text x="105" y="155" fontSize="14" textAnchor="middle" fill="currentColor">own worktree</text>
47 <rect x="215" y="105" width="170" height="64" rx="8" fill="none" stroke="currentColor" strokeWidth="2" />
48 <text x="300" y="133" fontSize="15" textAnchor="middle" fill="currentColor">Agent 2</text>
49 <text x="300" y="155" fontSize="14" textAnchor="middle" fill="currentColor">own worktree</text>
50 <rect x="410" y="105" width="170" height="64" rx="8" fill="none" stroke="currentColor" strokeWidth="2" />
51 <text x="495" y="133" fontSize="15" textAnchor="middle" fill="currentColor">Agent 3</text>
52 <text x="495" y="155" fontSize="14" textAnchor="middle" fill="currentColor">own worktree</text>
53 <line x1="300" y1="59" x2="105" y2="103" stroke="currentColor" strokeWidth="2" />
54 <line x1="300" y1="59" x2="300" y2="103" stroke="currentColor" strokeWidth="2" />
55 <line x1="300" y1="59" x2="495" y2="103" stroke="currentColor" strokeWidth="2" />
56 <line x1="105" y1="169" x2="300" y2="225" stroke="currentColor" strokeWidth="2" strokeDasharray="6 5" />
57 <line x1="300" y1="169" x2="300" y2="225" stroke="currentColor" strokeWidth="2" strokeDasharray="6 5" />
58 <line x1="495" y1="169" x2="300" y2="225" stroke="currentColor" strokeWidth="2" strokeDasharray="6 5" />
59 <rect x="170" y="225" width="260" height="56" rx="8" fill="none" stroke="currentColor" strokeWidth="2" />
60 <text x="300" y="250" fontSize="15" textAnchor="middle" fill="currentColor">You: brief, review, merge</text>
61 <text x="300" y="270" fontSize="14" textAnchor="middle" fill="currentColor">terminal, desktop app or phone</text>
62 </svg>
63</Diagram>
64
65A **subagent** is a helper a session calls for a side job, like review, defined in `.claude/agents/`. **Hooks** are rules Claude Code enforces in `.claude/settings.json`, not just reads.
66
67## Step 1: Write the rules once
68
69Every agent reads `CLAUDE.md` at the start of every session, so it's where you write down what you'd otherwise repeat to each one. For a team of agents, the most useful rules say how to check the work, how to stay in its lane, and how to report back:
70
71```markdown
72# How to check your work
73- Run `npm test` and `npm run lint` before you say a task is done
74- In your summary, paste the command you ran and the last lines of its output
75
76# How we work
77- One task per session. If you find a second problem, tell me instead of fixing it
78- Stay in your own worktree. Never push to main
79- Ask before you add a dependency or change the database schema
80
81# When you finish
82- Summarize what changed in 3 to 5 bullets
83- List anything you skipped or couldn't check
84```
85
86Swap in your own commands. Our [CLAUDE.md guide](/knowledge-work/using-ai/claude-md-guide) covers where the file goes and how to check that Claude loaded it.
87
88## Step 2: Write the brief like a ticket
89
90A vague task gets a vague result. Give each agent a brief with a clear finish line:
91
92```prompt
93Task: [one sentence]
94Why: [the problem this solves]
95Done means: [the test or check that proves it works]
96Stay inside: [the files or folders it may change]
97Don't: [what to leave alone]
98Before you change anything, show me a short plan and wait for my OK.
99```
100
101Here's one filled in:
102
103```prompt
104Task: Fix the order dates that show one day early for customers in Asia.
105Why: Dates are converted to UTC twice before they're displayed.
106Done means: A new test for a Tokyo customer passes, and npm test passes.
107Stay inside: src/lib/dates.ts and its tests.
108Don't: Change the database or any API responses.
109Before you change anything, show me a short plan and wait for my OK.
110```
111
112| Vague | Clear |
113| --- | --- |
114| Fix the dates | Fix the order dates that show one day early in Asia |
115| Make sure it works | A new test for a Tokyo customer passes |
116| Clean up the code | Stay inside `src/lib/dates.ts` and its tests |
117
118The last line of the brief puts a review step before any edit. You can also start the session in plan mode, covered in Step 5.
119
120## Step 3: Run agents side by side
121
122Two agents editing the same folder will overwrite each other's work. Claude Code solves this with git worktrees: each session gets its own separate copy of the project. Open a terminal for each task:
123
124```bash
125claude --worktree fix-date-bug
126claude --worktree add-checkout-tests
127claude --worktree update-docs
128```
129
130`-w` is the short form. Each worktree lives in `.claude/worktrees/<name>/`. Add `.claude/worktrees/` to your `.gitignore`. When you exit a session and the worktree has changes or new commits, Claude Code asks whether to keep or remove it. A clean worktree can be removed for you. Gitignored files such as `.env` don't count as changes, so copy out anything you need first. Paste a brief into each session and let them work.
131
132If you'd rather not keep a terminal open for every agent, start them in the background and check on them from one place:
133
134```bash
135claude --bg "Fix the order dates that show one day early in Asia. Done means npm test passes."
136claude agents
137```
138
139`claude agents` opens agent view, where you can see every background session grouped by state, peek at its latest output, reply, or attach to the full conversation. Agent view is a research preview, so details may change.
140
141<Callout type="note">
142Claude Code also has agent teams, where one session leads and other sessions work as teammates that message each other. It's experimental, off by default, and uses many more tokens. Start with worktrees, and see Anthropic's agent teams page when you outgrow them.
143</Callout>
144
145## Step 4: Give side jobs to subagents
146
147A subagent is a helper that a session calls for one focused job, with its own context window and its own tools. A reviewer is the most useful one to start with, because it checks work with fresh eyes. Save this as `.claude/agents/reviewer.md` in your project:
148
149```markdown
150---
151name: reviewer
152description: Reviews a finished change for bugs, missing tests and edits outside the task. Use after a task is done and before it is merged.
153tools: Read, Glob, Grep, Bash
154model: sonnet
155---
156
157You review changes. Read the diff against main and run the tests, then report:
1581. Bugs or risky edits, with the file and line
1592. Missing tests
1603. Anything that doesn't match the task
161Don't edit any files. Report only.
162```
163
164Then, in any session:
165
166```prompt
167Use the reviewer subagent to check this work before I merge it.
168```
169
170The `model` line lets a helper run on a smaller, cheaper model than the main session. Anthropic's subagents page lists every field.
171
172## Step 5: Add guardrails Claude Code enforces
173
174A line in `CLAUDE.md` works most of the time. For anything that must never happen, use settings that Claude Code enforces whatever the model decides.
175
176### Pick a permission mode
177
178New terminal sessions start in Auto. Press `Shift+Tab` in a session to switch modes, or start with a flag such as `claude --permission-mode plan`.
179
180| Mode | What it does | Use it for |
181| --- | --- | --- |
182| Auto | A separate model checks each action and blocks risky ones | Long tasks where prompts would stall the work |
183| Manual | Asks before most edits and commands | Getting started, or any risky task |
184| Accept edits | Edits files without asking, still asks for most commands | Agents you trust on a small task |
185| Plan | Reads and plans, but edits stay blocked until you approve the plan | Checking an agent's plan before it starts |
186
187Auto mode needs a supported model, and Team and Enterprise admins can turn it off. If it isn't available, a session starts in Manual. Anthropic's permission modes page has the details.
188
189### Block what must never happen
190
191Hooks are commands Claude Code runs at fixed points. A `PreToolUse` hook runs before every tool call, and if it exits with code 2, the call is blocked. This one stops force pushes and pushes to main. Add it to `.claude/settings.json`:
192
193```json
194{
195 "hooks": {
196 "PreToolUse": [
197 {
198 "matcher": "Bash",
199 "hooks": [
200 {
201 "type": "command",
202 "command": "\"$CLAUDE_PROJECT_DIR\"/.claude/hooks/block-risky-git.sh"
203 }
204 ]
205 }
206 ]
207 }
208}
209```
210
211Then save this script as `.claude/hooks/block-risky-git.sh` and run `chmod +x` on it. It needs `jq`:
212
213```bash
214#!/usr/bin/env bash
215# Stops force pushes and pushes to main. Exit code 2 blocks the command,
216# and Claude sees the message on stderr.
217cmd=$(jq -r '.tool_input.command // ""')
218if echo "$cmd" | grep -Eq 'git push.*(--force|-f( |$))|git push.* main( |$)'; then
219 echo "Blocked: no force pushes and no pushes to main. Open a pull request instead." >&2
220 exit 2
221fi
222exit 0
223```
224
225We tested it with sample commands. It blocks `git push origin main`, `git push -f` and `git push --force-with-lease`, and allows `git push -u origin worktree-add-tests` and `git push origin main-menu-fix`. PreToolUse hooks run before the permission mode is checked, so this block holds in every mode.
226
227### Get a ping when an agent needs you
228
229With several agents running, you won't be watching each one. On a Mac, this `Notification` hook shows a system notification whenever Claude Code is waiting for you. Add it inside the same `"hooks"` object:
230
231```json
232"Notification": [
233 {
234 "matcher": "",
235 "hooks": [
236 {
237 "type": "command",
238 "command": "osascript -e 'display notification \"Claude Code needs your attention\" with title \"Claude Code\"'"
239 }
240 ]
241 }
242]
243```
244
245## Step 6: Review before you merge
246
247Reviewing is the operator's real job. Before you merge anything, ask for evidence, not a promise:
248
249```prompt
250Show me what you changed: a short summary of the diff, the test command you ran with its output, and anything you couldn't check. Don't merge anything yet.
251```
252
253If it looks right, ask the agent to commit and open a pull request. If it doesn't, say what's wrong in one or two sentences. After two failed corrections, it's usually faster to run `/clear` and write a better brief than to try a third time.
254
255## Run it from your phone
256
257Your agents don't need you at the desk. Remote Control connects the Claude app on your phone to a Claude Code session running on your own computer, so you can send prompts, read results and steer from anywhere.
258
259Start a session with Remote Control on:
260
261```bash
262claude --remote-control
263```
264
265Or turn it on in a session that's already open with `/remote-control` (or `/rc`). Then open the Claude app on your phone and go to the **Code** tab. Run `/mobile` in Claude Code for a QR code that gets you the app.
266
267- **Plans:** Remote Control works on Pro, Max, Ultra, Team and Enterprise. On Team and Enterprise, an owner has to turn it on first. It doesn't work with an API key.
268- **Your computer stays on.** The session runs on your machine, so the computer has to stay on with Claude Code running. If it sleeps or the network drops, the session reconnects when the machine is back online.
269- **Talk instead of typing.** Your phone's dictation works in the prompt box, so you can speak each brief.
270
271<Callout type="tip">
272Claude Code's Projects take this further: one project conversation splits work into threads that run in parallel, mostly as cloud sessions, and you can check and steer every thread from your phone. Projects are a public beta on Pro, Max, Ultra, Team and Enterprise. They are rolling out gradually on individual plans, and on Team and Enterprise an owner has to turn them on. See Anthropic's Projects page.
273</Callout>
274
275## Watch your token use
276
277Running agents in parallel spends your plan's limits faster. Check where it's going:
278
279- `/usage` shows your plan's usage limits and an estimate for the current session. `/cost` and `/stats` open the same screen.
280- `/context` shows what's filling the current session's context window.
281
282To spend less: keep one task per session, run `/clear` before starting a new task in the same session, put helpers on a smaller model, and stop background agents you no longer need.
283
284## When it goes wrong
285
286| If you see | Do this |
287| --- | --- |
288| An agent drifts into other work | Press `Esc`, restate the task, and keep one task per session |
289| It says "done" but never ran the tests | Make "Done means" a command, and ask for its output |
290| Two agents change the same files | Give each one a worktree and a "Stay inside" line |
291| Your limits run out fast | Run fewer agents at once, and put helpers on a smaller model |
292| You type the same correction every day | Add it to `CLAUDE.md` |
293| Something must never happen | Use a hook, not a line in `CLAUDE.md` |
294
295## Your first week as an operator
296
2971. **Write the brief like a ticket.** A task, a reason, and a finish line Claude can check.
2982. **Give each agent one job.** One task, one session, one worktree.
2993. **Make every result easy to review.** Ask for the diff, the test output and what was skipped, every time.
300
301Start with two agents on small, separate tasks. Add a third once reviewing the first two feels easy.
302
303## How we checked this
304
305We checked every command, flag and setting on this page against Anthropic's Claude Code documentation on December 3, 2026, and ran the hook script on sample commands. Agent view, agent teams and Projects are previews, experiments or betas, so check Anthropic's pages if something looks different.
306
307## Keep going
308
309New to the rules file? Start with [How to write a CLAUDE.md that Claude Code follows](/knowledge-work/using-ai/claude-md-guide). For more on agents that drive a screen, read [What computer-use agents can do, and how to run them safely](/knowledge-work/using-ai/what-is-computer-use), then [Let Claude Code drive a browser with Playwright MCP](/knowledge-work/using-ai/playwright-mcp-claude-code).