# Autopilot rules

URL: https://codepanel.ai/docs/autopilot

Rules that start agent tasks on their own from CI failures, stalled pull requests, Dependabot, issue labels and schedules, with caps and Stop everything.

An autopilot rule starts a task on its own when something happens on a repository: CI fails, a pull request sits with open findings, Dependabot opens a pull request, an issue gets a label, or a schedule comes round. The task runs on your [local runner](/docs/desktop-app) like one you started, and its pull request is reviewed like any other. Nothing waits for your approval; caps bound what a rule can spend, and Stop everything halts it all at once.

## Triggers

| Trigger | When | Its one setting | Placeholders its prompt can use |
| --- | --- | --- | --- |
| `ci_failed` | A workflow run on the repository's own default branch ends `failure`, `timed_out` or `startup_failure` | none | `{{branch}}`, `{{sha}}`, `{{check}}`, `{{log_url}}` |
| `pr_ci_failed` | A workflow run on a same-repo pull request branch ends `failure`, `timed_out` or `startup_failure` | none | `{{pr}}`, `{{branch}}`, `{{sha}}`, `{{check}}`, `{{log_url}}` |
| `review_blocked` | A CodePanel review posts blocking findings on a pull request | none | `{{pr}}`, `{{pr_title}}`, `{{pr_url}}`, `{{sha}}`, `{{findings}}`, `{{refs}}` |
| `pr_stalled` | An open pull request has open CodePanel findings and no push since its review | `idleMinutes`: 15 to 10,080, default 90 | `{{pr}}`, `{{pr_title}}`, `{{pr_url}}`, `{{sha}}`, `{{findings}}` |
| `dependabot_pr` | Dependabot opens a pull request | none | `{{pr}}`, `{{pr_title}}`, `{{pr_url}}`, `{{branch}}` |
| `issue_labeled` | An issue (not a pull request) is given the label | `label`, default `agent` | `{{issue}}`, `{{issue_title}}`, `{{issue_url}}`, `{{label}}` |
| `schedule` | A five-field cron in UTC comes round, at most 4 times an hour | `schedule`, such as `0 2 * * *` (required) | none beyond the common two |
| `webhook` | An authenticated HTTP POST arrives at the rule's webhook URL | none (mints a bearer token) | `{{event_id}}`, `{{source}}`, `{{title}}`, `{{severity}}`, `{{url}}`, `{{payload}}` |

Every prompt can also use `{{repo}}` and `{{rule}}`. A placeholder the trigger does not fill is refused when the rule is saved, so a misspelling never reaches an agent. Each trigger has a default prompt, so a rule needs nothing but its trigger.

CI on a pull request does not count, even from a fork's branch named `main`: only the default branch's own runs fire `ci_failed`. The webhook events come from the repository's hook or the GitHub App; a repository connected before rules existed needs reconnecting to send `workflow_run` and `issues`.

## Make a rule

In the desktop app, **Autopilot** (sidebar) → **New rule**: pick the trigger, its setting, the repositories it watches (all by default), the prompt, who works it and the caps. The toggle on each row turns it on or off; **Edit** changes anything but the trigger.

| Setting | Default | Range |
| --- | --- | --- |
| Repositories | All connected | Any of them |
| Worked by | Auto: the repository's team, else the default team, else the first agent | An agent or a team |
| Dollars one task may spend (`taskUsd`) | $2 | $0.10 to $50 |
| Dollars its tasks may spend in a UTC day (`dayUsd`) | $10 | $0.10 to $500, at least `taskUsd` |
| Its tasks running at once (`maxConcurrent`) | 2 | 1 to 10 |

An account holds up to 50 rules. Each row shows the rule's last 7 days: tasks started, how many ended, how many of their pull requests merged, the spend, and the last event with why it was skipped, if it was.

From an agent:

| Action | MCP | CLI |
| --- | --- | --- |
| List | [`list_rules`](/docs/mcp-server/list_rules) | `codepanel rules` |
| Create | [`create_rule`](/docs/mcp-server/create_rule) | `codepanel rules create <trigger> [--repo a/b] [--prompt ...]` |
| Change, on, off | [`update_rule`](/docs/mcp-server/update_rule) | `codepanel rules update\|enable\|disable <ruleId>` |
| Delete | [`delete_rule`](/docs/mcp-server/delete_rule) | `codepanel rules delete <ruleId>` |

