# The live swarm

> How RaptorCode runs four specialist agents in parallel, each in its own git worktree, behind a live dashboard, and what you get when the run ends.

The swarm is RaptorCode's headline feature. One mission goes to four specialists that work at the same time, each on its own branch in its own git worktree, so they never touch your checkout or each other's files.

## Start a swarm

There are three ways in, and all of them need a git repository:

| How | Notes |
|---|---|
| Type a request in the REPL | After you grant consent, every request in a git repository becomes a swarm run. |
| `/swarm <mission>` in the REPL | Starts a run explicitly; also needs consent. |
| `raptor swarm run "mission"` | Needs an interactive terminal and is refused when `CI=true`, because confirmations appear on the dashboard. |

```bash
raptor swarm run "Add a /health endpoint, show its status on the page and cover it with tests"
```

## The four specialists

- **frontend-agent**: User interface components, styling, accessibility and client-side logic, with a clean, accessible default style.
- **backend-agent**: APIs, data models, persistence, business logic and integrations, validating external input and handling errors explicitly.
- **test-agent**: Unit and integration tests for the mission's critical paths, and makes sure the test commands actually run.
- **security-agent**: Reviews the attack surface, hardens configuration and inputs, and records findings and fixes in `SECURITY_NOTES.md`.

Each agent gets the same mission and is told to deliver its specialty's share of it. They start from the same commit and work independently.

## What happens during a run

#### 1. A task id is derived from the mission

The id is a slug of the mission text plus a hash. If a task or swarm with that id already exists, the run is refused: reword the mission to start a new one. (A request typed in the REPL falls back to a single agent instead.)

#### 2. Four branches and worktrees are created

One per role: branch `raptor/<task-id>/<role>` with its worktree under `.raptor/worktrees/<task-id>/<role>`. The worktrees start from your **last commit**, so uncommitted changes in your checkout are not visible to the agents. The summary tells you how many files that affected.

#### 3. The agents work in parallel

Each agent has its own DeepSeek session, its own context budget and its own [tool policy](https://raptorcode.dev/docs/security#tool-policy), rooted at its worktree: writes outside it ask for your confirmation. You watch them on the dashboard.

#### 4. The run ends with a summary

The summary lists each role's outcome, the files it wrote, its steps, its worktree and its final message, then the commands to review the work. The run is recorded in `.raptor/swarms/<task-id>.toml`.

## The dashboard

The dashboard shows a panel per agent with its status, files written, steps and a progress bar, and a footer with the number of live agents, the elapsed time and the tokens used.

| Key | Action |
|---|---|
| `y` / `n` | Answer a confirmation an agent is waiting on |
| `1` – `4` | Focus one agent's panel |
| `q` or `Esc` | Deny pending confirmations and stop the agents at their next step or tool call |

## Limits and failures

- Each agent has at most **100 steps**. A run that stops early keeps its work in the role worktrees for you to review; resuming a stopped swarm is not supported yet.
- A rejected key or an exhausted balance on one agent stops the others.
- An agent that crashes is recorded as failed without taking the others down.
- A swarm uses about four times the tokens of a single agent.

## After the run

All changes stay **uncommitted** in the role worktrees. Nothing is committed, merged or pushed for you:

```bash
raptor review <task-id>                 # status and changed files for every role
raptor diff <task-id> frontend-agent    # the full diff of one role
raptor test <task-id>                   # the detected test command in every role worktree
```

Then keep what you want with git. [Review and merge](https://raptorcode.dev/docs/review-and-merge) walks through it, including conflicts between roles.

## Clean up a run

There is no cleanup command for swarm runs yet. When you are done with one:

```bash
git worktree remove .raptor/worktrees/<task-id>/<role>   # add --force to discard uncommitted work
git branch -D raptor/<task-id>/<role>                    # for branches you no longer need
rm .raptor/swarms/<task-id>.toml
```

> **Tip:** `.raptor/` is listed in your repository's local `.git/info/exclude` when the first task or swarm is created, so worktrees and metadata never show up in `git status` or get committed by accident. No tracked file changes.

## Plan without executing

`raptor swarm "description"` creates the same four worktrees but only asks DeepSeek for a **plan** per role, written to `RAPTOR_PLAN.md`. Nothing is executed. See [Tasks and planning](https://raptorcode.dev/docs/tasks).
