$npx -y skills add volcengine/OpenViking --skill tmuxRemote-control tmux sessions for interactive CLIs by sending keystrokes and scraping pane output.
| 1 | # tmux Skill |
| 2 | |
| 3 | Use tmux only when you need an interactive TTY. Prefer exec background mode for long-running, non-interactive tasks. |
| 4 | |
| 5 | ## Quickstart (isolated socket, exec tool) |
| 6 | |
| 7 | ```bash |
| 8 | SOCKET_DIR="${NANOBOT_TMUX_SOCKET_DIR:-${TMPDIR:-/tmp}/vikingbot-tmux-sockets}" |
| 9 | mkdir -p "$SOCKET_DIR" |
| 10 | SOCKET="$SOCKET_DIR/vikingbot.sock" |
| 11 | SESSION=vikingbot-python |
| 12 | |
| 13 | tmux -S "$SOCKET" new -d -s "$SESSION" -n shell |
| 14 | tmux -S "$SOCKET" send-keys -t "$SESSION":0.0 -- 'PYTHON_BASIC_REPL=1 python3 -q' Enter |
| 15 | tmux -S "$SOCKET" capture-pane -p -J -t "$SESSION":0.0 -S -200 |
| 16 | ``` |
| 17 | |
| 18 | After starting a session, always print monitor commands: |
| 19 | |
| 20 | ``` |
| 21 | To monitor: |
| 22 | tmux -S "$SOCKET" attach -t "$SESSION" |
| 23 | tmux -S "$SOCKET" capture-pane -p -J -t "$SESSION":0.0 -S -200 |
| 24 | ``` |
| 25 | |
| 26 | ## Socket convention |
| 27 | |
| 28 | - Use `NANOBOT_TMUX_SOCKET_DIR` environment variable. |
| 29 | - Default socket path: `"$NANOBOT_TMUX_SOCKET_DIR/vikingbot.sock"`. |
| 30 | |
| 31 | ## Targeting panes and naming |
| 32 | |
| 33 | - Target format: `session:window.pane` (defaults to `:0.0`). |
| 34 | - Keep names short; avoid spaces. |
| 35 | - Inspect: `tmux -S "$SOCKET" list-sessions`, `tmux -S "$SOCKET" list-panes -a`. |
| 36 | |
| 37 | ## Finding sessions |
| 38 | |
| 39 | - List sessions on your socket: `{baseDir}/scripts/find-sessions.sh -S "$SOCKET"`. |
| 40 | - Scan all sockets: `{baseDir}/scripts/find-sessions.sh --all` (uses `NANOBOT_TMUX_SOCKET_DIR`). |
| 41 | |
| 42 | ## Sending input safely |
| 43 | |
| 44 | - Prefer literal sends: `tmux -S "$SOCKET" send-keys -t target -l -- "$cmd"`. |
| 45 | - Control keys: `tmux -S "$SOCKET" send-keys -t target C-c`. |
| 46 | |
| 47 | ## Watching output |
| 48 | |
| 49 | - Capture recent history: `tmux -S "$SOCKET" capture-pane -p -J -t target -S -200`. |
| 50 | - Wait for prompts: `{baseDir}/scripts/wait-for-text.sh -t session:0.0 -p 'pattern'`. |
| 51 | - Attaching is OK; detach with `Ctrl+b d`. |
| 52 | |
| 53 | ## Spawning processes |
| 54 | |
| 55 | - For python REPLs, set `PYTHON_BASIC_REPL=1` (non-basic REPL breaks send-keys flows). |
| 56 | |
| 57 | ## Windows / WSL |
| 58 | |
| 59 | - tmux is supported on macOS/Linux. On Windows, use WSL and install tmux inside WSL. |
| 60 | - This skill is gated to `darwin`/`linux` and requires `tmux` on PATH. |
| 61 | |
| 62 | ## Orchestrating Coding Agents (Codex, Claude Code) |
| 63 | |
| 64 | tmux excels at running multiple coding agents in parallel: |
| 65 | |
| 66 | ```bash |
| 67 | SOCKET="${TMPDIR:-/tmp}/codex-army.sock" |
| 68 | |
| 69 | # Create multiple sessions |
| 70 | for i in 1 2 3 4 5; do |
| 71 | tmux -S "$SOCKET" new-session -d -s "agent-$i" |
| 72 | done |
| 73 | |
| 74 | # Launch agents in different workdirs |
| 75 | tmux -S "$SOCKET" send-keys -t agent-1 "cd /tmp/project1 && codex --yolo 'Fix bug X'" Enter |
| 76 | tmux -S "$SOCKET" send-keys -t agent-2 "cd /tmp/project2 && codex --yolo 'Fix bug Y'" Enter |
| 77 | |
| 78 | # Poll for completion (check if prompt returned) |
| 79 | for sess in agent-1 agent-2; do |
| 80 | if tmux -S "$SOCKET" capture-pane -p -t "$sess" -S -3 | grep -q "❯"; then |
| 81 | echo "$sess: DONE" |
| 82 | else |
| 83 | echo "$sess: Running..." |
| 84 | fi |
| 85 | done |
| 86 | |
| 87 | # Get full output from completed session |
| 88 | tmux -S "$SOCKET" capture-pane -p -t agent-1 -S -500 |
| 89 | ``` |
| 90 | |
| 91 | **Tips:** |
| 92 | - Use separate git worktrees for parallel fixes (no branch conflicts) |
| 93 | - `pnpm install` first before running codex in fresh clones |
| 94 | - Check for shell prompt (`❯` or `$`) to detect completion |
| 95 | - Codex needs `--yolo` or `--full-auto` for non-interactive fixes |
| 96 | |
| 97 | ## Cleanup |
| 98 | |
| 99 | - Kill a session: `tmux -S "$SOCKET" kill-session -t "$SESSION"`. |
| 100 | - Kill all sessions on a socket: `tmux -S "$SOCKET" list-sessions -F '#{session_name}' | xargs -r -n1 tmux -S "$SOCKET" kill-session -t`. |
| 101 | - Remove everything on the private socket: `tmux -S "$SOCKET" kill-server`. |
| 102 | |
| 103 | ## Helper: wait-for-text.sh |
| 104 | |
| 105 | `{baseDir}/scripts/wait-for-text.sh` polls a pane for a regex (or fixed string) with a timeout. |
| 106 | |
| 107 | ```bash |
| 108 | {baseDir}/scripts/wait-for-text.sh -t session:0.0 -p 'pattern' [-F] [-T 20] [-i 0.5] [-l 2000] |
| 109 | ``` |
| 110 | |
| 111 | - `-t`/`--target` pane target (required) |
| 112 | - `-p`/`--pattern` regex to match (required); add `-F` for fixed string |
| 113 | - `-T` timeout seconds (integer, default 15) |
| 114 | - `-i` poll interval seconds (default 0.5) |
| 115 | - `-l` history lines to search (integer, default 1000) |