
# agc ship, end to end

`agc ship` snapshots your working tree, builds and rehearses it on a fresh branch of production, asks a person when one must approve, then migrates production and switches traffic. It's done when it exits 0 with `"outcome": "live"`.

```bash
agc ship
```

## Execution contract

- **Before starting:** A linked app and running mirror; apply migrations with `agc migrate`.
- **Do:** `agc check`, then `agc ship` only when you mean to deploy.
- **Success:** Exit 0 and `"outcome": "live"` together.
- **If blocked:** Exit 11: fix the change. Exit 20: `agc wait <op>`. Else: follow the error's fix.
- **Human handoff:** Exit 10: relay the decision and await the person; never approve it yourself.

## Ask your agent

```text
Ship this to production. If it needs my approval, ask me here.
```
## Steps

```bash
agc check
agc ship
```

A successful ship answers:

```json
{
  "ok": true,
  "product": "agent.cloud",
  "command": "ship",
  "op": "op_8c2e…",
  "env": "prod",
  "outcome": "live",
  "data": {
    "op": "op_8c2e…",
    "app": "camp-bookings",
    "version": "v12",
    "state": "live",
    "url": "https://camp-bookings.ac0.app",
    "migrations": [],
    "decision": { "human": false, "reason": "Code only, and this app lets agents release code on their own." }
  },
  "receipt": { "id": "rcp_…", "url": "https://agent.cloud/r/rcp_…" },
  "next": [{ "cmd": "agc status", "why": "see production and your mirrors" }]
}
```

`data.warnings` lists fixes that didn't stop it (below). While the app has only its default icon, a live ship adds `agc icon use <file.svg>` as its last `next` step ([Your app's icon](/docs/build/your-apps-icon.md)). When this machine runs the folder's mirror, the last step is `agc down <copy> --delete`.

If your tool calls time out first:

```bash
agc ship --no-wait
agc wait op_8c2e…
```

## How it works

**1. Snapshot.** agc packs the files git would track (`git ls-files --cached --others --exclude-standard`), or, outside git, the folder minus `.gitignore` matches. `.agentcloudignore` excludes more. `node_modules/`, `.git/`, `.agentcloud/`, `.env*`, `.venv/`, `venv/`, `__pycache__/` and `.DS_Store` never ship. `[[asset]]` folders upload separately.

**2. Plan, in control.** Control compares your migrations with production's ledger. Editing a migration production already ran is refused (`ship.migration_modified`). It then decides, by rules only, whether a person is needed:

| A person is asked when | Reason shown |
|---|---|
| First release of an app at `watch` autonomy or on a customer's own target | "First release of a new app: a person claims it and sets its budget." |
| A pending migration drops or empties data (`DROP`, `TRUNCATE`, `DELETE`, `UPDATE` without `WHERE`, …) | "Changes the production database (…)." |
| The app's autonomy is `watch` | "This app asks a person before every release." |
| The live worker would be removed | "Removes the live worker service." |
| `[storage]` goes while production's bucket exists | "Removes [storage] while production's bucket still exists (…)" |
| Sign-in changes (`[auth] provider`) | "Changes how people sign in: …" |
| An edge app opens a new `[auth] public` path | "Opens a path to anyone, without sign-in: …" |
| A held check is removed or changed | "Removes or changes a check agent.cloud holds: …" |

Otherwise it goes out on its own, additive migrations included. An app nobody owns yet stops at a private preview: exit 10, `ship.preview`, with `data.preview_url` and `data.publish_url` to relay; `agc wait <op>` answers live once it's published.

**3. Build, then rehearse.** A release rehearses when it has checks, pending migrations or a worker. The rehearsal runs before anyone is asked, so a person only ever approves a release whose rehearsal passed. A release with a worker is rehearsed with the worker killed mid-job.

**4. Decide.** If a person is needed, the op waits in `waiting_approval` and agc exits 10 (see [Approving in a session vs the console](/docs/ship/approving-in-a-session-vs-the-console.md)). An approval expires after 24 hours (`ship.approval_expired`). A waiting ship doesn't hold the app: shipping a different snapshot supersedes it (`ship.superseded`). If another release went live while it waited, it rehearses again before promoting, without asking again.

**5. Promote.** Migrations run on production, then the runner starts the new version, waits for it to answer healthy, and switches traffic. Each migration has its own transaction, so if a later one fails, earlier ones stay applied.

The states agc prints while it follows:

| `state` | agc shows |
|---|---|
| `building` | Building v12 |
| `rehearsing` | Rehearsing v12 on a fresh branch of production |
| `deciding` | Deciding on v12 |
| `verifying` | Waiting for the verifier to judge v12 (up to 30 minutes) |
| `waiting_approval` | Waiting for a person to approve v12 |
| `migrating` | Updating the production database for v12 |
| `releasing` | Starting v12 in production |
| `previewed` | Waiting for your person to publish v12: it runs privately at its preview until then |
| `live`, `failed`, `declined` | final |

`agc ship` follows for up to 10 minutes, then returns `ship.still_running` with exit 20.

