ReferenceCLI commands
BetaYou are reading docs for the beta channel (
2.4.1-beta.1) — updated automatically on every beta release.Switch to stable →CLI commands
ak backups prune
Delete snapshots older than a threshold or beyond a retention count
Delete snapshots that are NOT retained by the policy. A snapshot is RETAINED when it is among the --keep-last newest OR younger than --older-than (whichever is more protective). When neither flag is set the command is a no-op.
Who it's for: Power devs reclaiming disk; ops scripts.
When to use it: Periodic cleanup; before a major upgrade to drop ancient state.
What changes on disk: Removes ~/.agentkit/backups/<id>/ trees that fall outside the retention window.
Usage
ak backups prune [flags]Examples
ak backups prune --older-than 30d # delete snapshots > 30 days old
ak backups prune --keep-last 5 # retain the 5 newest
ak backups prune --older-than 7d --keep-last 3 # both rules apply (most protective wins)
ak backups prune --older-than 30d --dry-run # preview deletion planFlags
| Flag | Description |
|---|---|
--dry-run | Print the deletion plan without removing anything |
-h, --help | help for prune |
--json | Emit machine-readable JSON (implies --no-interactive) |
--keep-last int | Retain the N newest snapshots |
--no-interactive | Disable interactive prompts (CI-safe) |
--older-than string | Delete snapshots older than this duration (e.g. 30d, 168h, 90d) |
-q, --quiet | Suppress non-error output on stderr |
-V, --verbose | Extra diagnostic output on stderr (loses to --quiet) |
-y, --yes | Assume yes for all prompts |
Output modes
| Mode | Behavior |
|---|---|
pretty | default on TTY (colors, ASCII markers) |
plain | auto when stdout piped or --no-interactive |
json | --json (single-object envelope, NDJSON-safe) |
Exit codes
| Code | Meaning |
|---|---|
0 | success |
1 | runtime error |
2 | invalid flags |
3 | user-cancel (SIGINT, prompt-cancel) |
2 | invalid --older-than duration |
4 | another ak backups operation already holds the lock |
Related commands
ak backups— Manage rollback snapshots