# Detach and recover

Canonical HTML: [Detach and recover](https://getred.dev/docs/sessions). Website source: `b212874eefaf200143affa21c770fbb8855a4f5c`. Documented Red release: v0.9.1. Installer source: `b86a2ca4b92e9547d3b174910c82db8a259f5171`.

Keep a live editor across terminal disconnects on macOS and Linux, or restore an atomic snapshot after the editor stops.

<a id="keep-a-live-session-running"></a>

## Keep a live session running

Detach and attach are available on macOS and Linux. Start a named session:

```shell
red --detach=refactor src/main.rs
```

The terminal attaches immediately. Press `Ctrl-\` to leave the TUI while the editor, unsaved buffers, plugins, language servers, running shell jobs, and Codex app-server process stay alive.

```shell
red --attach refactor
red --stop refactor
```

Only one TUI can attach at a time. Sessions are local to the current OS user and use a private Unix socket rather than a TCP port. Windows supports recovery but not detach and attach.

<a id="use-the-default-session-name"></a>

## Use the default session name

```shell
red --detach src/main.rs
```

Without an explicit name, Red uses `default`. Named sessions require the `--detach=NAME` form so a filename can't be mistaken for a session name.

<a id="restore-after-a-crash"></a>

## Restore after a crash

```shell
red --resume
```

Recovery is available on every supported platform. Red restores the newest valid snapshot, including dirty buffers, window layout, cursors, registers, marks, undo history, and Agent conversation state. Restored dirty text stays in memory; Red doesn't write it to disk until you save.

> **Don't resume a running editor**
>
> Interactive owners don't currently hold an exclusive recovery lock. Use `--attach` for a live detached owner and `--resume` only after the owner has stopped.

<a id="know-which-recovery-path-applies"></a>

## Know which recovery path applies

| Situation                  | Use                         | What happens                                                |
| -------------------------- | --------------------------- | ----------------------------------------------------------- |
| Terminal or SSH disconnect | `red --attach NAME`         | Reconnects to the same live editor owner                    |
| Editor or machine stopped  | `red --resume`              | Loads the newest valid atomic snapshot                      |
| Normal clean exit          | `red` in the same directory | Restores clean file-backed buffers, views, and split layout |