**Repeats are safe.** agc sends an idempotency key: a hash of the archived snapshot, `--fixes`, the commit message and the assets. The same ship within 24 hours returns the same op with `data.repeated: true`. To ship identical code again after a failure, change something or pass `--idempotency-key <new key>`.

**The first task.** If `agc init --prompt` made the app's first task (`<app>#1`) and this credential still owns it open, a ship with no `--work` carries it, and the answer adds `data.task: "<app>#1"`.

## Reference

| Flag | Effect |
|---|---|
| `--no-wait` | Return at once with exit 20 and the op id |
| `-m "<intent>"` | The release's message in place of the last commit's subject: one line, up to 120 characters, or `ship.bad_intent` (exit 2) |
| `--fixes "<text>"` | Says what reported problem this fixes, up to 200 characters. Checks this release adds become held once it's live |
| `--idempotency-key <key>` | Your own key, 1–256 of `A-Za-z0-9._:%/-`; never expires (see [CI/CD with deploy keys](/docs/ship/ci-cd-with-deploy-keys.md)) |
| `--work <id>` / `--pr <n>` | Record the work item and PR the ship is for; with a task, carries its counter |
| `--counter <n>` | Override the task counter agc remembered |
| `--from-git <commit>` | Ship one commit from git objects, with `AGC_TOKEN` (see the CI page) |

Warnings in `data.warnings` (the ship still goes ahead): check lint from `agentcloud.toml`; code that hashes passwords itself; `[[verify]]` that hasn't run, or ran on different code; a release that declares no checks (review rule `no-checks`), except on `watch` autonomy.

| Outcome | Exit | Meaning |
|---|---|---|
| `live` | 0 | Serving traffic |
| `waiting_approval` | 10 | A person must decide |
| `preview` | 10 | A private preview waits for its person to publish it |
| `failed` with `ship.check_failed` | 11 | A check failed in rehearsal; production unchanged |
| `denied` | 12 | A person declined (`ship.declined`) |
| `failed` | 1 | Read the error; migrations already applied to production can remain |
| still running | 20 | `--no-wait`, or 10 minutes passed |

## Errors

| Code | Exit | Cause | Fix |
|---|---|---|---|
| `ship.check_failed` | 11 | An invariant or smoke flow failed on the branch of production | Run `agc check` on your mirror; fix the change |
| `ship.approval_required` | 10 | A person must approve | Relay the link or ask in session; `agc wait <op>` |
| `ship.declined` | 12 | The person declined | Ask them what to change |
| `ship.locked` | 1 | Another release is building, rehearsing or releasing (`data.locked_by`) | `agc wait <that op>`, then ship |
| `ship.migration_modified` | 1 | A migration production already ran was edited | Restore it; put the change in a new migration |
| `ship.secret_missing` | 1 | `[secrets] required` names one that isn't set | Give the person the settings link |
| `ship.too_large` | 1 | Snapshot over 64 MiB compressed or 320 MiB before packing | Ignore build output; use `[[asset]]` |
| `ship.release_failed` | 1 | `[auth] provider = "edge"` with no health path: the new release answered only through the sign-in (`cause: health_missing`); the previous release keeps serving | Set `health` in `[service.web]` to a path that answers without sign-in (`health = "/health"`), then ship again |
| `ship.behind` | 1 | Your base is older than the live release and shipping would undo the paths it names | `agc pull --fresh`, re-apply your change, ship |
| `ship.superseded` | 1 | A newer ship replaced this one while it waited | Nothing; follow the newer op |
| `ship.approval_expired` | 1 | Nobody decided within 24 hours | Ship again |
| `ship.still_running` | 20 | Still in progress | `agc wait <op>` |

```json
{
  "ok": false, "product": "agent.cloud", "command": "ship", "op": "op_8c2e…", "env": "prod", "outcome": "failed",
  "data": { "op": "op_8c2e…", "app": "camp-bookings", "version": "v13", "state": "failed", "migrations": ["20261020_add_waitlist"],
            "checks": [{ "name": "never overbooked", "kind": "invariant", "ok": false, "detail": "…" }] },
  "error": { "code": "ship.check_failed", "message": "…", "fix": "…", "retryable": false },
  "next": [{ "cmd": "agc check", "why": "reproduce it on your mirror" }, { "cmd": "agc ship", "why": "ship again once fixed" }]
}
```

## Limits

- Snapshot: 64 MiB compressed, 320 MiB uncompressed. Assets: at most 8 `[[asset]]` entries, 256 MB compressed each.

## Agent notes

- `agc receipt <id>` prints any operation's receipt, by op or release record id.
- Every answer about a ship op, failed ones included, carries `data.release_url`, its release page in the console.

## Related

- [Operations and waiting](/docs/concepts/operations-and-waiting.md)
- [Rehearsals](/docs/concepts/rehearsals.md)
- [Approvals](/docs/concepts/approvals.md)
- [Held checks and fixes](/docs/checks/invariants.md#held-checks-and-fixes)
- [Exit codes](/docs/reference/the-json-envelope.md#exit-codes)

<!-- feedback:start -->
---
Wrong, outdated or unclear? Run `agc feedback docs "ship/agc-ship-end-to-end: <what is wrong>" --body <file>` with the sentence quoted in the file. No code or app data is sent.
<!-- feedback:end -->
