3.4.0-beta.1). Features may change before the next stable release.Switch to stable →ak backups
ak backups restore
Preflight, authorize, preview, and apply a bounded rollback snapshot with exact stream and recovery semantics.
Use ak backups restore to replay one committed rollback snapshot to its
recorded destinations. It is a bounded, replace-oriented restore, not a
full-machine rollback and not an all-or-nothing multi-file transaction.
Syntax
ak backups restore <id> [--allow-root <absolute-root>]... [--dry-run]
ak backups restore --latest [--allow-root <absolute-root>]... [--dry-run]Before you run
Stop other AgentKit lifecycle mutations. Inspect and verify the snapshot first:
ak backups show <id>
ak backups verify <id>
ak backups restore <id> --dry-runFor a project bundle, repeat --allow-root for every exact root printed by
show. A broader ancestor, missing root, or unrelated root fails before a
prompt or live write. The command is local and needs no network or
authentication.
Without bundle authority, restore accepts only its fixed AgentKit, Claude, and Codex home scopes plus the exact Claude runtime configuration file. A project path outside those scopes requires the persisted bundle-root contract.
Take a new recovery snapshot of current state before rolling backward when practical. This command does not create a pre-restore snapshot automatically.
Arguments
| Argument | Required | Meaning |
|---|---|---|
<id> | Unless --latest is used | Snapshot ID in YYYYMMDDTHHMMSSZ-8lowercasehex form. |
At most one ID is accepted. An ID and --latest are mutually exclusive.
Options
| Option | Default | Effect |
|---|---|---|
--allow-root <absolute-root> | Empty | Adds one explicit project bundle root. Repeat it until the canonical set exactly matches the persisted bundle_roots. For a checkpoint, names one root key whose recorded path differs from the current one. |
--dry-run | false | Runs integrity, topology, authority, and destination preflight; prints the plan without live mutation. |
--latest | false | Selects the most recently created readable snapshot instead of an ID. |
--skip-secrets | false | For a checkpoint whose key is missing, restore everything except sealed secret files. With a snapshot ID it exits 2. |
Shared flags are described in CLI conventions. There is
no --force or --apply flag.
Restore a checkpoint
When <id> names a checkpoint written by ak backups checkpoint, the command
uses the checkpoint engine instead of the snapshot plan above. A dry-run
verifies the archive and prints, per root key, its restore mode and the counts
to write, keep unchanged, and remove; removals apply only to exact-mode roots.
An applied run first captures a pre-restore checkpoint labeled
before recover <id>, so every file it overwrites or removes stays
recoverable, then restores and ends with:
[OK] restored checkpoint <id>; undo with `ak recover <pre-restore-id>`On a TTY the prompt reads Restore checkpoint <id>? This writes <n> file(s) and removes <m> file(s) not in the checkpoint from exact roots; a pre-restore checkpoint is taken first. [y/N]:. When the checkpoint key is missing, the
prompt says that the manifest cannot be authenticated and only roots matching
this environment are restored. Explicit consent, meaning --yes or an answered
prompt, also accepts a missing key and unmeasurable free disk space;
--no-interactive alone does not.
With --json, the dry-run envelope is backups.checkpoint_restore_plan and the
applied envelope is backups.checkpoint_restore; both carry data.id,
data.dry_run, data.roots[], data.written, data.unchanged,
data.removed, data.databases, data.secrets_skipped,
data.skipped_secret_paths[]?, data.symlinks_refused, and data.warnings[]?.
The applied envelope adds data.pre_restore_checkpoint. A checkpoint ID that
does not exist exits 5, and a held checkpoint lock exits 4.
Confirmation behavior
Without --yes, --no-interactive, or --json, an applied restore prints the
verified plan and reads stdin. Only y or yes followed by a newline confirms;
any other answer or end-of-file declines with exit 3. Piped stdin can answer
the prompt.
--json implies noninteractive mode. Both --json and --no-interactive skip
the prompt and can mutate without --yes. Add --yes in automation to make
the intent explicit. --dry-run never prompts or mutates.
Examples
ak backups restore 20260426T123005Z-deadbeef --dry-run
ak backups restore 20260426T123005Z-deadbeef --yes
ak backups restore --latest --yes
ak backups restore <id> --dry-run \
--allow-root /absolute/project-a \
--allow-root /absolute/project-bOutput and streams
Human dry-run output on stdout separates Restore, Remove exact paths,
Remove plugin directories recursively, Keep, Skip, and authorized roots.
An interactive apply prints the same plan on stdout, then the prompt on stderr.
An apply with --yes, --json, or --no-interactive skips that plan display.
Dry-run JSON uses a success envelope on stdout:
schema_version: 1
kind: backups.restore_plan
data.plan.BackupID
data.plan.Restore
data.plan.Keep
data.plan.Skip
data.plan.Remove
data.plan.RemoveTrees
data.plan.AuthorizedRootsThe plan field names are case-sensitive. An applied restore with --json
writes one success envelope on stdout:
schema_version: 1
kind: backups.restore
data.id
data.restored
data.plandata.plan uses the same case-sensitive fields as the dry-run plan. Without
--json, an applied restore writes a plain completion line to stderr, and
--quiet does not suppress it:
[OK] restored <id>JSON-mode failures, including flag-parse errors (exit 2), write a structured
error envelope to stderr.
Exit status
| Exit | Meaning |
|---|---|
0 | Dry-run preflight completed, or all approved effects were applied. |
1 | Integrity, topology, authority, destination, I/O, or partial-restore failure. |
2 | Missing or malformed ID, too many arguments, invalid flags, or ID combined with --latest. |
3 | The stdin confirmation was declined or reached end-of-file. |
4 | Another backup mutation holds the registry lock at apply time. With --json, the error envelope names error_code lock_held. |
5 | A valid-shaped ID was not found, or --latest found no snapshot. |
An exit 1 after live mutation may mean earlier files were already restored.
Effects, safety, and recovery
Preflight verifies manifest metadata and every captured hash, validates scope, anchors destinations, and freezes the proposed live effects before asking for consent. Apply then acquires the backup registry lock, re-verifies the snapshot, manifest, authority, and approved live state, and fails closed if they changed.
Each captured file is replaced through a sibling temporary file and rename. The command also removes exact paths recorded absent and recursively removes only post-snapshot AgentKit plugin directories explicitly listed in the approved plan. Unrelated later-created files remain. Excluded snapshot subtrees remain protected from recursive cleanup.
Per-file replacement is atomic, but the complete restore is not transactional.
After a partial failure, stop new mutations, preserve command output, rerun
show and verify, inspect the affected paths, and decide whether to resume
from the same verified snapshot or use a newer recovery point.
Related commands and limitations
- Top-level equivalent
ak recover - List snapshots
- Inspect manifest and authority
- Verify integrity
- Complete command facts
Some project-local lifecycle snapshots report only a manual snapshot-data path because they are outside normal restore authority. Follow the recovery method reported by the command that created the snapshot.