Summary
Add a single-key workflow that opens a fork of the currently active OpenCode session in a new tmux pane.
The resulting pane must inherit the current working directory and load the exact current OpenCode session as a fork, allowing both sessions to continue independently side by side.
Desired UX
While focused inside an active OpenCode TUI session running in tmux:
- Press one configured keybind.
- A new tmux pane opens, preferably to the right of the current pane.
- The new pane starts OpenCode in the same working directory.
- OpenCode forks the exact session that was active when the keybind was pressed.
- The original pane and session remain untouched.
The user must not need to:
- manually copy a session ID
- open the session picker
- type a shell command into the OpenCode prompt
- infer the current session from timestamps, titles, or working-directory heuristics
Repository context
Relevant existing files and conventions:
.tmux.conf
- tmux prefix is
C-a
- directional pane splits already preserve
#{pane_current_path}
- tmux configuration is currently kept in this root file
.config/opencode/opencode.json
- contains the active OpenCode plugin configuration
.config/opencode/
- appropriate location for an OpenCode plugin or TUI configuration, if required
scripts/
- appropriate location for a reusable executable helper, if required
.config/opencode/context/domain/dotfiles-architecture.md
- repository uses GNU Stow
- scripts should be idempotent and pass ShellCheck
- commits should use Conventional Commits
Do not edit backup files such as *.bak unless there is a specific documented reason.
Investigation required
Before implementing, verify the capabilities of the currently installed/supported OpenCode version rather than relying on stale examples.
Determine:
- Whether OpenCode keybindings can invoke a custom command or plugin action.
- Whether an OpenCode plugin hook, custom command, environment variable, API, or CLI command can reliably expose the exact active session ID.
- The current supported CLI syntax for opening a session and forking it.
- Whether OpenCode already ships a native action or command that can be composed with tmux.
- Whether Oh My OpenAgent or another already-installed plugin provides this behavior.
Prefer documented, stable APIs. Do not query OpenCode's internal database using directory/time heuristics unless no supported mechanism exists, and do not use such a heuristic silently.
Preferred implementation shape
Choose the smallest reliable design after completing the investigation.
A likely shape is:
OpenCode keybind or tmux keybind
↓
OpenCode-aware command/plugin obtains exact active session ID
↓
small helper invokes tmux split-window
↓
new pane runs OpenCode with the session ID and fork option
Possible components may include:
- a custom OpenCode plugin/action under
.config/opencode/
- a custom OpenCode command under
.config/opencode/command/
- a helper script under
scripts/
- a tmux binding in
.tmux.conf
- a TUI keybinding config file if supported by the installed OpenCode version
These are implementation options, not mandatory files. Avoid unnecessary layers.
Functional requirements
Session correctness
- The newly opened OpenCode instance must fork the exact active session.
- It must not pick merely the newest session in the same directory.
- It must not attach to and mutate the same session concurrently.
- The original session must remain active and unchanged.
tmux behavior
- Open the fork in a new tmux pane.
- Default placement should be a horizontal split opening to the right, unless existing conventions make another placement more appropriate.
- Start the new pane in the current pane's working directory.
- Preserve paths containing spaces or shell metacharacters.
- Do not interpolate the session ID or working directory unsafely.
- Do not use
tmux kill-server or alter unrelated tmux state.
Keybinding
- Provide a single ergonomic keybind while OpenCode is focused.
- Prefer an OpenCode-native keybind if custom actions are supported cleanly.
- Otherwise, use a tmux keybind that behaves reliably without typing text into the OpenCode prompt.
- Check for conflicts with existing tmux and OpenCode bindings before choosing the final key.
- Document the chosen key and how to change it.
Failure handling
Provide clear, non-destructive errors for at least:
- command invoked outside tmux
- no active OpenCode session ID available
opencode missing from PATH
- tmux pane creation failure
- unsupported OpenCode version/API
The current OpenCode session must continue normally if pane creation fails.
Maintainability
- Keep the helper focused and readable.
- Use
set -euo pipefail for Bash unless another shell or language is better justified.
- Pass ShellCheck for shell files.
- Avoid hard-coded absolute home-directory paths.
- Follow the repository's GNU Stow layout.
- Do not introduce a dependency unless the benefit is substantial and documented.
Acceptance criteria
Manual test plan
- Start tmux and open a repository whose path contains no spaces.
- Start OpenCode and create enough conversation history to identify the session.
- Trigger the new keybind.
- Confirm a new pane opens on the expected side.
- Confirm the new pane starts in the same repository.
- Confirm the fork contains the original session history.
- Send a distinct message in the fork and verify the original session does not change.
- Repeat with two active OpenCode sessions in the same working directory and confirm the correct source session is forked.
- Repeat in a directory whose path contains spaces.
- Invoke the helper outside tmux and verify the error is clear.
- Temporarily simulate a missing session ID and verify no unrelated OpenCode session is opened.
- Reload
.tmux.conf and confirm existing keybindings still work.
Deliverables
- implementation in the appropriate dotfiles paths
- any required OpenCode/tmux configuration
- concise documentation of:
- chosen keybind
- implementation approach
- how the active session ID is obtained
- how to change pane direction or keybind
- known OpenCode version requirements
- verification notes or screenshots showing the original session and its independent fork side by side
Non-goals
- building a general tmux session manager
- changing the normal OpenCode
session_fork behavior globally
- automatically creating git branches or worktrees
- forking background subagents
- restoring sessions after reboot
- adding broad tmux layout management
Implementation note
If OpenCode cannot expose the current session ID to an external command through a supported API, stop and document the limitation in the PR before introducing database inspection or heuristic session selection. A reliable partial solution is preferable to a shortcut that occasionally forks the wrong session.
Summary
Add a single-key workflow that opens a fork of the currently active OpenCode session in a new tmux pane.
The resulting pane must inherit the current working directory and load the exact current OpenCode session as a fork, allowing both sessions to continue independently side by side.
Desired UX
While focused inside an active OpenCode TUI session running in tmux:
The user must not need to:
Repository context
Relevant existing files and conventions:
.tmux.confC-a#{pane_current_path}.config/opencode/opencode.json.config/opencode/scripts/.config/opencode/context/domain/dotfiles-architecture.mdDo not edit backup files such as
*.bakunless there is a specific documented reason.Investigation required
Before implementing, verify the capabilities of the currently installed/supported OpenCode version rather than relying on stale examples.
Determine:
Prefer documented, stable APIs. Do not query OpenCode's internal database using directory/time heuristics unless no supported mechanism exists, and do not use such a heuristic silently.
Preferred implementation shape
Choose the smallest reliable design after completing the investigation.
A likely shape is:
Possible components may include:
.config/opencode/.config/opencode/command/scripts/.tmux.confThese are implementation options, not mandatory files. Avoid unnecessary layers.
Functional requirements
Session correctness
tmux behavior
tmux kill-serveror alter unrelated tmux state.Keybinding
Failure handling
Provide clear, non-destructive errors for at least:
opencodemissing fromPATHThe current OpenCode session must continue normally if pane creation fails.
Maintainability
set -euo pipefailfor Bash unless another shell or language is better justified.Acceptance criteria
Manual test plan
.tmux.confand confirm existing keybindings still work.Deliverables
Non-goals
session_forkbehavior globallyImplementation note
If OpenCode cannot expose the current session ID to an external command through a supported API, stop and document the limitation in the PR before introducing database inspection or heuristic session selection. A reliable partial solution is preferable to a shortcut that occasionally forks the wrong session.