Sessions and restarts
Closing the window doesn't end your work. Your shells and agents run in a background process, the session host, and the window only draws them. Close it, crash it or relaunch it, and every shell, agent and scrollback keeps running for the next window to pick up.
A session is the saved picture of a workspace: its tabs, splits, each pane's directory, each agent's resume command, sticky notes and the left bar's tree, in ~/.config/terminal-delight/sessions/<name>.toml. Launching terminal-delight with no arguments reopens the session last saved on the workspace you are on, or the most recent one nobody else is using.
If the host itself goes down, you still get your layout back. Terminal Delight reopens each pane in its directory and types the agent's resume command, such as claude --resume <id>, so every conversation continues. What doesn't come back is anything that only lived in memory: the scrollback, and programs like vim that can't resume. If a window ever stops saving its layout, it says Layout not saving across the top.
TD_SESSION=work terminal-delight opens a named session. TD_SCRATCH=1 opens a throwaway window that never saves.
Story explains it with a television; Technical has the files, which session opens, and what is guarded.
The television and the station
Think of an old television on a sideboard. When you switch it off, the programmes don't stop. They keep broadcasting from the station, and when you switch the set back on you're watching whatever is on now, not the moment you left.
Most terminals are a television that is also the station. Close the window and the shows stop, because the shells lived inside the window. Your agent was halfway through a change, your build was running, and a server was tailing its logs, and all of it goes dark together.
Terminal Delight splits the two. The session host is the station: a small background process that owns every shell and agent in a session and keeps them running. The window is the set, drawing what the host sends it. You can close the set, kick its plug out, or swap it for a newer model, and the station keeps broadcasting. The next window tunes in to the same channel and you're back in the middle of every programme, scrollback and all. When nothing has been watching and nothing has happened for about twelve hours, the station takes a last picture of the schedule and closes for the night.
The station also keeps a schedule on paper: the session file. It lists every channel, where each one was filming (the pane's directory) and which episode each show was on (the agent's resume command). That paper is what saves you when the station itself burns down. A new station reads the schedule, rebuilds every channel, and starts each show from its last episode. The live programmes are lost: a film that was mid-scene, or a vim session with unsaved edits, only ever existed on the air. Every conversation with an agent comes back, because an agent can pick up from its own transcript.
One more rule keeps the schedule honest: only the station writes it. A set that has lost its station stops writing, so it can't overwrite a good schedule with a picture of a dead one, and it puts a notice on screen so you know the paper has stopped keeping up. A save that would wipe out more than half your panes or tabs is refused unless you closed them yourself.
So you are left holding the real terms. The session host owns the terminals, the window is its client, and the session file is the layout and resume recipe it writes, which is what a new host rebuilds from when the old one is gone.
Sessions
A session has a stable name Terminal Delight owns, like 1, 2 or work, and its file is ~/.config/terminal-delight/sessions/<name>.toml (or under $XDG_CONFIG_HOME). The name is trimmed and cut to 64 characters, and any character other than a letter, a digit, - or _ becomes -; a name with nothing else left becomes default, which is also used where nothing names one. Since 2026-09-10 the session host is on by default.1
Older builds kept one state.toml. The first session window after an upgrade moves it to sessions/<name>.toml once, if that file does not exist yet; nothing reads or writes state.toml after that.
Which session a launch opens#
$TD_SESSION, if set, wins over everything, even if that session doesn't exist yet.- A running host with no window attached.
- The most recently saved session with no host, preferring one last saved on the Hyprland workspace you are on, then one with more than a single pane.
- Otherwise, a new session.
A host someone is already watching is left alone; a second launch gets a different session. Two windows can share one session only if you name it, and then the most recent to attach takes each pane. A host from an incompatible build is asked to save and stand down, which ends its terminals, and a new host starts from the saved file.
Each save records last_workspace: the workspace the window itself is on, read from Hyprland's own list of windows, so two windows can no longer both claim the workspace that happened to have keyboard focus. When Hyprland gives no single answer, the key is left out rather than guessed.1
What the file records#
| Level | Keys |
|---|---|
| Window | the active tab, window bounds, scale, theme, skin, lang, last_workspace, the left bar's projects, groups, left_bar and left_bar_w, the MCP policy under mcp (enabled, expose, events, writable), and closed for panes held in the bay with the time each is held until |
| Tab | name, color, text_color, group, project, level, and the split tree |
| Pane | cwd, resume, name, logo, appearance, the sticky note, the document it shows (path and scroll), the host's pane_id, and off_limits when a person has marked it off-limits to agents |
Older files still load, and a file from before the left bar opens as an unfiled list of tasks. Writes go to <name>.toml.tmp and are renamed into place, and the directory and files are owner-only (0700 and 0600). Before each write the previous file is copied to sessions/backups/<name>/, keeping the last ten. To go back to one, copy it over the session file; a running host notices and carries on from it. What an agent handed over is not in this file: it is rebuilt from the agent's own conversation record.
When saving stops#
Every 30 seconds, a window attached to a host checks that the file on disk files each pane's tab under the same project and group the window shows. The first time they differ it saves again without a word. If they still differ at the next check, it puts Layout not saving: N tabs would reopen out of place across the top of the window, repeats it at every check, and, if desktop notifications are on, sends one notification with the same title and the reason, such as this window has lost its session host or saves are not reaching the session file, followed by Closing this window now would lose where those tabs are filed. When the two agree again it says Layout saving again.2
How a resume command is chosen#
For each agent pane Terminal Delight reads the foreground process's working directory and writes a resume command:
| Agent | With a known conversation | Without |
|---|---|---|
| Claude Code | claude --resume <id> | claude --continue |
| Codex | codex resume <id> | codex resume --last |
For Claude Code, --permission-mode, --model, --effort and --dangerously-skip-permissions are carried over; Codex lines carry no flags. The conversation id comes from what the process declares, then (for Claude Code) from a transcript started at the same moment, then from the newest conversation in that directory, which is skipped when two agents share a directory. For an exact answer across /clear, /resume and compaction, install the ledger hook with scripts/install-recovery-hook.sh. terminal-delight probe <pid> prints what would be resumed for any shell, as JSON, and terminal-delight bindings lists each agent's conversation with how many restarts deep it is, or unrecorded where the agent hooks are not installed.3
The workbench and the focus reader find a pane's conversation the same way. When several agents share a folder and a pane cannot be matched to its own conversation for certain, it shows nothing rather than a neighbour's work.
What comes back#
| Window closed or crashed | Host gone | |
|---|---|---|
| Tabs, layout, names, colours, the tree | yes | yes |
| Each pane's directory | yes | yes |
| Agent conversations | yes, still running | yes, resumed |
| Scrollback | yes | no |
Programs that can't resume (vim, htop, a build) | yes, still running | no |
| Sticky notes, documents, logos | yes | yes |
A reattached window matches each saved pane to the live terminal by its id, and then by the resume command it is running. If a saved layout names one conversation twice (one conversation id, or --continue in the same directory), the first pane keeps it and the second comes back without it, wearing the note DUPLICATE TAB, so one conversation is never started twice. A bare claude names no conversation and never collides. A pane that reattaches to its live terminal has any such note taken off.
Guards#
- Only the host writes the session file. A window whose host has gone stops saving, so it can't overwrite a good file with an empty one. A slow answer from the host does not count as gone; only a closed connection does.
- A save that loses more than half the panes (of four or more) or tabs (of three or more) is refused unless you closed them yourself, and the file on disk is copied to
<name>.toml.last-good. - The host saves every 30 seconds while a window is attached and every five minutes while none is, and it exits after about twelve hours with no window and no output, saving first.
- A host holds 64 terminals at most. Only closing a pane ends its shell; a window disconnecting ends nothing.
- Another user's process can't talk to your host: the connection is refused on its user id before a byte is read.
Kinds of window#
- a session window
- Owns a session and saves it. Its title is
terminal-delight — <name>, or plainterminal-delightfordefault.terminal-delight <dir>is one too, with its first terminal in that directory. - a scratch window
TD_SCRATCH=1, or a pane torn off into its own window. One fresh terminal, never restores, never saves; it borrows the latest session's theme. Titleterminal-delight — scratch.- a window opened by another program
- A launch through
xdg-terminal-exec, as when Terminal Delight is the desktop's default terminal, is a quick window: it never claims or saves a session and never starts a host, so it cannot disturb the window you are working in. See Omarchy. - a window without a host
TD_NO_SESSIOND=1. The window owns its terminals, as in older builds, and holds the session with a file lock.
Inside a hosted pane the host sets TD_SESSION, TD_PANE_ID and TD_TAG, which agents use to find their own pane. See Environment flags.
Files#
| Path | Is |
|---|---|
sessions/<name>.toml | The session. |
sessions/backups/<name>/ | The last ten versions. |
sessions/<name>.toml.last-good | The file as it was when a shrinking save was refused. |
sessions/<name>.host.lock | Which host serves it. |
sessions/<name>.hostspawn.lock | Held while a host is being started, so two windows never start two. |
sessions/<name>.lock | The window's hold on the session when it runs without a host. |
$XDG_RUNTIME_DIR/terminal-delight/session-<name>.sock | The host's socket, with .tag and .window beside it. |
~/.local/state/terminal-delight/logs/host-<name>.log | The host's log, moved aside to .log.1 past 4 MiB. |
The sessions/ paths are under ~/.config/terminal-delight/; the log follows $XDG_STATE_HOME when it is set.4
In 0.5.0#
Ending a terminal has a bounded wait. Closing a pane sends hangup to its programs and closes the terminal, waits 250 ms, then kills what is left and waits up to another 250 ms to see it go; each look at the remaining processes has a 100 ms budget. A program stuck in the kernel is handed to a background reaper and reported as pending, so the close never hangs on it. Jobs the shell started in their own process groups are reached too, and a session that was deliberately detached is left alone.5
Watching a terminal no longer keeps it alive: reading its size or its foreground program holds only a weak reference, so closing a terminal ends it. The host's reply to a close can carry an optional cleanup record with hangup_sent, kill_sent, exit_observed, observed_jobs_remaining and error; what was not observed is left out rather than reported as zero, and older windows and hosts still understand the reply. The cleanup runs inside the host, so a host started by an older build keeps the old behaviour until it is restarted; replacing the window alone keeps the old host and its terminals.
The layout file gains, on a pane, seat (its place in the Threshing Floor) and agents = "read-only"; at the window level, [[lines]] (each with from, to, rung and an optional prompts_left), [[org_lines]] and ask_press_tokens for the Threshing Floor, [ui] for UI CONFIG, and looks. A 0.4.0 window reading such a file opens a read-only pane as open and ignores seats and lines. Resting and sleeping agents are kept in a separate file, ~/.local/state/terminal-delight/rest-<session>.toml; see Resting agents.
Not yet#
- Replacing the host, for example after an upgrade, still ends every terminal in that session. A handover that keeps them is planned.
- There is no command to list or stop hosts; a host exits when idle or when its process is ended.
What would prove this wrong#
Kill the window, not the host, and relaunch. If a single shell, agent or scrollback is missing, the split has failed. The project's survival test does exactly this twenty times in a row, and on 2026-09-11 it lost nothing.6 And if a window keeps working while its tabs vanish from the saved file without Layout not saving ever appearing, the save check has failed.
Sources
- Session files, names, the
state.tomlmove, which session a launch opens andlast_workspace: instance.rs; the host: host.rs and the session host protocol; the saved keys: main.rs (StateFile). - The save check (
SAVE_WATCH_SECS) and its messages: main.rs; a slow answer is not a lost host: hostctl.rs. - Resume commands and carried flags: session.rs; which conversation a pane reads: paneident.rs; duplicate conversations: main.rs.
- Locks: instance.rs; the socket: hostproto.rs; the log: diag.rs.
- 0.5.0: the bounded close in vt/pty.rs, the
cleanuprecord in vt/pump.rs and hostproto.rs, the new layout keys in main.rs and threshing_floor.rs, and the rest file in agentrest_io.rs. - The measurements, including 0 losses over 20 window kills: the client-server plan's status, and the harness td-survival-test.sh.