Automatically Restore Codex Sessions with tmux
This macOS setup saves a tmux workspace and restores each identified Codex conversation with its full session UUID and working directory. It combines tmux-resurrect, tmux-continuum, a local recovery tool, and a LaunchAgent.
Key points
- Save the current session ID. Resume each identified conversation with its full UUID. Do not select it by name or
--last. - Use one set of wrappers. Manual actions, scheduled saves, and restore operations share the same file lock and snapshot checks.
- Use two schedules. Continuum saves every five minutes. A LaunchAgent checks for changes approximately every 15 seconds.
- Keep servers separate. Each tmux server needs its own snapshot directory.
- Restore saved history, not running processes. In-flight requests and tool tasks are outside the recovery scope.
The excerpts below show the final configuration structure. All machine-specific paths and service labels are placeholders. They require an existing local recovery tool; the plugins alone do not provide the Codex identity checks described here.
1. Expose the current Codex session ID
Add this setting to the existing [tui] section in your Codex configuration:
[tui]
terminal_title = ["session-id", "thread", "project"]
The recovery tool reads the native ID at the start of the pane title. It resolves abbreviated IDs against the local Codex database and requires a unique match, saved user history, and an existing working directory.
The saved command uses the full UUID:
codex resume <SESSION_UUID>
The working directory is stored separately in the tmux layout. The resolver uses the current conversation identity, including after switching conversations within the client. It does not infer identity from a name, directory, or recent activity.
See the Codex command reference for the resume command.
2. Connect tmux to the recovery wrappers
The local tool provides four entry points:
| Entry point | Purpose |
|---|---|
configure | Set wrapper paths and register the current server socket |
save | Save and validate a snapshot |
restore | Validate a snapshot and start the saved conversations |
hook | Add exact Codex identities to the saved layout |
Replace /absolute/path/to/tmux-codex with the tool’s installation directory. Merge the following settings into your tmux configuration, with only one TPM initialization block:
# Prefix: Ctrl-a
unbind C-b
set -g prefix C-a
bind-key C-a send-prefix
set -g @plugin 'tmux-plugins/tpm'
set -g @plugin 'tmux-plugins/tmux-resurrect'
set -g @plugin 'tmux-plugins/tmux-continuum'
set -g @continuum-restore 'on'
set -g @resurrect-processes '"~(^|[ /])codex( |$)"'
run '~/.tmux/plugins/tpm/tpm'
# Configure custom entry points after loading the plugins.
set -g @continuum-save-interval '5'
set -g @resurrect-capture-pane-contents 'on'
set -g @resurrect-dir '/absolute/path/to/snapshots/server-a'
set -g @resurrect-hook-post-save-layout '/absolute/path/to/tmux-codex/hook'
set -g @resurrect-save-script-path '/absolute/path/to/tmux-codex/save'
set -g @resurrect-restore-script-path '/absolute/path/to/tmux-codex/restore'
bind-key C-s run-shell '/absolute/path/to/tmux-codex/save'
bind-key C-r run-shell '/absolute/path/to/tmux-codex/restore'
set -ag status-right ' #[fg=red,bold]#{@codex-restore-warning}#[default]'
run-shell '/absolute/path/to/tmux-codex/configure'
set-environment -gu NO_COLOR
tmux-resurrect saves and rebuilds the workspace. tmux-continuum schedules saves and restores the workspace when tmux starts. Give every server a different @resurrect-dir.
The tool also needs explicit executable paths for tmux, Python, Codex, and the plugin helpers. On Apple Silicon, this setup uses Homebrew executables under /opt/homebrew/bin. Before restoring panes, the tool finds the current Codex executable and checks it with --version.
The final line clears tmux’s inherited NO_COLOR variable. The wrapper also removes it from child environments. Existing processes retain their own environment.
3. Add the change watcher
Use a LaunchAgent to run recovery.py watch. This template checks every 15 seconds. Replace the paths and service label, and create the log directory before loading it.
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN"
"http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Label</key>
<string>com.example.codex-tmux-save</string>
<key>ProgramArguments</key>
<array>
<string>/opt/homebrew/bin/python3</string>
<string>/absolute/path/to/tmux-codex/recovery.py</string>
<string>watch</string>
</array>
<key>EnvironmentVariables</key>
<dict>
<key>PATH</key>
<string>/opt/homebrew/bin:/usr/bin:/bin:/usr/sbin:/sbin</string>
</dict>
<key>RunAtLoad</key>
<true/>
<key>StartInterval</key>
<integer>15</integer>
<key>StandardOutPath</key>
<string>/absolute/path/to/logs/save.log</string>
<key>StandardErrorPath</key>
<string>/absolute/path/to/logs/error.log</string>
</dict>
</plist>
The watcher checks existing servers. It saves when the pane signature changes, retries a failed save, and checks the selected snapshot before skipping unchanged state.
Fifteen seconds is a check interval, not a maximum data-loss window. Scheduling requires the user to be logged in and the Mac to be awake. The agent does not start tmux; startup restore occurs when tmux starts.
4. Save, restore, and check
| Action | Entry point |
|---|---|
| Save now | Ctrl-a Ctrl-s |
| Restore | Ctrl-a Ctrl-r |
| Check the watcher | launchctl print gui/$(id -u)/com.example.codex-tmux-save |
| Check save status | codex-state.json in the snapshot directory |
| Inspect logs | The paths configured in the LaunchAgent |
Each snapshot generation contains a layout (.txt), identity manifest (.json), and screen archive (.tar.gz). Save and restore share .codex-save.lock. The saver checks staged files before updating last; restore uses the archive from the selected generation.
Use the wrappers rather than the plugin’s original save.sh. Keep each generation’s three files together when managing retention.
Restore into a fresh server with no work to preserve. If the original server and processes are still running, attach directly. After a restore, check the full UUID, visible saved history, and actual working directory.
Supported scope
An identity that cannot be resolved at save time gets a resume picker and a RESTORE! warning. Other panes retain their exact IDs. Restore preparation stops if a pinned session has missing history, a missing directory, or a command that conflicts with its manifest.
On November 3, 2026, all 12 disposable regression checks passed. Archived isolated-server tests also cover history recovery and working directories. No production restart, machine reboot, or power-loss test was performed for this article. The checkpoint inspected that day contained 26 Codex panes: 25 had full UUIDs and one remained unresolved.
Snapshot retention is manual. The layout format does not support tabs or newlines in names and paths. Plugin and Codex storage changes require compatibility checks. A custom CODEX_HOME is supported in code but has not had a separate live-login restore test. Snapshot publication uses locking and validation, without a complete sudden-power-loss durability guarantee.