tmux + OpenCode reference

Running the laptop’s local AI (OpenCode + llama-server) inside tmux, so you can start it on one machine and watch it from another.

0. tmux is installed (3.6, installed 2026-11-18)

tmux is on the laptop now — no install step needed. If it ever goes missing (e.g. after a rebuild), reinstall it on the laptop, as mtayter:

sudo apt update && sudo apt install -y tmux

The mental model

There are three separate pieces. Knowing which one you’re touching is the whole trick:

1. Start an OpenCode session in tmux

ssh mtayter-laptop
tmux new -s opencode
cd ~/vm-escape && opencode --continue

Notes:

2. Watch the same session from a different machine

SSH in from the other machine, then attach to the same tmux session. Both machines see the same screen, live.

ssh mtayter-laptop
tmux attach -t opencode

Variations:

CommandWhat it does
tmux lsList tmux sessions on the laptop.
tmux attach -t opencodeAttach (shared view — both machines can type).
tmux attach -t opencode -rAttach read-only (watch, can’t type).

3. Leave without stopping anything (detach)

Inside tmux, press Ctrl-b then d (release Ctrl-b before pressing d). This is the one to use when you’re done looking.

Don’t use Ctrl-d to leave. In OpenCode, Ctrl-d quits the TUI. Detach is always Ctrl-b then d.

3a. Scrolling back through messages

Scroll inside OpenCode, not in tmux. The TUI draws on the terminal’s alternate screen and redraws in place, so tmux never sees the older lines — tmux copy mode (Ctrl-b then [) can only go back to the top of the current screen, and raising tmux’s scrollback limit won’t help.

KeyWhat it does
PageUp / Ctrl+Alt+BPage up through messages.
PageDown / Ctrl+Alt+FPage down through messages.
Ctrl+Alt+U / Ctrl+Alt+DHalf page up / down.
Ctrl+G / HomeJump to the first message.
Ctrl+Alt+G / EndJump to the last message.
Ctrl+?Open the TUI help dialog with the live key list.

The mouse wheel also scrolls the messages, if the terminal passes it through. While scrolled up, the TUI keeps running underneath — you’re just looking at older output.

In Termius (phone/tablet): swiping Termius’s own view won’t scroll the TUI. Send a real PgUp keystroke instead — add PgUp/PgDn to Termius’s extra-keys bar above the on-screen keyboard, or map a gesture (or shake) to PgUp/PgDn in Termius’s terminal/gestures settings. A Bluetooth keyboard’s real PgUp key just works. If neither is handy, Ctrl+G (first message) and Ctrl+Alt+G (last message) only need the Ctrl key, which is on the extra-keys bar.

4. Exit the TUI but keep the agent running

Press Ctrl-C in the TUI. If a turn is running you’ll get a quit confirmation — the turn keeps running in the background service either way. To look again later: tmux attach -t opencode, then run opencode --continue in a shell if the TUI isn’t there anymore.

Don’t type /exit — it isn’t an OpenCode command (it opens an agent selector instead). Ctrl-C is the way out.

5. Interrupt the current turn (abort it)

Press Esc in the TUI. The turn is abandoned and marked failed, but everything it did so far is saved in the session. To pick the work back up, type continue in the TUI.

A crashed or interrupted turn does not auto-resume — after reattaching and running opencode --continue, type continue.

6. Pause the agent — and how that differs from stopping it

Pausing is not stopping.

CommandWhat happens
Pause (freeze)~/pause-opencodeFreezes the agent mid-thought (SIGSTOP on the background service). The TUI just looks still. Nothing is lost.
Resume~/pause-opencode resumeThe turn continues exactly where it froze.
Stop (abort turn)Esc in the TUIEnds the current turn. The session is saved; type continue to pick it up again. Not the same as pausing — the turn does not resume mid-thought.
Hard stop (rare)pkill -f 'opencode.exe serve'Kills the background service outright. The session survives in the database; reopen with opencode --continue. Only if the service itself is wedged.

7. Stop the model server (llama-server)

~/stop-dense

This stops the serve-dense unit and verifies the unit is inactive, port 8080 is free, and no llama-server is left. Or directly:

systemctl --user stop serve-dense
Ctrl-C does not stop it. The server runs as a systemd unit — Ctrl-C in its terminal only kills the waiting systemd-run process, and the server keeps running on port 8080. Always stop it with ~/stop-dense or systemctl --user stop serve-dense.

Order matters: pause the agent (~/pause-opencode) or abort its turn (Esc) before stopping the server, or the agent’s model calls will fail. To start everything again:

~/serve-dense
~/stop-dense --check        # wait until it reports active / listening
cd ~/vm-escape && opencode --continue

8. Status checks

CommandTells you
tmux lsWhich tmux sessions exist.
~/stop-dense --checkModel server active? Port 8080 listening? Free memory?
systemctl --user status serve-denseServer unit state and recent log lines.
pgrep -a -x llama-serverWhether the model server process is alive.
pgrep -a -f 'opencode.exe serve'Whether the OpenCode background service is alive.

9. Your setup (stable facts)

10. Gotchas