Sessions
Session data is saved to the selected backend after each completed turn, after a child invocation settles, after a successful /compact, and again on an orderly exit when the transcript has a user message. The saved session stores the transcript, todos, the mode, session-only disabled built-in tools, last-request and cumulative token usage, turn counts, and any child records. Saved-session lists show only parents.
A running turn is also saved after your message, after each model round, and after each tool batch. A crash, a kill -9, or a power loss loses at most the round or tool batch in progress. A tool call without a result is saved as not completed, and resuming shows it that way; check its effects before you retry it. Child invocations are not saved while they run, and the parent checkpoint records them as unfinished. If a checkpoint cannot be written, one note says so and the turn continues.
Home files the host replaces, such as config.json, credentials.json, permissions.json, trusted.json, access.json, JSON sessions, media, and prompt history, are written to a temporary sibling, flushed, and renamed over the target. A crash or power loss leaves the old or the new file, never a truncated one. Workspace files written by write, edit, and apply_patch are not covered.
/quit, or two Ctrl+C presses on an empty composer, leaves the alternate screen and prints the session id and crystal --resume <id>. kill (SIGTERM), a system shutdown, or closing the terminal window (SIGHUP) interrupts the running turn, saves the session, and exits the same way. A second signal exits at once.
Storage format
Section titled “Storage format”sessionStorage in config.json selects sqlite (the default, stored in ~/.crystal/sessions.db) or json (one file per session in ~/.crystal/sessions/). Override it for one process with --session-storage sqlite|json.
To find sessions from both backends, set searchAllSessionStorages to true or pass --search-all-session-storages on for one process. When both backends contain the same session ID, the newer updatedUtc wins. Writes go to the selected backend.
To copy existing JSON sessions into SQLite, run the command below. Reverse --from and --to to copy in the other direction. The source is kept. Existing destination IDs are skipped unless you pass --overwrite. Use --format text for plain progress.
crystal sessions convert --from json --to sqliteSQLite performance
Section titled “SQLite performance”When you use only the SQLite backend, the /resume picker reads session summaries and /stats reads the stored usage and tool data it needs. The JSON backend reads session documents to produce those views. The difference is most noticeable with a large session library, especially when the active workspace contains only a small share of it. Opening a selected session still loads its transcript. Searching both backends can also require a JSON scan.
In a local storage benchmark on an Apple MacBook, the library contained 1,200 synthetic sessions with 2 MiB of transcript text each. One session matched the current workspace. Median time over five warm runs fell from 791 ms to 2.45 ms for the /resume list query (about 323×), and from 805 ms to 3.40 ms for the /stats read (about 237×). These measurements cover storage reads. Screen rendering, replaying the transcript, and compiling the final statistics are separate.
Resume and fork
Section titled “Resume and fork”| Command | Effect |
|---|---|
crystal --resume |
Choose a session for this workspace at process start |
crystal --resume <id> |
Load that file and stay in this workspace |
crystal --resume <path> |
Choose a session from that directory, then enter it |
crystal --resume all |
Choose a session from any workspace, then enter its directory |
/resume |
Choose a session for this workspace and replay the transcript |
/resume <path> |
Choose a session from that directory, then enter it |
/resume all |
Choose a session from any workspace, then enter its directory |
/resume <id> |
Load that file and stay in this workspace |
/fork |
Save the current session and continue from a new id |
/fork <id> |
Branch that saved session into a new id in the current workspace |
/sessions |
List resumable sessions for this workspace, newest first |
/sessions all |
List resumable sessions from every workspace, newest first |
/clear |
Start a new id |
--resume without a value opens the selector before the alternate screen. --workspace and --resume <path> must name the same directory when both are set. A missing or empty session exits without entering the TTY. A redirected terminal cannot open the selector. Pass --resume <id>.
The selector lists sessions newest first. Type to filter by title, first message, ID, or workspace path. Use Up/Down or PgUp/PgDn to move the selection. The mouse wheel scrolls the list and keeps the selection within view. Enter resumes the highlighted session and Esc closes the selector.
Inside a running session, trust is confirmed before a named directory’s selector opens. Escape leaves the current workspace unchanged. Choosing a session from /resume all asks for trust before entering that directory. Declining trust does not restore the session.
While topicModel.enabled is on, the first completed turn of an unnamed session starts a short background request to name it. The turn does not wait, and the progress row shows Naming Topic until it ends. The request keeps the topic model’s own output limit. If a reply has no text, the note explains why; lowering /topic thinking or choosing another /topic model may help. A session that opens with a greeting has nothing to name yet, so the next completed turn asks again. You can keep sending messages while naming runs. The name appears in /sessions, the resume picker, and the topic status-line field. A session without a topic shows its first message instead. /topic names, clears, or regenerates the topic by hand; a name you set is not replaced. /clear and /fork start without a topic.
Resume restores the last usage snapshot and cumulative usage, so the status bar, /status, and compaction have a baseline before the next model call. Older files without cumulative usage show an unknown cumulative value, not a partial total. A compacted session restores the full conversation on screen. The model continues from the summary and recent tail. Only the live system prompt is refreshed.
Fork keeps the conversation, model context, todos, mode (Plan, Work, or custom), turn counters, usage baseline, and child records. It does not add child usage again. It does not copy directory access. The new branch gets the current workspace’s defaults from ~/.crystal/access.json. The source session is unchanged. The branch gets a new creation time, uses the current workspace, and refreshes its live system prompt. Session lists mark the current id and keep the full id for /resume or /fork.