After a terminal restart, programs come back on their own: what Rex's OSC 7577 aims to solve
Rex lets programs that are running when a server restarts recover themselves. The highlight is not the animation, but that programs proactively report a recovery command, and the terminal then decides whether to trust it and whether to run it.
When the terminal restarts, all running programs disappear. Most terminals only restore window layout, working directory, and scrollback history; the programs themselves are gone. Mitchell Hashimoto announced on X that Rex can now bring programs back after a server restart, using the newly released terminal protocol OSC 7577. The protocol was developed by Mitchell Hashimoto in collaboration with herdrdev, with reviews from authors of multiple terminal emulators and terminal programs. Original post: https://x.com/mitchellh/status/2125713695233970521
OSC is a type of terminal control sequence. A program writes a special piece of text to the pty, and the terminal parses it and performs an action. OSC 7577 does something very specific: a program tells the terminal, 'If you want to restore me, run this command.' The report contains pid, time, argv, and a mac. argv is the argument list of the recovery command, with each argument base64-encoded separately. cwd is optional. clear is used to delete the record. The terminal validates mac and time, then decides whether to accept or reject. After a restart, the terminal can execute the stored command according to its own policy. The protocol documentation is in the Rex docs: https://www.superlogical.com/rex/docs/build/program-resume
The documentation is clear: recovery is a hint, not a guarantee. The terminal may choose not to restore, reject the report, or restore only allowlisted programs. Reports use the OSC7577_TOKEN environment variable for feature detection. Each terminal pane has its own token, regenerated on every startup. mac is the SHA-256 of the body plus the token, not an HMAC. The documentation explains why: HMAC is harder to compute in a shell, and common approaches put the token on the command line where other users can see it. A plain hash only needs sha256sum, with the token passed via standard input.
Security is the main course of this protocol. A recovery command means the terminal will later run some code as the user. cat-ing a file, tailing a log, or ssh-ing to a remote host, text on the screen may contain escape sequences. Without a token, malicious output can register a recovery command. The time window is recommended to be 60 seconds to prevent replay. pid is only used for validation and lifecycle management, not as a security mechanism. The documentation says directly that it is easy for programs running as the same user to forge each other's pid. Program recovery is not recommended for root or privileged terminals. Sandboxed, chrooted, or user-switching child processes should remove OSC7577_TOKEN; otherwise a restricted child process could register a command that later runs with full user privileges.
Rex's implementation is conservative. Recovery rules are configured in Lua and opt-in per program; they can be filtered by program name, path, working directory, and command-line flags, and can be disabled in one line. Rex has built-in Claude Code support and sends OSC 7577 in the session start hook. Mitchell says any program can use it, with no special integration with a particular terminal required. In the comments, some agree that escape sequences are the right choice, avoiding the need to maintain a new IPC. Someone else joked that tmux's session/resurrect had been instantly outclassed. Someone also asked why Linux installation instructions make people go to Discord; Mitchell replied that the people who received the invitation are also in Discord and can see them after logging in. This kind of friction does not affect the protocol, but it does affect the early experience.
What the protocol can and cannot do is clearly defined. It restores the command reported by the program; it does not restore shell variables, history, stopped jobs, or intermediate layers such as sudo -s or nix develop that do not report. Failed recovery is not retried. What comes back is a new process, and terminal modes return to defaults. Programs must save their own state files, such as editor sessions and agent session IDs, and ensure repeated loading is safe.
The value of this is not in 'yet another terminal feature.' It moves terminal recovery from guessing a process's command line to programs declaring their own recovery intent. Approaches like tmux-resurrect and kitty sessions rely on process detection; what they get is the launch command, not the recovery command. Re-running rm would cause trouble; editors need session files, and agents need session IDs. OSC 7577 lets programs themselves say 'how to bring me back,' while the terminal is only responsible for trust decisions and execution. The hard part also shifts from saving state to two things: whether the terminal dares to execute it, and whether programs are willing to adapt. Rex's built-in Claude Code support is only the first step. Whether the protocol spreads depends on whether other terminals and programs adopt it. At least it moves the problem from saving window layout to saving what is actually running.
发布时间: 2026-11-27 01:33