# apply_panel

URL: https://codepanel.ai/docs/mcp-server/apply_panel

The CodePanel MCP tool that builds and writes the panel for a cost and quality goal, to one repository's own panel with repo, and returns an undo.

`apply_panel` builds the panel for a goal and writes it: it recomputes `get_panel_recommendation` for the same arguments, edits the matching seats in place, changes the orchestrator's model and returns an `undo` that `restore_panel` can replay. With `repo`, it creates or changes only that repository's own panel. It needs the `panel:write` scope.

## When to call it

- **After `get_panel_recommendation`**, with the same arguments, once you have read what it would change. The apply does not take the recommendation you saw. It computes a fresh one, so it matches only if your keys and the repository's history have not changed in between.
- **To set up a repository without touching the others.** With `repo`, your default panel and every other repository stay as they are.
- **To fit a spending limit.** `maxUsdPerPr` becomes the panel's per-pull-request limit.

Keep the `undo`. It is the only way to put the panel back in one call.

## Inputs

| Input | Type | Required | Description |
| --- | --- | --- | --- |
| `cost` | `low` or `medium` or `high` | no | How much to spend: picks the model tiers. Default medium |
| `quality` | `low` or `medium` or `high` | no | How thorough: picks the roles and effort. Default medium |
| `repo` | string | no | Set up this repository alone, priced from its own recent rounds |
| `panelId` | string | no | Without repo: the panel to change; default panel if left out |
| `roles` | array of strings | no | Role ids from list_roles, instead of the goal's |
| `provider` | string | no | Keep every seat on this provider |
| `maxUsdPerPr` | number | no | Spend at most this per pull request; apply also sets it as the panel's limit |

It writes: the server marks it `readOnlyHint: false` and `destructiveHint: true` (it can change what is already there), so a client that asks before writes asks here.

The inputs are the same as for [`get_panel_recommendation`](/docs/mcp-server/get_panel_recommendation), and so are its errors. What is particular to the write:

- **`repo`.** The write goes to that repository's own panel. If it has none, it is given one: a copy of the panel it uses today, with copies of its seats. Your default panel and other repositories are not changed. If the repository already has its own panel, that panel is edited.
- **No `repo`.** The write goes to `panelId`, or your default panel. Every repository that reviews with that panel gets the change.
- **Nothing to change.** When `unchanged` is `true`, no seat is written, and a repository with no panel of its own is not given one. With `maxUsdPerPr`, the limit alone is written, to the repository's own panel, created if needed.
- **`maxUsdPerPr` and `budget.fits`.** The limit is written even when the plan could not be cut to fit. Reviews then stop at the limit instead of running past it, so check `budget.fits` in `get_panel_recommendation` first.
- **`roles`.** An explicit lineup may add or remove seats. `recommendation.changes` lists each one and why.

## What it returns

