A tmux plugin that preserves OpenCode sessions across tmux restarts.
When tmux dies and tmux-resurrect restores your panes, OpenCode panes normally come back as empty shells. This plugin makes them resume the exact session they were running before.
- OpenCode sets the tmux pane title to
OC | <session title>for every active session. - tmux-resurrect saves pane titles in its save file (every 15 minutes via tmux-continuum, or on manual save).
- After each save, this plugin's hook:
- Extracts the session title from each OpenCode pane
- Queries the OpenCode SQLite database to find the matching session ID
- Rewrites the saved command from
opencodetoopencode --session <id>
- On restore, tmux-resurrect runs the rewritten command, and OpenCode resumes the exact session.
- tmux >= 2.0
- tmux-resurrect
- OpenCode
sqlite3(command-line tool)
With TPM (recommended)
Add this line to your ~/.tmux.conf, after tmux-resurrect and before the TPM init line:
set -g @plugin 'tmux-plugins/tmux-resurrect'
set -g @plugin 'tmux-plugins/tmux-continuum' # optional, for auto-save/restore
set -g @plugin 'tmux-resurrect-opencode-sessions' # <-- add this
# Initialize TPM (keep at the very bottom)
run '~/.tmux/plugins/tpm/tpm'Then press prefix + I to install.
Clone the repo into your tmux plugins directory:
git clone https://github.com/YOUR_USER/tmux-resurrect-opencode-sessions \
~/.tmux/plugins/tmux-resurrect-opencode-sessionsAdd this line to ~/.tmux.conf:
run-shell ~/.tmux/plugins/tmux-resurrect-opencode-sessions/opencode-sessions.tmuxOnce installed, the plugin works automatically. No configuration needed.
- Save:
prefix + Ctrl-s(or automatic via tmux-continuum) - Restore:
prefix + Ctrl-r(or automatic on tmux server start via tmux-continuum)
After a restore, each pane that was running OpenCode will resume the same session it had before.
tmux-resurrect saves pane state
|
v
post-save-layout hook fires
|
v
For each pane where command = "opencode"
and pane title starts with "OC | ":
|
v
Extract title -> query SQLite DB -> get session ID
|
v
Rewrite command: "opencode -c" -> "opencode --session ses_abc123"
|
v
Modified save file written back
tmux-resurrect reads save file
|
v
Sees "opencode --session ses_abc123"
(matches "opencode" in @resurrect-processes)
|
v
Sends command to pane via send-keys
|
v
OpenCode resumes the exact session
tmux-resurrect saves pane state in a tab-delimited text file. The relevant fields:
| Field | Description |
|---|---|
| Column 7 | Pane title (e.g., OC | My session title...) |
| Column 10 | Pane command (e.g., opencode) |
| Column 11 | Full command (e.g., :opencode -c) |
The plugin rewrites Column 11 with the session-specific command.
- Check that
sqlite3is installed:which sqlite3 - Check that the OpenCode database exists:
ls ~/.local/share/opencode/opencode.db - Trigger a manual save (
prefix + Ctrl-s), then inspect the save file:You should see lines likegrep opencode ~/.local/share/tmux/resurrect/last:opencode --session ses_...in the last column.
This can happen if multiple sessions have very similar titles (matching the same prefix). OpenCode session titles are usually unique enough that this is rare. The plugin picks the most recently updated session when there are multiple matches.
This plugin uses the @resurrect-hook-post-save-layout hook. If another plugin also uses this hook, the plugin will chain them together with && so both run. If you experience issues, check:
tmux show-option -gv @resurrect-hook-post-save-layoutGPL-3.0. See LICENSE for details.