# Sessions, rewind and checkpoints

> Resume, inspect, rewind, fork and clean up zelk's sessions, and restore files the agent changed.

Every conversation with zelk is a session, recorded as a log. The terminal
UI, `zelk exec` and `zelk acp` keep their sessions on disk; only print mode
(`zelk -p`) keeps its session in memory.

## Where sessions live

Sessions are kept in the state directory's `sessions/`: `-state DIR` if
given, else `$XDG_STATE_HOME/zelk`, else `~/.local/state/zelk`. Each
session keeps its log, the long command output and fetched pages it saved,
its checkpoints and its subagents' sessions there.

## Resume

```sh
zelk -c                      # the terminal UI, continuing this directory's last session
zelk -r                      # pick one to resume
zelk -session ID             # open a session by its ID
zelk exec resume --last "go on"   # exec's last session in this directory
```

In the terminal UI, **Resume a session…** and **New session** in the palette
do the same. A resumed session keeps its conversation, and the rules granted
in it, but runs with the mode and flags the resuming launch gives.

A session is open in one zelk at a time. If another zelk has it, the terminal
UI opens it read-only and tells you until when. After a crash or a kill,
resuming the session is safe: the next message settles whatever the crash left
open before anything else runs, as [Durability and
recovery](/concepts/durability/) describes.

## Inspect and organize

These commands need no model:

```sh
zelk status                       # where this directory's last session stands
zelk status SESSION
zelk sessions list                # JSON, newest first
zelk sessions -tag docs list      # only sessions with this tag
zelk sessions rename SESSION "TODO survey"
zelk sessions tags SESSION docs review   # set its tags; give none to clear them
zelk sessions delete SESSION      # refuses a session with a process recorded as running
zelk sessions delete -force SESSION   # removes it anyway; stops no process
zelk sessions report SESSION      # every action of its runs, and how each was decided
```

`zelk status` shows the model and mode, whether a run is under way, how the
last one ended, the task list, background work, the tokens spent and where
the log and memory are kept:

```text
Session 01a21181-470c-7ac2-9eac-471f6af6ebdd · "list the TODOs in README.md"
Model claude-sonnet-5-5 · plan mode
Idle
Tokens: 142180 in (18 uncached), 803 out
…
```

`zelk sessions report` is JSON: each tool call, whether it ran, and what
decided it (the rules, the auto-mode reviewer or a person), with the files
the run changed.

Renaming, tagging and deleting need the session idle. Deleting removes its
log, outputs, checkpoints and subagents at once.

A log this zelk can't read is left out of `list` and the session picker,
which say how many they left out. Resuming one, or asking for its report,
fails with the session's ID, the state directory and the reason. zelk never
deletes such a log on its own, however old. A log can't be read when:

- **it was written before the current log format.** zelk reads only logs
  of its own format, so sessions from a zelk before the format changed
  can't be continued here. The zelk that wrote them still can. Start the
  new zelk with a fresh `-state` directory to keep them for it, or remove
  them with `zelk sessions delete -force SESSION`;
- **a newer zelk wrote it;**
- **it is damaged.** Remove it with `zelk sessions delete -force SESSION`.

In the terminal UI, **Rename session…**, **Tags…** and **Delete this
session…** do the same for the open session, and **Status** shows its state.

## Rewind

You can take a session back to before any earlier prompt. Open
**Rewind…** from the palette, or press Esc twice on an empty prompt while
nothing runs. Pick the prompt, then what to restore:

| Choice | Does |
|---|---|
| Restore code and conversation | files and conversation as they were before that prompt |
| Restore conversation | the conversation goes back; files stay as they are |
| Restore code | files go back; the conversation stays |
| Fork from here | a new session from before that prompt; this one is kept |

Before restoring files, zelk shows what it will create, rewrite and delete,
and asks. The prompt you went back past returns to the prompt box, to edit
and send again. The log keeps everything, so rewinding loses nothing from
the record, though tokens already spent stay spent.

**Fork session** in the palette copies the whole conversation to continue
in, keeping the original; it is listed in **Resume a session…**.
`zelk exec resume --last --fork "task"` does the same for exec.

## Checkpoints

Restoring code works from **checkpoints**. Before Write or Edit first
changes a file in a run, zelk saves the file's old version with the session,
and at each prompt it notes later changes to those files, Bash's included.
Each prompt in the Rewind list says how many files can go back.

Files that only Bash changed aren't tracked, so a rewind leaves them as
they are: commit to Git for anything else. A session keeps checkpoints for
its last 100 prompts. `-checkpoints=false` (or `"checkpoints": false` in
`config.json`) turns them off for new sessions.

## Long sessions

zelk compacts a conversation as it nears the model's context window, keeping
the goal, your recent messages, the task list and other facts intact
([Context and compaction](/concepts/context/)). To compact now, use
**Compact now…** (or type `/compact`), optionally saying what to keep, or
`zelk exec resume --last --compact "what to keep"`.

**Goal…** sets what zelk works towards until it is done, kept across new
messages and compaction. Saving it empty clears it.

## Cleanup

Each time it starts, zelk removes sessions idle for longer than
`-cleanup-days` (30 by default, or `cleanup_days` in `config.json`), with
everything they keep, sparing the session it is about to resume. Memory and
settings are never cleaned up this way.

## Where to go deeper

- [`zelk sessions`](/reference/cli/#zelk-sessions) and [`zelk status`](/reference/cli/#zelk-status) in the CLI reference
- [How zelk works](/concepts/overview/), sessions as logs
- [Durability and recovery](/concepts/durability/), what a crash leaves and how it is settled
- [The rewind contract](/internals/rewind/)
