Automate Program resume (OSC 7577)
In a pane that provides OSC7577_TOKEN, a program can tell Paneflow how to
start it again if the terminal session is lost. An editor can report the
command that loads its saved session, for example. A report is a suggestion,
not a request to run the command immediately. Resuming starts a new process;
it does not recover the old process or its memory.
This page describes Paneflow's implementation of the Program Resume Protocol, revision 0.5. To report what a running program is doing instead, use Program Status (OSC 7501).
Detect support
Read OSC7577_TOKEN from the program's environment. If it is absent, do not
send a report. There is no query or reply; OSC 7577;? is ignored. Paneflow
creates a separate random token each time it starts an eligible pane. It does
not provide one on Windows, for WSL shells, or when program resume is off.
Keep the token out of terminal output, logs, and command-line arguments. Do not forward it to remote machines, containers, or restricted child processes. The token is meant to protect against untrusted terminal output, not to isolate processes running as the same user.
Report a resume command
Write the sequence to the terminal, not to a redirected log. This schematic
shows the order of the framing bytes and the final mac; replace the uppercase
placeholders before sending a report.
OSC 7577;pid=PID:time=UNIX_SECONDS:argv=BASE64_ARGV:mac=MAC_HEX STOSC is ESC ] (bytes 1B 5D). End the sequence with ESC \ (1B 5C)
or BEL (07). The spaces in the diagram are not bytes in the sequence.
Separate key=value pairs with : and don't repeat keys. The keys before
mac may appear in any order.
| Field | Value |
|---|---|
pid | Required. Positive decimal PID of the process that owns the record. A helper may report for that process. |
time | Required. Positive decimal Unix time in seconds when the report is made. Like pid, it has no leading zeros. |
argv | The resume command, with each argument separately encoded in standard base64 and the elements joined by ,. Use a bare program name or absolute path for the first element. It cannot be empty, and a bare name cannot start with -. |
cwd | Optional absolute working directory, encoded in standard base64. |
clear | Set to 1 to remove the owner's record. Send exactly one of argv and clear. |
need | Optional comma-separated list of keys the terminal must implement. Paneflow ignores unknown keys unless need lists them. |
mac | Required, last. SHA-256 digest written as 64 lowercase hexadecimal characters. |
For example, the argument list nvim, -S,
/home/user/.local/state/nvim/session.vim is encoded as follows:
argv=bnZpbQ==,LVM=,L2hvbWUvdXNlci8ubG9jYWwvc3RhdGUvbnZpbS9zZXNzaW9uLnZpbQ==Base64 padding is optional. Decoded text must be valid UTF-8 without control
characters. An empty element after the first is an empty argument. There is
no field for environment variables. Paneflow captures up to 4,096 bytes
including 7577;, leaving 4,091 bytes for the body, including mac.
Sign the report
Hash the exact bytes of the body before :mac=, followed by one : and the
value of OSC7577_TOKEN. Encode the SHA-256 digest in lowercase hex and append
it as the final mac field. The framing bytes do not take part in the hash.
This is SHA-256 with the token appended, not HMAC.
Paneflow allows a clock difference of up to 60 seconds and ignores reports older than the last accepted one for that PID. A truncated report, an invalid MAC, or a missing or out-of-window timestamp leaves the earlier record alone. An authenticated, timely report that is rejected can remove the earlier record if Paneflow can identify its owner.
Records and lifetime
Paneflow verifies that the PID is still alive, runs as the same user, and belongs to the pane's OS session. This check does not prove which process wrote the sequence. An accepted report replaces its owner's record. Paneflow keeps up to 16 records per pane, subject to a 24 KiB storage budget. It prefers an ancestor's record to a descendant's, and chooses the most recently updated record among the remaining candidates.
Paneflow saves the reported cwd when present. Otherwise it takes the
owner's directory from the OS, or the pane's initial directory if that cannot
be read. It does not use OSC 7 to choose the recorded directory.
Report again when the resume command changes or the program starts after a
resume. Send clear=1 when the user ends the program, not when the terminal
is lost. On normal owner exit, the host gives the record a two-second grace
period before removing it. Closing a pane or choosing Stop everything and
quit discards its records. Terminal resets and shell prompts do not clear
these records.
How Paneflow resumes
If the original terminal is still running, Paneflow reconnects instead of
starting another process. When restoring a pane whose terminal was lost,
terminal.program_resume.mode controls what to do with a saved record:
| Mode | Behavior |
|---|---|
ask (default) | Offers Resume or Dismiss for a generic program. A program in terminal.program_resume.trusted_programs may resume without asking. A trusted name matches only a bare first argument, not an absolute path. |
auto | May resume a generic program without asking. |
off | Does not offer or automatically run an OSC 7577 resume. New panes do not receive the token. |
An unfinished resume attempt always requires confirmation before trying again.
For a recognized agent, automatic resume requires agents.restore_conversations
and arguments that match the agent's native resume template. Paneflow cannot
resume a record if its explicitly reported directory is missing, the shell lacks
resume integration, or its owner was the first process in the original terminal.
It also blocks the resume if the sandbox was enabled or disabled, or if its root
or Unix pathname socket setting no longer matches the record.
Automatic resume uses the new shell's startup integration. Clicking Resume
uses the shell already open in the restored pane. In either case, Paneflow
passes the arguments to paneflow-resume in a private, one-use file. The
launcher resolves bare names using absolute entries in the shell's PATH,
not aliases, functions, or builtins. It passes the arguments directly to the
executable rather than evaluating them as shell code. The command runs in
that shell's environment, not a copy of the reporting program's environment.
See the session host implementation for record admission and launch checks.