Writes need the `tasks:write` scope, since a rule is standing permission to queue tasks.

## What a rule does on its own

1. **An event arrives.** Each rule keeps one event per repository and key (a commit's CI failure, a pull request at a head, an issue and label, a schedule tick). Redeliveries and a second failing workflow on the same commit join the event already waiting; one that already started a task changes nothing.
2. **It waits briefly.** 60 seconds for CI, 30 for Dependabot and labels, so a burst settles into one task.
3. **The gates.** The rule is on; agents are not paused; the account has a plan; the repository is connected; the account's day cap and the rule's `dayUsd` are not spent. A refusal skips the event and records why. `maxConcurrent` is the one gate that waits: the event tries again every 5 minutes for up to an hour.
4. **The task is queued** with the rule's prompt filled from the event, ending with which rule started it and why. Its budget is the rule's `taskUsd`, under the worker's own cap. The thread's header names the rule, and [`get_task`](/docs/mcp-server/get_task) shows `origin: "rule:<ruleId>"` and the trigger.
5. **The runner works it.** On an open pull request (`pr_stalled`, `dependabot_pr`), the run starts from the pull request's head and pushes onto its branch when it can; otherwise its work becomes a new pull request ([What gets pushed](/docs/desktop-app#what-gets-pushed)).

Event text such as an issue title can come from anyone, so the prompt marks it as data, not instructions, and a rule's run starts from the `strict` rules: every edit and command asks unless allowed. An edit to a file that defines what a project command runs (`package.json`, a Makefile, `scripts/`) makes every command ask again until one that runs a script is allowed. These runs also have no network, their dependency install included, unless you allow it for the repository in the desktop app's Settings → Runners ([The sandbox](/docs/desktop-app#the-sandbox)); their dependencies install offline from your package cache, and a run that cannot install them that way waits in the Inbox as **Needs network**.

## When a rule turns itself off

As a rule's task ends, a success clears its failure streak and a failure adds one; a task you stopped counts as neither. After 3 failures in a row the rule turns itself off, saying why. It then waits in the Inbox as a **Rule off** item until you turn it back on, edit it or delete it; the item's `nextAction` is `update_rule` with `enabled: true`.

## Guardrails

The Autopilot page's **Guardrails** lists every limit on the account's runs, rule-started or not:

| Limit | Value | Set where |
| --- | --- | --- |
| Runs at once | 1 per runner; the rest queue | Fixed |
| Daily spend cap | $25 by default, up to $1,000, per UTC day, across all runs | Guardrails, Settings → Budgets & limits, [`set_agent_day_cap`](/docs/mcp-server/set_agent_day_cap), `codepanel autopilot day-cap <usd>` |
| Per-task cap | The agent's budget, else $5 | The agent, or the team's cap per task |
| Per-ticket cap | None by default; up to $1,000 across every run of one ticket (a task's `ticket`) | [`set_agent_day_cap`](/docs/mcp-server/set_agent_day_cap) `ticketUsd`, `codepanel autopilot ticket-cap <usd>` or `off` |
| Allowed commands | The checkout's checks; everything else asks | Settings → Runners & worktrees, and [Always allow](/docs/run-control#always-allow) |
| Auto-merge | Not available: merging a run's pull request is left to you | |

The model proxy enforces the caps on every call, so a run cannot spend past them. When a run hits one, it stops and waits in the Inbox ([Budget stops](/docs/run-control#budget-stops)). Tokens are charged at cost ([Agent runs](/docs/billing#agent-runs)).

## Stop everything

**Stop everything** pauses every agent on the account. Press it twice: in the Autopilot page's title bar, or ⌘⇧. from any page of the app (the first press arms it, the second within four seconds stops; Esc disarms). It:

- stops every run in progress (each task stays, and can be retried);
- refuses new tasks, new runs and every model call until you resume;
- leaves queued tasks queued: they run once you resume.

Rules skip their events while paused. **Resume agents** lifts it. The same switch is [`pause_agents`](/docs/mcp-server/pause_agents) and [`resume_agents`](/docs/mcp-server/resume_agents) over MCP, and `codepanel autopilot pause [--reason <text>]` and `codepanel autopilot resume` in the CLI; [`get_agents_pause`](/docs/mcp-server/get_agents_pause) says whether it is on, since when and by whom.

To hold one run without stopping the rest, pause it instead ([Run control](/docs/run-control#pause-and-resume)).
