Per-pane session history and prefilled resume commands for Rex server restarts — never auto-runs.
English | 中文
When the Rex server restarts (Restart Server, a server update, a crash, or a Mac reboot), your panes and layout come back, but the programs in them do not. On the first prompt back, rxr shows what was running: for an interrupted Claude Code, Codex, Antigravity CLI (agy), Copilot CLI, Pi, or opencode session, it prefills the resume command; when a pane's last activity was plain shell commands, it lists the last 3 without prefilling. rxr never runs anything by itself — you read the command and press Enter.
Works alongside Rex's built-in restore: covers agents that don't report OSC 7577 yet, keeps per-pane history, and stays quiet in panes Rex already restored. (Restarting only the Rex app client keeps your shells alive, so there is nothing to restore.)
brew install iTofu/tap/rxr
rxr setup # preview first with: rxr setup --dry-runRequires zsh in Rex panes, Python 3.9+, and rex on PATH (tested on macOS; Linux should work, less tested). Full install · Uninstall
A pane that was running Claude Code when the Rex server restarted (session IDs shortened here):
── Before Rex restarted, this pane was running ─────────────
Claude Code session 3f2a9c1e interrupted by restart (last seen 11-28 14:40:12)
command claude
dir ~/code/app
last in ~/code/app/src
The resume command is filled in: Enter resumes, Ctrl-C clears it. More: rxr
$ rxr resume 3f2a9c1e-… # claude --resume 3f2a9c1e-…
A pane whose last activity was plain commands. Nothing is pre-filled; an older agent session gets one line:
── Before Rex restarted, recent commands in this pane ──────
Earlier: Claude Code session 3f2a9c1e ×2 (interrupted); type rxr to see it
dir ~/code/app
11-28 16:03:20 finished npm run build
11-28 16:04:47 finished git status ×2
11-28 16:05:31 interrupted by restart npm run dev
$
rxr lists what this pane ran. The newest entry is at the bottom, right above the prompt, and is number 1:
$ rxr
# time type state what dir
4 11-28 13:16:40 command exited git pull ~/code/app
3 11-28 13:18:22 Claude Code exited session 8b71d04a ~/code/app
2 11-28 13:33:05 command exited npm test ×3 ~/code/app
1 11-28 13:35:51 Claude Code interrupted session 3f2a9c1e ×2 ~/code/app ← prefilled
Last recorded: Claude 11-28 13:35:51 · agy never · Codex never · Copilot never · Pi never · opencode never
$ rxr resume 3f2a9c1e-… # claude --resume 3f2a9c1e-…
Sessions you quit on purpose stay in the list too, not just ones a restart cut off. To get the last one back later in the same pane, type rxr, even if you've run other commands since. It prefills the resume command for the newest agent session, so you don't have to look up the session ID; press Enter to resume.
| What ran in the pane | Recorded as | After a server restart |
|---|---|---|
| Claude Code, Codex, Antigravity CLI, Copilot CLI, Pi, opencode | the agent, with its session ID | The banner says the session was interrupted and the resume command is prefilled. |
Other agent CLIs rxr knows: aider, gemini, goose, amp, crush, cursor-agent, droid, kimi, qwen |
the agent, by name, without a session ID | The banner says it was interrupted and shows its command and directory. Nothing is prefilled. |
| Any other command | a plain command | The banner lists the last 3, interrupted ones marked. Never prefilled. |
The command's first word decides, so npx opencode counts as a plain command. An agent that reports its session (the first row) turns the entry into that session whatever was typed. opencode and copilot are known by name too: a run of theirs that reports no session, such as copilot -p, is recorded as in the second row. pi is not known by name, since other programs are called pi too: it counts as Pi once Pi reports its session.
-
Pre-fill, never run. The resume command goes onto the command line (and once into shell history). Some tools type the resume command and run it for you. rxr stops before Enter: after a restart you may not want the old session back, and running a command by accident costs more than pressing one key.
-
What the pane did last decides the banner.
- An interrupted agent session: its resume command is pre-filled, on every restart.
- An agent that exited normally: the resume command only goes into history (press ↑).
- An agent rxr can't tell was interrupted: a hint only.
- An agent without a session ID: its command and directory, plus one line for an older session that can be resumed, if the pane has one; nothing is pre-filled.
- A plain command: the last 3 commands, plus one line for an earlier agent session (one that can be resumed, if there is one); nothing is pre-filled.
Nothing is pre-filled for a session that was resumed later in another pane, and there is no banner for a session the agent has since deleted.
-
Repeats collapse. The same session, or the same command line in the same directory, takes one row with a
×Ncount. -
Newest at the bottom. Lists read like a terminal: oldest on top, newest right above the prompt. Entry 1 is the newest. Times are local and shown to the second (
MM-DD HH:MM:SS). -
No double resume.
rxr resumerefuses a session that is already running and tells you where it runs. One exception: for about a minute after a Codex TUI is gone (say, right after a Rex restart), Codex's shared background process still holds its session. Thenrxr resumewaits for it to let go, up to 90 seconds (Ctrl-C cancels), and resumes. If it still holds the session after that, the session may be open in Codex somewhere else, andrxr resumerefuses. Of two shells that resume the same session at the same time, only one goes ahead; the other refuses. A resume that is refused or cancelled leaves no entry, so the pane's next banner still offers the session. For Copilot CLI, Pi and opencode, the check relies on rxr's own records: a session open in a terminal outside Rex, or in a process rxr never recorded, can be resumed a second time. -
Typed resumes count.
claude -r/--resume <ID>,codex resume <ID>,agy -r/--resume/--conversation <ID>,copilot -r/--resume <ID>,pi --session <ID>andopencode -s/--session <ID>typed at the prompt are recognized as that session right away, before the agent reports it:rxr resumein another pane refuses it at once. -
Not inside tmux or screen. A tmux or screen session started from a Rex pane inherits that pane's ID, which would be wrong for its own panes, so rxr records nothing and shows nothing there.
-
Language. English by default, Chinese when the first non-empty one of
LC_ALL,LC_MESSAGES,LANGstarts withzh.rxr config set lang enorzhoverrides the locale (see Configuration); the banner,rxrand the installer all follow it. Colors are off whenNO_COLORis set or stderr is not a terminal.
- Rex, with the
rexCLI onPATH. rxr uses it for pane names inrxr -aand for the daily cleanup of closed panes. - zsh as the shell in your Rex panes.
- Python 3.9 or newer. The installer refuses older versions. The Homebrew formula uses macOS's
/usr/bin/python3(Homebrew's Python on Linux). psandlsof(used to check whether a session is still running).- Tested on macOS. Linux should work but has had less testing.
- For agent sessions, any of the supported agents. rxr adds a hook to each agent's own config:
| Agent | Config file | Hook events |
|---|---|---|
| Claude Code | ~/.claude/settings.json ($CLAUDE_CONFIG_DIR/settings.json when set) |
SessionStart, SessionEnd |
| Codex | ~/.codex/hooks.json |
SessionStart, SessionEnd |
| Antigravity CLI | ~/.gemini/config/hooks.json |
SessionStart, PreInvocation |
| Copilot CLI | ~/.copilot/hooks/rxr.json (under $COPILOT_HOME when set), a hook file of rxr's own |
SessionStart, SessionEnd |
| Pi | ~/.pi/agent/extensions/rxr.ts (under $PI_CODING_AGENT_DIR when set), an extension of rxr's own |
session_start, session_shutdown |
| opencode | $OPENCODE_CONFIG_DIR (else $XDG_CONFIG_HOME/opencode, default ~/.config/opencode): plugins/rxr/tui.ts (rxr's own file, auto-discovered by 2.x) and, for 1.x, an entry in tui.json (tui.jsonc when that is the only one) pointing at ~/.local/share/rxr/rxr-opencode.ts (with Homebrew, $(brew --prefix)/opt/rxr/libexec/rxr-opencode.ts) |
the session the TUI shows, and its exit |
The installer skips an agent whose directory (~/.claude, ~/.codex, ~/.gemini/antigravity-cli, ~/.copilot, ~/.pi/agent, ~/.config/opencode) does not exist. Run it (or rxr setup) again after installing that agent.
Codex ignores new hooks until you approve them: after installing, open Codex, run /hooks, and approve the rxr entries. The installer reminds you whenever it changes the Codex hooks.
Known limitation: Codex runs its sessions in a shared background process, so rxr finds the pane through the running Codex TUI on a terminal (codex exec and other non-interactive runs don't count) that starts its sessions in the session's directory: its -C / --cd directory, else its working directory. The directory must match even with a single TUI open, because sessions started remotely from ChatGPT run in the same background process. When no TUI matches, or more than one does (two TUIs in the same directory), rxr can't tell which pane the session belongs to and does not record it. A TUI started with --worktree never matches, since rxr can't know its directory. A codex resume <ID> typed at the prompt is still recorded from the command line.
Copilot CLI, Pi and opencode:
- Copilot CLI: only its interactive UI on a terminal is recorded;
copilot -p/--prompt,--acpand its subcommands are not. Copilot CLI runs as a launcher and a child of the same name; rxr records the launcher, the process your shell started. - Pi: the extension reports only Pi's interactive UI with a saved session, not
--print,--mode json/rpcor--no-session. A session kept with--session-diris found only when the same directory is set inPI_CODING_AGENT_SESSION_DIRor Pi'ssessionDirsetting, andpi --session <ID>finds it only that way too. Pi 1.7.0 and later also tell the terminal how to resume themselves (OSC 7577); rxr works alongside that the same way as with Rex's own restore (see below). - opencode: supports opencode 1.x and 2.x (their TUI plugins; a server plugin would not do, as it does not run in the pane). Only the
opencodecommand is supported (opencode2andopencode2-nodeare not). The plugin reports the session the TUI shows (for a sub-agent's session, the root session it belongs to; in 2.x with multiple tabs open, only the currently active root session), looking once a second. Before offering a session, rxr checks read-only that it is still in opencode's database (select 1 from session_v2 where id = ?whensession_v2exists, elseselect 1 from session where id = ?, nothing else is read); in 2.x, passing-s <ID>for a missing session uses that ID when the first prompt creates a new session. If opencode 2.x migrated an oldertui.jsonintocli.json,cli.jsonmay keep a harmless unusedrxr-opencode.tspath entry while 2.x loadsplugins/rxr/tui.ts; it stays harmless after uninstall too, as 2.x takes it for unsupported, shows no toast and leaves it out of its plugin list. /new,/clear,/resumeand the like in the same process move the pane's entry to the new session.
brew install iTofu/tap/rxr
rxr setupHomebrew can't write to your home directory, so rxr setup adds the ~/.zshrc line and the hook entries. It does what the installer below does, except copying the scripts: they stay where Homebrew put them, and everything it writes points at $(brew --prefix)/opt/rxr/libexec/, a path that stays the same from one version to the next. Preview it with rxr setup --dry-run. Running it again changes nothing. Open a new shell in a Rex pane to start recording.
Coming from
make install? Runmake uninstallin the clone first, then open a new shell (or typecommand rxr setupabove): therxrfunction an open shell already loaded belongs to the old install and doesn't knowsetup. Use one install method at a time. Both keep their record of what they wrote in the same file, so either one's uninstall also takes out the hooks and the~/.zshrcline the other wrote.
If you'd rather not add a tap:
git clone https://github.com/iTofu/rxr
cd rxr
make install # or: python3 install.pyPreview the changes first with make dry-run (python3 install.py --dry-run).
The installer:
- copies
rxr-core,rxr.zshand the opencode 1.x pluginrxr-opencode.tsto~/.local/share/rxr/($XDG_DATA_HOME/rxr); - appends one line ending in
# rxrto~/.zshrc($ZDOTDIR/.zshrcwhenZDOTDIRis set, in the environment or by~/.zshenv). It sourcesrxr.zshin interactive shells inside a Rex pane; - adds the hook entries listed above. For Claude Code and Codex it adds only its own handlers; yours stay as they are, even in the same group. For Antigravity CLI it adds a group of its own named
rxr. For opencode it writesplugins/rxr/tui.ts(auto-discovered by 2.x, without touchingcli.json) and appends one entry totui.json(c)plugin(keeping your plugins' order; skipped whencli.jsonexists and neithertui.jsonnortui.jsoncdoes). Copilot CLI's hook file, Pi's extension and opencode'splugins/rxr/tui.tsare files of rxr's own, written whole (with the path of the installedrxr-corein them). A file of that name that rxr did not write is left alone.
It is safe to run again. Before changing a config file it copies it to ~/.local/state/rxr/.backups/ and prints the copy's path. A JSON file it changes is written back with two-space indentation; its keys and values, and their order, stay as they were. Its output names files and keys, never their content. A config file that is not valid JSON, or not shaped as expected, is left untouched.
The installed rxr-core names its Python in its first line: the interpreter that runs the installer, or the one you pass with make install PYTHON=/usr/bin/python3 (python3 install.py --python /usr/bin/python3). The path is used as written, without following symlinks. Hooks run in your project's directory, where python3 may be a version manager's shim pointing at a version that is not installed; a pinned interpreter keeps them working there.
Open a new shell in a Rex pane to start recording.
With Homebrew:
brew upgrade rxr && rxr setupThe hook entries and the ~/.zshrc line still point at the same path, so they stay as they are and Codex doesn't ask you to approve its hooks again. rxr setup only refreshes rxr's own plugin files (Pi's extension, opencode's plugin) when the new version changed them.
From a clone:
cd rxr
git pull && make installPass the same PYTHON= again if you pinned one; otherwise rxr-core is pinned to the python3 that runs the installer.
Either way, open a new shell afterwards.
rxr list this pane's entries
9D8B
and prefill the resume command of its newest agent session
rxr N prefill entry N (1 is the newest)
rxr -a list the entries of all panes, closed ones included (kept for 90 days)
rxr resume <ID> resume a session: refuse if it is already running somewhere else;
otherwise go back to its launch directory and run the agent's own resume command
(claude --resume / codex resume / agy --resume / copilot --resume= / pi --session / opencode -s)
rxr config list the settings: value, and whether it comes from the config file or is the default
rxr config get KEY | set KEY VALUE | unset KEY
read or change a setting
rxr setup Homebrew install: add the agent hooks and the ~/.zshrc line (--remove: take them out again)
rxr -h show this help
rxr -V print the version
rxr resumeaccepts an ID prefix of 8 or more characters if it matches only one recorded session. Lists show 8 characters of an ID (12 of opencode's, which start withses_and the time). Given a full ID that rxr never recorded, it looks in the session stores of Claude Code, Codex, Antigravity CLI, Copilot CLI, Pi and opencode.- The agent runs in its launch directory; your shell's current directory does not change. A Claude Code session moved with
/cdresumes in the directory it is in now, read from Claude Code's own transcript of the session. If the directory is gone, rxr says so and uses the current directory. - The pre-filled line (and the history line) is
rxr resume <ID> # <native command>only when zsh'sinteractivecommentsoption is set. Without it, zsh would take the comment as part of the command, so the line is justrxr resume <ID>. - The
Last recordedline under each list shows when each agent's hook last fired.nevermeans the hook has not run yet; for Codex, check/hooks. - Exit status: 0 when there is nothing to list or prefill; 2 for a bad argument (no such entry, an ambiguous ID prefix, an unknown setting); 1 when the entry or session can't be resumed (no session ID, not found, already running), or when
rxr config set/unsetcan't write the config file; 130 when you cancelrxr resumewith Ctrl-C.
Settings live in ~/.config/rxr/config ($XDG_CONFIG_HOME/rxr/config): one key = value per line; # starts a comment. Change them with rxr config, or edit the file by hand.
rxr config # lang = auto (default; one of: auto | en | zh)
rxr config set lang zh # Chinese, whatever the locale says
rxr config get lang # zh
rxr config unset lang # back to the default| Key | Values | Default |
|---|---|---|
lang |
auto (follow the locale), en, zh |
auto |
A key the file does not set, or sets to a value rxr doesn't know, has its default. rxr config set refuses unknown keys and values. It replaces the key's line in place and keeps your other lines and comments. The file is written atomically, and its directory is created if needed.
rxr.zshadds a zshpreexecandprecmdhook. Before a command runs, it is written to the pane's record as running; when the prompt comes back, its exit status is filled in.- The agent hooks (and Pi's extension and opencode's plugin) call
rxr-core hook <agent> <start|end>, which tags the entry with the session ID, the agent's process and its launch directory. Only interactive sessions are recorded; sub-agents and non-interactive runs such asclaude -porcopilot -pare skipped. A hook that gives up (apsorlsofthat takes over 3 seconds, say) records nothing and adds one line to.hook-login the state directory: the time and the error's type, nothing about the session. - Each pane is identified by Rex's
REX_BLOCK. Its record is one small file,~/.local/state/rxr/<pane id>($XDG_STATE_HOME/rxr), with at most 10 entries. Only the newest 3 plain commands are kept, plus any still running. The shell and the hooks take turns writing it, through a lock file next to it (.lock-<pane id>); one that waits more than a second or two writes anyway. - On the first prompt of a new shell, if the shell that wrote the pane's last entry is gone, rxr treats it as a restart and prints the banner.
- Once a day,
rxr-core gcasks Rex which panes still exist. The record of a closed pane is deleted 90 days after rxr first sees it closed. If Rex can't be reached, nothing is deleted.
What an entry stores: start and last-update time, state, exit status, agent or cmd, session ID, shell and agent process IDs, launch directory (and Claude Code's last directory), the command line as typed (up to 300 characters) and a repeat count.
Privacy. Records stay on this machine; rxr makes no network requests. The state directory is private (700) and each record file is 600. Commands that start with a space are not recorded, whatever your HIST_IGNORE_SPACE setting is, and neither are commands that match $HISTORY_IGNORE. A command that looks like it holds a secret is stored as <program> [hidden]: only the program name is written to disk. "Looks like" means it contains token, key, secret, password, passwd, auth or bearer anywhere, in any case (so --author counts), or a run of 20 or more letters and digits outside a UUID or an opencode session ID (an ID counts only on its own, not as part of a longer run of letters and digits). An agent started with a leading space is still recorded by its hook, under its session ID, without the command line (for Codex, only if the pane's shell has recorded some other command before).
Rex restores an agent itself when the agent reports how to resume it, through a signed OSC 7577 escape sequence: Rex starts it again with that resume command. At the time of writing, Claude Code reports through the hooks rex skill setup installs, and Pi reports on its own from 1.7.0; Codex, Antigravity CLI, Copilot CLI and opencode don't report. rxr is meant as the fallback for the rest: agents that don't report (rxr resumes them by session ID), plain commands, and sessions the built-in restore did not bring back. Unlike Rex's restore, rxr never runs the command for you: it pre-fills it, and it keeps a history for each pane.
The two don't get in each other's way. Rex restores a pane by running the resume command in the pane's new shell: Rex 1.0 and later from a job scheduled in that shell, earlier versions through a wrapper shell (rex-run). rxr recognizes both, records the restored command, and shows no banner in that pane. If you run rxr resume on a session Rex has already restored, rxr sees it running and refuses.
With Homebrew:
rxr setup --remove
brew uninstall rxrrxr setup --remove takes out what rxr setup added, the same way as below, and leaves the scripts for brew uninstall. Preview it with rxr setup --remove --dry-run.
From a clone:
make uninstall # or: python3 install.py uninstallPreview it with python3 install.py uninstall --dry-run.
- It removes only what the installer added: the scripts, the
~/.zshrcline, rxr's own hook handlers and opencodepluginentry, and rxr's own files (Copilot CLI'shooks/rxr.json, Pi'sextensions/rxr.ts, opencode'splugins/rxr/tui.ts). A config file or directory the installer created and that is now empty is deleted. - It cleans the Copilot CLI, Pi and opencode directories the installer wrote to, even if
COPILOT_HOME,PI_CODING_AGENT_DIRorOPENCODE_CONFIG_DIRhave changed since. Ahooks/rxr.json,extensions/rxr.tsorplugins/rxr/tui.tsthat rxr did not write is left alone, with a note. An opencodepluginlist that was there before install stays, even when it ends up empty. - If a config file can't be cleaned (for example, it is not valid JSON), uninstall names it, keeps the copied files and exits with an error. Remove rxr's entries from it yourself and run uninstall again.
- Your records and config backups stay in
~/.local/state/rxr/, and uninstall prints where they are; delete that directory yourself if you want them gone. - Your settings file
~/.config/rxr/configis never touched; uninstall says so.
Bug reports, fixes, and support for more agent CLIs are welcome — see CONTRIBUTING.md.
MIT. See LICENSE.