AI coding
Claude Code
AI agents
git worktree
subagents
developer tools
productivity

Stop Running One AI Agent at a Time: How to Spawn and Maintain a Team of Dev Agents

By Job Fit Studio · · 10 min read

90% of professional developers now use AI coding agents at work every week, and 68% use them every day, according to JetBrains' 2026 Developer Ecosystem Survey of more than 15,000 developers.

But look at how most of us actually use them: one terminal, one agent, and us watching it type. While it works, we wait. When it gets stuck, we notice ten minutes later.

The jump from "I use an AI agent" to "I run a team of agents" isn't about a smarter model. It's about setup. You need a way to spawn several agents without them stepping on each other, and a way to maintain them so they get better over time instead of repeating the same mistakes.

This guide covers both, in five steps, with the exact commands. The examples use Claude Code, but the ideas carry over to any agent tool.

In this guide

  1. The 5 steps at a glance
  2. Step 1: One agent, one worktree
  3. Step 2: Hand it off and walk away
  4. Step 3: One job, fewest tools
  5. Step 4: Fix the file, not the chat
  6. Step 5: Watch the bill
  7. A day with a three-agent team
  8. Common mistakes
  9. Your 15-minute setup
  10. Sources

The 5 steps at a glance

#StepPartWhat it solvesThe command or file
1One agent, one worktreeSpawnAgents overwriting each other's filesclaude --worktree <name>
2Hand it off, walk awaySpawnBabysitting every sessionclaude --bg "task" and claude agents
3One job, fewest toolsMaintainAgents doing too much, or the wrong thing.claude/agents/<name>.md with a tools list
4Fix the file, not the chatMaintainRepeating the same correction every sessionOne new line in CLAUDE.md
5Watch the billMaintainToken use that grows with every agentclaude stop / claude rm, tidy worktrees

Step 1: One agent, one worktree

The first thing that breaks when you run two agents is the files. Agent A is halfway through refactoring auth.ts when agent B opens the same file to fix a bug. One of them loses.

The fix is a git worktree: a second (or third, or tenth) checkout of the same repository, on its own branch, in its own folder. Worktrees share your git history, so they're quick to create and don't copy the whole repo.

Claude Code creates and enters one for you:

# terminal 1
claude --worktree feature-auth

# terminal 2
claude --worktree fix-billing

Each session gets its own folder under .claude/worktrees/<name>/ and its own branch. They can both edit freely and never touch each other's files. When you're done, you review and merge each branch like any other.

Bring your secrets along. A worktree is a fresh checkout, so gitignored files like .env aren't there. Add a .worktreeinclude file at your repo root, written in .gitignore syntax, and Claude Code copies matching files into every new worktree:

.env
.env.local

What worktrees don't isolate. They separate files, branches and the git index. They don't separate anything outside the checkout. If every agent starts your API on port 3000, the second one fails. If they all point at the same local Postgres, they'll run each other's migrations. Give each worktree its own port and database name in your setup script if your agents run servers or tests that touch a database.

Cleanup is mostly automatic. When you exit a worktree session, Claude Code removes a clean worktree for you and asks before deleting one that still has work in it. To check by hand:

git worktree list
git worktree remove .claude/worktrees/feature-auth

Step 2: Hand it off and walk away

Worktrees let agents work side by side. But if you still have to sit in front of each terminal, you've just multiplied the babysitting.

The second step is to run agents in the background and check on them from one place. In Claude Code, that's agent view (a research preview):

claude --bg "fix the flaky checkout tests"   # start a background session
claude agents                                 # open agent view

Agent view lists every session with its state, such as Working, Needs input, Idle or Completed, so you can see at a glance which one actually needs you. From there:

  • Press Enter on a row (or run claude attach <id>) to jump into a session.
  • Press Ctrl+X (or run claude stop <id>) to stop one.
  • Press Ctrl+X again (or run claude rm <id>) to remove it.

Sessions you start from agent view move into their own worktree before they edit any files, so Step 1 happens for you.

How to hand off well. A background agent can't ask you a quick question while you're in a meeting, so give it what it needs up front:

  • The goal, in one sentence. "Make the checkout tests pass reliably."
  • Where to look. "The flaky ones are in tests/checkout/."
  • How to know it's done. "Run pnpm test checkout ten times in a row with no failures."
  • What not to touch. "Don't change the payment provider mocks."

A clear "done" check is the most important line. Without it, the agent stops when it thinks it's done.


Step 3: One job, fewest tools

Once agents run on their own, their instructions matter more. The Claude Code docs give two rules for custom agents (subagents) that are worth following everywhere: design focused agents that each excel at one task, and grant only the tools they need.

A subagent is a Markdown file in .claude/agents/. Here's a reviewer that can read code but can't change it:

---
name: reviewer
description: Reviews a diff for bugs, missing tests and risky changes. Use after an agent finishes a task, before merging.
tools: Read, Grep, Glob
model: sonnet
---

You are a code reviewer. You can read the code but you cannot change it.

When invoked:
1. Read the diff and the files it touches.
2. Look for bugs, missing or weak tests, unhandled errors, and security risks.
3. Check the change against the rules in CLAUDE.md.