- `panelId`: the panel that was written. For a repository that had no panel of its own, it is the new one.
- `repo`: the repository, or `null`.
- `recommendation`: exactly what `get_panel_recommendation` returns for these arguments, as it stood when applied. `current` is the panel before the write.
- `undo`: the panel as apply found it: its `panelId`, `reviewerIds`, `reviewerModels` (each seat's name, provider, model, effort and tier following), the `orchestrator` model and effort, and `budgetUsd` (a number, `null` for no limit, or `"default"` for the default limit).

Matching seats are edited in place and keep their instructions and history. A seat in the recommendation that has no match is created. A seat that is not in it is taken off the panel. When apply copies a repository's panel, the copies have new ids, so the `agentId` values in `recommendation.reviewers` name the seats of the panel it copied, while `undo.reviewerIds` names the copies. `undo.panelId` is always the panel that was written.

## Examples

These responses come from a test account on a local backend. Model ids and prices are seed values, not real prices.

### Give a repository its own cheaper panel

```json title="Call"
{
  "repo": "codepanel-dev/web-app",
  "cost": "low",
  "quality": "medium"
}
```

The real result is about 7 KB. This copy keeps the first of four reviewers in `changes`, `reviewers` and `current`, leaves out `budget`, `comparison` and `estimate` (they have the shape shown for `get_panel_recommendation`), and cuts each `reason` after its first sentence. The `undo` is whole.

```json title="Result (trimmed)"
{
  "panelId": "vs79t2rrpcvekcnsk7n9cq0d598j6jcv",
  "recommendation": {
    "changes": [
      "Retain Bugs & Security (k57f28zq4gs6631q0x3yrpb54s8j704w): keep its instructions and history; use anthropic/claude-haiku-5-5 at medium effort."
    ],
    "current": {
      "orchestrator": {
        "agentId": "k5775rqpcnqr3m3mz31d47xr5h8j7kcm",
        "modelId": "claude-opus-5-5",
        "name": "Orchestrator",
        "provider": "anthropic",
        "reasoningEffort": "high"
      },
      "reviewers": [
        {
          "agentId": "k57f28zq4gs6631q0x3yrpb54s8j704w",
          "modelId": "claude-sonnet-5-5",
          "name": "Bugs & Security",
          "provider": "anthropic",
          "reasoningEffort": "medium"
        }
      ]
    },
    "goal": {
      "cost": "low",
      "quality": "medium"
    },
    "nextAction": "apply",
    "orchestrator": {
      "model": "Sonnet 5.5",
      "modelId": "claude-sonnet-5-5",
      "provider": "anthropic",
      "reason": "Balanced orchestrator: …",
      "reasoningEffort": "medium",
      "source": "own_key",
      "tier": "balanced",
      "usdPerRound": 0.026399999999999996
    },
    "repo": "codepanel-dev/web-app",
    "reviewers": [
      {
        "agentId": "k57f28zq4gs6631q0x3yrpb54s8j704w",
        "model": "Haiku 5.5",
        "modelId": "claude-haiku-5-5",
        "name": "Bugs & Security",
        "provider": "anthropic",
        "reason": "Kept this existing seat, its instructions and history. …",
        "reasoningEffort": "medium",
        "role": "bugs-security",
        "source": "own_key",
        "tier": "economy",
        "usdPerRound": 0.002975
      }
    ],
    "target": {
      "note": "Applying gives codepanel-dev/web-app its own panel; your default panel and other repositories are not changed.",
      "panelId": null,
      "scope": "repo"
    },
    "unchanged": false
  },
  "repo": "codepanel-dev/web-app",
  "undo": {
    "budgetUsd": 3,
    "orchestrator": {
      "modelId": "claude-opus-5-5",
      "provider": "anthropic",
      "reasoningEffort": "high"
    },
    "panelId": "vs79t2rrpcvekcnsk7n9cq0d598j6jcv",
    "reviewerIds": [
      "k57d5rxa4vmsh7qxnwnyefv6018j6rp3",
      "k57bzxc9gr8xh9wsk0bgg5t4bh8j7dbf",
      "k571gqg6dpptezyyth0fakme6s8j640z",
      "k57228bdncm44ms17e7pvmwr2d8j6j3x"
    ],
    "reviewerModels": [
      {
        "agentId": "k57d5rxa4vmsh7qxnwnyefv6018j6rp3",
        "modelId": "claude-sonnet-5-5",
        "name": "Bugs & Security",
        "provider": "anthropic",
        "reasoningEffort": "medium"
      },
      {
        "agentId": "k57bzxc9gr8xh9wsk0bgg5t4bh8j7dbf",
        "modelId": "gpt-5.4-mini",
        "name": "Tests & Maintainability",
        "provider": "openai",
        "reasoningEffort": "low"
      },
      {
        "agentId": "k571gqg6dpptezyyth0fakme6s8j640z",
        "modelId": "gemini-3.8-flash",
        "name": "Docs & Best Practices",
        "provider": "google",
        "reasoningEffort": "low"
      },
      {
        "agentId": "k57228bdncm44ms17e7pvmwr2d8j6j3x",
        "modelId": "grok-4.7",
        "name": "Design & UX",
        "provider": "xai",
        "reasoningEffort": "low"
      }
    ]
  }
}
```

Read it as follows:

- `target.panelId` was `null`, so this repository had no panel of its own. `panelId` is the new one, and `undo.panelId` is the same id.
- `recommendation.reviewers[].agentId` (`k57f28…`) names the default panel's seats. `undo.reviewerIds` (`k57d5r…` and the rest) names the copies the repository now owns. The `reviewerModels` in `undo` hold what those copies ran before the write, which is what the default panel's seats were running.
- `undo.budgetUsd` is `3`: the limit at the time. It matches the limit the [`update_panel`](/docs/mcp-server/update_panel) example set.
- `undo.orchestrator` has `reasoningEffort: "high"` while the recommended one has `medium`: the orchestrator is changed in the same write.

Pass `undo` to [`restore_panel`](/docs/mcp-server/restore_panel) to put these settings back. It restores the panel's seats and limit. It does not unpin the repository from its new panel.

## The same step without MCP

| Surface | Form |
| --- | --- |
| CLI | `codepanel panel apply --cost low --quality medium --repo owner/name`. It prints the command that undoes it ([CLI](/docs/cli#panels-models-and-keys)) |
| HTTP API | [`POST /panels/apply`](/docs/api#post-panelsapply) with the same fields |

## What the server tells your agent

The description your agent reads when it lists the tools:

> Apply get_panel_recommendation's recommendation for the same arguments: it is recomputed, then updates existing seats in place, preserving their instructions and history. Explicit roles may add or remove seats; changes lists why. The orchestrator model changes in the same transaction. With repo, only that repository changes: it gets its own panel if it has none. Returns the recommendation applied and undo; pass undo to restore_panel to put the panel back.

## Related

- [`get_panel_recommendation`](/docs/mcp-server/get_panel_recommendation): the same arguments, changing nothing.
- [`restore_panel`](/docs/mcp-server/restore_panel): replay the `undo`.
- [`get_optimization`](/docs/mcp-server/get_optimization): suggests a panel from your spend and quality.
- [`update_repo_settings`](/docs/mcp-server/update_repo_settings): `panelId: null` returns a repository to your default panel.
- [Ask for a panel by goal](/docs/reviewers#ask-for-a-panel-by-goal): what each level does.
- [MCP server](/docs/mcp-server#control-cost-and-check-quality): where it fits in tuning cost.
