|
1 | 1 | --- |
2 | | -summary: "CLI reference for `openclaw sessions` (list stored sessions + usage)" |
| 2 | +summary: "CLI reference for listing, archiving, deleting, and maintaining stored sessions" |
3 | 3 | read_when: |
4 | 4 | - You want to list stored sessions and see recent activity |
| 5 | + - You want to archive or delete sessions from a headless Gateway |
5 | 6 | title: "Sessions" |
6 | 7 | --- |
7 | 8 |
|
@@ -78,6 +79,81 @@ skipped. |
78 | 79 | } |
79 | 80 | ``` |
80 | 81 |
|
| 82 | +## Archive sessions |
| 83 | + |
| 84 | +Archive one or more sessions through the running Gateway: |
| 85 | + |
| 86 | +```bash |
| 87 | +openclaw sessions archive "agent:main:scratch-1" |
| 88 | +openclaw sessions archive "agent:main:scratch-1" "agent:main:scratch-2" |
| 89 | +openclaw sessions archive "agent:work:scratch-1" --agent work |
| 90 | +openclaw sessions archive "agent:main:scratch-1" --dry-run |
| 91 | +openclaw sessions archive "agent:main:scratch-1" --json |
| 92 | +``` |
| 93 | + |
| 94 | +Archive uses the same `sessions.patch` lifecycle operation as the Control UI. |
| 95 | +It keeps the transcript, marks the session archived, and removes the session |
| 96 | +from the default active list. Already archived sessions are successful no-ops. |
| 97 | +Use `--dry-run` to validate every key and preview the result without changing |
| 98 | +session state. |
| 99 | + |
| 100 | +## Delete sessions |
| 101 | + |
| 102 | +Delete one or more sessions through the running Gateway: |
| 103 | + |
| 104 | +```bash |
| 105 | +openclaw sessions delete "agent:main:scratch-1" |
| 106 | +openclaw sessions delete "agent:main:scratch-1" "agent:main:scratch-2" --yes |
| 107 | +openclaw sessions delete "agent:work:scratch-1" --agent work --yes |
| 108 | +openclaw sessions delete "agent:main:scratch-1" --dry-run |
| 109 | +openclaw sessions delete "agent:main:scratch-1" --yes --json |
| 110 | +``` |
| 111 | + |
| 112 | +<Warning> |
| 113 | + Delete is destructive. In an interactive terminal it asks once before |
| 114 | + deleting the valid keys. Non-interactive and `--json` deletion requires |
| 115 | + `--yes`. Use `--dry-run` first when scripting a bulk cleanup. |
| 116 | +</Warning> |
| 117 | + |
| 118 | +Delete uses the same `sessions.delete` lifecycle operation as the Control UI, |
| 119 | +with transcript cleanup enabled. The Gateway removes the live session row, |
| 120 | +transcript generations, session-owned runtime state, bindings, boards, and |
| 121 | +other lifecycle artifacts. For ordinary sessions it retains the transcript as |
| 122 | +a verified `.jsonl.deleted.<timestamp>` archive; incognito transcripts are |
| 123 | +removed without an archive. If a managed worktree cannot be removed safely, |
| 124 | +the command reports the preserved branch and path for manual cleanup. |
| 125 | + |
| 126 | +Both lifecycle commands: |
| 127 | + |
| 128 | +- accept multiple keys and report one ordered result per key; |
| 129 | +- use `--agent <id>` to select the owning agent, which is required for a |
| 130 | + `global` key outside the default agent; |
| 131 | +- support `--url`, `--token`, `--password`, and `--timeout <ms>` Gateway |
| 132 | + connection overrides; |
| 133 | +- return a non-zero exit when any key is unknown or any operation fails, while |
| 134 | + still processing the other valid keys; |
| 135 | +- emit one stable JSON envelope with `ok`, `operation`, `dryRun`, and `results` |
| 136 | + when `--json` is set. |
| 137 | + |
| 138 | +Example mixed-result JSON: |
| 139 | + |
| 140 | +```json |
| 141 | +{ |
| 142 | + "ok": false, |
| 143 | + "operation": "archive", |
| 144 | + "dryRun": false, |
| 145 | + "results": [ |
| 146 | + { "key": "agent:main:scratch-1", "ok": true, "status": "archived" }, |
| 147 | + { |
| 148 | + "key": "agent:main:missing", |
| 149 | + "ok": false, |
| 150 | + "status": "not_found", |
| 151 | + "error": "Session not found. Run openclaw sessions list --json to choose a valid key." |
| 152 | + } |
| 153 | + ] |
| 154 | +} |
| 155 | +``` |
| 156 | + |
81 | 157 | ## Tail trajectory progress |
82 | 158 |
|
83 | 159 | ```bash |
|
0 commit comments