Reply with a short list, most serious first. For each item give the file and line,
what is wrong, and the fix you suggest. If everything looks good, say so in one line.

A few things to notice:

  • tools: Read, Grep, Glob is an allowlist. Without Edit or Write, a reviewer can't "helpfully" rewrite the code it's supposed to judge. If you leave tools out, the agent gets every tool.
  • description is how Claude decides when to use this agent. Make it specific enough that it can't be confused with your other agents.
  • model: sonnet keeps a read-only job on a cheaper model.

Other useful fields: disallowedTools to remove one tool (like Bash) while keeping the rest, isolation: worktree to give a subagent its own worktree, and maxTurns to cap how long it runs.

Commit .claude/agents/ to git. Then your whole team gets the same agents, and changes to them go through review like any other code.


Step 4: Fix the file, not the chat

Here's the habit that separates agents that get better from agents that don't.

When an agent gets something wrong, the natural move is to correct it in the chat: "No, use pnpm, not npm." It works for that session. Then the session ends, the correction is gone, and tomorrow's agent makes the same mistake. Run five agents in parallel and you'll make that correction five times.

Instead, put the correction in a file every agent reads. For project-wide rules, that's CLAUDE.md, which loads into every session. For rules that only apply to one agent, put them in that agent's own file.

A simple pattern is a "Lessons" section:

## Lessons (rules agents keep getting wrong)
- Use pnpm, never npm.
- Run `pnpm test` before you say a task is done.
- Don't edit files in `generated/`; change the schema and regenerate.
- New API routes need an integration test in `tests/api/`.

A good rule of thumb: the second time you correct an agent for the same thing, add a line.

And keep it short. CLAUDE.md loads every session, so every line costs tokens on every agent. Each line should be a rule an agent would actually get wrong without it. Delete rules that no longer apply, and move long, task-specific instructions (like a full release checklist) into a skill or a dedicated agent, which only load when needed.


Step 5: Watch the bill

The Claude Code docs say it plainly: running several sessions or subagents at once multiplies token usage. Four agents working for an hour cost roughly four times what one does. That's often worth it, since you get four tasks done, but idle agents and forgotten sessions cost you for nothing.

Three habits keep it under control:

  1. Close what's done. When a session finishes, stop and remove it (claude stop <id>, claude rm <id>, or Ctrl+X in agent view). Done sessions shouldn't sit around.
  2. Match the model to the job. Reviewers, searchers and test runners rarely need your most expensive model. Set model: sonnet or model: haiku in their agent files.
  3. Don't parallelize what's sequential. If task B needs task A's result, running them side by side just means B guesses and gets redone. Parallel agents pay off for independent tasks.

A day with a three-agent team

Here's what this looks like in practice on a normal workday.

9:00. You look at your board and pick three independent tasks: add Google login, fix a billing rounding bug, and clean up flaky checkout tests.

9:05. You start them:

claude --bg "Add Google login. Follow the existing GitHub login in src/auth/. Done when pnpm test auth passes and the login page shows both buttons."
claude --bg "Fix the rounding bug in invoice totals (issue #412). Add a test that fails before the fix."
claude --bg "Make tests in tests/checkout/ pass 10 runs in a row. Don't change the payment mocks."

9:06 to 10:30. You do your own work. You open claude agents twice. Once, the billing agent shows Needs input: it found two places that round differently and asks which is correct. You answer in one line and leave.

10:30. The login agent is done. You run the reviewer agent on its branch. It flags a missing test for the error case. You send that back to the login agent.

10:45. The checkout agent used npm install and broke the lockfile. It's the second time this week. You add - Use pnpm, never npm. to the Lessons section of CLAUDE.md. No agent makes that mistake again.

11:00. Two branches are reviewed and merged. You close those sessions, and their worktrees get cleaned up.

Three tasks done before lunch, and most of your morning was your own.


Common mistakes

  • Running parallel agents in the same folder. This is how agents overwrite each other. Use worktrees.
  • Vague hand-offs. "Fix the tests" invites guessing. Give the goal, the place, the done check and the no-go zones.
  • One giant agent that does everything. It's harder to steer and harder to trust. Split it into focused agents with fewer tools.
  • Correcting in chat only. If you've said it twice, write it down in CLAUDE.md.
  • Never cleaning up. Old sessions and worktrees pile up and keep using tokens and disk.
  • Skipping review. More agents means more code. Review every branch before it merges, or have a read-only reviewer agent do a first pass.

Your 15-minute setup

  1. Add .worktreeinclude to your repo root with .env and any other local config your app needs.
  2. Try two worktrees: run claude --worktree task-a and claude --worktree task-b in two terminals on two small, independent tasks.
  3. Try one background session: claude --bg "<a small task with a clear done check>", then open claude agents.
  4. Create a reviewer: save the reviewer file above as .claude/agents/reviewer.md, and commit it.
  5. Add a Lessons section to CLAUDE.md with the one rule your agents get wrong most often.
  6. End the day by closing finished sessions and running git worktree list.

Once this feels normal, add more agents. Two agents with a good setup beat five without one.


Sources

Commands and features were checked against the Claude Code docs on November 14, 2026. Agent view is a research preview, so details may change.

More guides