Skip to content

guysoft/tmux-resurrect-opencode-sessions

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 

Repository files navigation

tmux-resurrect-opencode-sessions

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.

How It Works

  1. OpenCode sets the tmux pane title to OC | <session title> for every active session.
  2. tmux-resurrect saves pane titles in its save file (every 15 minutes via tmux-continuum, or on manual save).
  3. 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 opencode to opencode --session <id>
  4. On restore, tmux-resurrect runs the rewritten command, and OpenCode resumes the exact session.

Requirements

Installation

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.

Manual

Clone the repo into your tmux plugins directory:

git clone https://github.com/YOUR_USER/tmux-resurrect-opencode-sessions \
    ~/.tmux/plugins/tmux-resurrect-opencode-sessions

Add this line to ~/.tmux.conf:

run-shell ~/.tmux/plugins/tmux-resurrect-opencode-sessions/opencode-sessions.tmux

Usage

Once 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.

How It Works (Technical Details)

Save Flow

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

Restore Flow

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

Save File Format

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.

Troubleshooting

OpenCode panes still open fresh sessions after restore

  1. Check that sqlite3 is installed: which sqlite3
  2. Check that the OpenCode database exists: ls ~/.local/share/opencode/opencode.db
  3. Trigger a manual save (prefix + Ctrl-s), then inspect the save file:
    grep opencode ~/.local/share/tmux/resurrect/last
    You should see lines like :opencode --session ses_... in the last column.

Some panes restored but with the wrong session

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.

The plugin conflicts with another resurrect hook

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-layout

License

GPL-3.0. See LICENSE for details.

About

Tmux plugin that preserves OpenCode sessions across tmux restarts. Works with tmux-resurrect.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages