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:
- tmux — a terminal session that lives on the laptop. It survives SSH disconnects. Detaching from it, killing its window, or closing your laptop lid does not stop anything inside it.
- OpenCode — two parts: the TUI (the screen you look at) and a background service that owns the running turn. Quitting, detaching, or killing the TUI never stops a running turn — the service keeps going.
- llama-server (the model, port 8080) — separate from both. OpenCode talks to it over HTTP. Stopping it while the agent is mid-turn makes the agent’s calls fail, so pause or stop the agent first.
1. Start an OpenCode session in tmux
ssh mtayter-laptop
tmux new -s opencode
cd ~/vm-escape && opencode --continue
Notes:
opencode --continueresumes your last session.opencodealone starts a brand-new session.- Resume a specific session:
opencode --session ses_e38fb7839ffe8R2Le7xeDBGrgq(the bug-bounty session). - If the model server isn’t running, start it first in another window:
~/serve-dense, wait for it to load, then start OpenCode. Check it with~/stop-dense --check.
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:
| Command | What it does |
|---|---|
tmux ls | List tmux sessions on the laptop. |
tmux attach -t opencode | Attach (shared view — both machines can type). |
tmux attach -t opencode -r | Attach 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.
- tmux, the TUI, and the agent all keep running on the laptop.
- Reattach later from any machine:
tmux attach -t opencode.
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.
| Key | What it does |
|---|---|
| PageUp / Ctrl+Alt+B | Page up through messages. |
| PageDown / Ctrl+Alt+F | Page down through messages. |
| Ctrl+Alt+U / Ctrl+Alt+D | Half page up / down. |
| Ctrl+G / Home | Jump to the first message. |
| Ctrl+Alt+G / End | Jump 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.
/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.
| Command | What happens | |
|---|---|---|
| Pause (freeze) | ~/pause-opencode | Freezes the agent mid-thought (SIGSTOP on the background service). The TUI just looks still. Nothing is lost. |
| Resume | ~/pause-opencode resume | The turn continues exactly where it froze. |
| Stop (abort turn) | Esc in the TUI | Ends 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
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
| Command | Tells you |
|---|---|
tmux ls | Which tmux sessions exist. |
~/stop-dense --check | Model server active? Port 8080 listening? Free memory? |
systemctl --user status serve-dense | Server unit state and recent log lines. |
pgrep -a -x llama-server | Whether the model server process is alive. |
pgrep -a -f 'opencode.exe serve' | Whether the OpenCode background service is alive. |
9. Your setup (stable facts)
- Laptop:
ssh mtayter-laptop— log in asmtayter. - Model server: llama.cpp v0.8.0, dense Qwen 27B,
127.0.0.1:8080, aliasqwen3.8-dense, 64k context, Q8 KV cache. - OpenCode service:
127.0.0.1:49374. Sessions live in~/.local/share/opencode/opencode.db. - Scripts in
/home/mtayter:serve-dense(start server),stop-dense(stop/check server),pause-opencode(freeze/resume agent). - Main session directory:
~/vm-escape. Bug-bounty session id:ses_e38fb7839ffe8R2Le7xeDBGrgq. - The laptop has no
curl— usepython3for HTTP checks in scripts.
10. Gotchas
- Killing the tmux session (
tmux kill-session -t opencode) kills the TUI but not a running turn — the service owns the turn. You’ll need to reopen the TUI to see it again. - Two machines attached at once both see the same screen and both can type. Last typer wins.
- Scrollback: don’t use tmux copy mode (Ctrl-b then [) — it can’t see past the current screen in a full-screen TUI. Scroll inside OpenCode instead; see §3a.
- After a laptop reboot, tmux sessions are gone. The OpenCode session survives in its database: start the server (
~/serve-dense), thencd ~/vm-escape && opencode --continue. - Detaching mid-turn is fine. The agent keeps working with nobody watching.