Run opencode as a server and attach to it
headless & scripting
// what it does
opencode serve starts a headless HTTP API (default port 4096) that scripts, clients, or a remote TUI can drive; opencode web adds a browser UI on top. opencode attach http://host:4096 connects your local TUI to a session running on another machine.
// shell
$ opencode serve --port 4096$ opencode web --port 4096$ opencode attach http://localhost:4096// gotcha
serve binds to localhost by default; exposing it with --hostname 0.0.0.0 puts a file-editing, shell-running agent on your network. Require authentication and do not leave it open. --cors controls which browser origins the web UI accepts.