tmux

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

tmux Skill (OpenClaw)

tmux 技能(OpenClaw)

Use tmux only when you need an interactive TTY. Prefer exec background mode for long-running, non-interactive tasks.
仅在需要交互式TTY时使用tmux。对于长时间运行的非交互式任务,优先使用exec后台模式。

Quickstart (isolated socket, exec tool)

快速入门(独立套接字,exec工具)

bash
SOCKET_DIR="${OPENCLAW_TMUX_SOCKET_DIR:-${CLAWDBOT_TMUX_SOCKET_DIR:-${TMPDIR:-/tmp}/openclaw-tmux-sockets}}"
mkdir -p "$SOCKET_DIR"
SOCKET="$SOCKET_DIR/openclaw.sock"
SESSION=openclaw-python

tmux -S "$SOCKET" new -d -s "$SESSION" -n shell
tmux -S "$SOCKET" send-keys -t "$SESSION":0.0 -- 'PYTHON_BASIC_REPL=1 python3 -q' Enter
tmux -S "$SOCKET" capture-pane -p -J -t "$SESSION":0.0 -S -200
After starting a session, always print monitor commands:
To monitor:
  tmux -S "$SOCKET" attach -t "$SESSION"
  tmux -S "$SOCKET" capture-pane -p -J -t "$SESSION":0.0 -S -200
bash
SOCKET_DIR="${OPENCLAW_TMUX_SOCKET_DIR:-${CLAWDBOT_TMUX_SOCKET_DIR:-${TMPDIR:-/tmp}/openclaw-tmux-sockets}}"
mkdir -p "$SOCKET_DIR"
SOCKET="$SOCKET_DIR/openclaw.sock"
SESSION=openclaw-python

tmux -S "$SOCKET" new -d -s "$SESSION" -n shell
tmux -S "$SOCKET" send-keys -t "$SESSION":0.0 -- 'PYTHON_BASIC_REPL=1 python3 -q' Enter
tmux -S "$SOCKET" capture-pane -p -J -t "$SESSION":0.0 -S -200
启动会话后,务必打印监控命令:
To monitor:
  tmux -S "$SOCKET" attach -t "$SESSION"
  tmux -S "$SOCKET" capture-pane -p -J -t "$SESSION":0.0 -S -200

Socket convention

套接字约定

  • Use
    OPENCLAW_TMUX_SOCKET_DIR
    (legacy
    CLAWDBOT_TMUX_SOCKET_DIR
    also supported).
  • Default socket path:
    "$OPENCLAW_TMUX_SOCKET_DIR/openclaw.sock"
    .
  • 使用
    OPENCLAW_TMUX_SOCKET_DIR
    (同时支持旧版
    CLAWDBOT_TMUX_SOCKET_DIR
    )。
  • 默认套接字路径:
    "$OPENCLAW_TMUX_SOCKET_DIR/openclaw.sock"

Targeting panes and naming

面板定位与命名

  • Target format:
    session:window.pane
    (defaults to
    :0.0
    ).
  • Keep names short; avoid spaces.
  • Inspect:
    tmux -S "$SOCKET" list-sessions
    ,
    tmux -S "$SOCKET" list-panes -a
    .
  • 目标格式:
    session:window.pane
    (默认值为
    :0.0
    )。
  • 名称请保持简短;避免使用空格。
  • 查看会话/面板:
    tmux -S "$SOCKET" list-sessions
    tmux -S "$SOCKET" list-panes -a

Finding sessions

查找会话

  • List sessions on your socket:
    {baseDir}/scripts/find-sessions.sh -S "$SOCKET"
    .
  • Scan all sockets:
    {baseDir}/scripts/find-sessions.sh --all
    (uses
    OPENCLAW_TMUX_SOCKET_DIR
    ).
  • 列出当前套接字下的会话:
    {baseDir}/scripts/find-sessions.sh -S "$SOCKET"
  • 扫描所有套接字:
    {baseDir}/scripts/find-sessions.sh --all
    (使用
    OPENCLAW_TMUX_SOCKET_DIR
    )。

Sending input safely

安全发送输入

  • Prefer literal sends:
    tmux -S "$SOCKET" send-keys -t target -l -- "$cmd"
    .
  • Control keys:
    tmux -S "$SOCKET" send-keys -t target C-c
    .
  • For interactive TUI apps like Claude Code/Codex, this guidance covers how to send commands. Do not append
    Enter
    in the same
    send-keys
    . These apps may treat a fast text+Enter sequence as paste/multi-line input and not submit; this is timing-dependent. Send text and
    Enter
    as separate commands with a small delay (tune per environment; increase if needed, or use
    sleep 1
    if sub-second sleeps aren't supported):
bash
tmux -S "$SOCKET" send-keys -t target -l -- "$cmd" && sleep 0.1 && tmux -S "$SOCKET" send-keys -t target Enter
  • 优先使用字面量发送:
    tmux -S "$SOCKET" send-keys -t target -l -- "$cmd"
  • 控制按键:
    tmux -S "$SOCKET" send-keys -t target C-c
  • 对于Claude Code/Codex等交互式TUI应用,本指南涵盖了如何发送命令的方法。 请勿在同一个
    send-keys
    命令中附加
    Enter
    。这些应用可能会将快速的文本+Enter序列视为粘贴/多行输入而不提交;这取决于时序。请将文本和
    Enter
    作为单独的命令发送,并加入短暂延迟(根据环境调整;如有需要可增加延迟,若不支持亚秒级睡眠则使用
    sleep 1
    ):
bash
tmux -S "$SOCKET" send-keys -t target -l -- "$cmd" && sleep 0.1 && tmux -S "$SOCKET" send-keys -t target Enter

Watching output

监控输出

  • Capture recent history:
    tmux -S "$SOCKET" capture-pane -p -J -t target -S -200
    .
  • Wait for prompts:
    {baseDir}/scripts/wait-for-text.sh -t session:0.0 -p 'pattern'
    .
  • Attaching is OK; detach with
    Ctrl+b d
    .
  • 捕获近期历史记录:
    tmux -S "$SOCKET" capture-pane -p -J -t target -S -200
  • 等待提示符:
    {baseDir}/scripts/wait-for-text.sh -t session:0.0 -p 'pattern'
  • 可以附加会话;使用
    Ctrl+b d
    分离。

Spawning processes

生成进程

  • For python REPLs, set
    PYTHON_BASIC_REPL=1
    (non-basic REPL breaks send-keys flows).
  • 对于Python REPL,请设置
    PYTHON_BASIC_REPL=1
    (非基础REPL会破坏send-keys流程)。

Windows / WSL

Windows / WSL

  • tmux is supported on macOS/Linux. On Windows, use WSL and install tmux inside WSL.
  • This skill is gated to
    darwin
    /
    linux
    and requires
    tmux
    on PATH.
  • tmux在macOS/Linux上受支持。在Windows上,请使用WSL并在WSL内部安装tmux。
  • 本技能仅对
    darwin
    /
    linux
    系统开放,且要求PATH中存在
    tmux

Orchestrating Coding Agents (Codex, Claude Code)

编排编码Agent(Codex,Claude Code)

tmux excels at running multiple coding agents in parallel:
bash
SOCKET="${TMPDIR:-/tmp}/codex-army.sock"
tmux擅长并行运行多个编码Agent:
bash
SOCKET="${TMPDIR:-/tmp}/codex-army.sock"

Create multiple sessions

Create multiple sessions

for i in 1 2 3 4 5; do tmux -S "$SOCKET" new-session -d -s "agent-$i" done
for i in 1 2 3 4 5; do tmux -S "$SOCKET" new-session -d -s "agent-$i" done

Launch agents in different workdirs

Launch agents in different workdirs

tmux -S "$SOCKET" send-keys -t agent-1 "cd /tmp/project1 && codex --yolo 'Fix bug X'" Enter tmux -S "$SOCKET" send-keys -t agent-2 "cd /tmp/project2 && codex --yolo 'Fix bug Y'" Enter
tmux -S "$SOCKET" send-keys -t agent-1 "cd /tmp/project1 && codex --yolo 'Fix bug X'" Enter tmux -S "$SOCKET" send-keys -t agent-2 "cd /tmp/project2 && codex --yolo 'Fix bug Y'" Enter

When sending prompts to Claude Code/Codex TUI, split text + Enter with a delay

When sending prompts to Claude Code/Codex TUI, split text + Enter with a delay

tmux -S "$SOCKET" send-keys -t agent-1 -l -- "Please make a small edit to README.md." && sleep 0.1 && tmux -S "$SOCKET" send-keys -t agent-1 Enter
tmux -S "$SOCKET" send-keys -t agent-1 -l -- "Please make a small edit to README.md." && sleep 0.1 && tmux -S "$SOCKET" send-keys -t agent-1 Enter

Poll for completion (check if prompt returned)

Poll for completion (check if prompt returned)

for sess in agent-1 agent-2; do if tmux -S "$SOCKET" capture-pane -p -t "$sess" -S -3 | grep -q "❯"; then echo "$sess: DONE" else echo "$sess: Running..." fi done
for sess in agent-1 agent-2; do if tmux -S "$SOCKET" capture-pane -p -t "$sess" -S -3 | grep -q "❯"; then echo "$sess: DONE" else echo "$sess: Running..." fi done

Get full output from completed session

Get full output from completed session

tmux -S "$SOCKET" capture-pane -p -t agent-1 -S -500

**Tips:**

- Use separate git worktrees for parallel fixes (no branch conflicts)
- `pnpm install` first before running codex in fresh clones
- Check for shell prompt (`❯` or `$`) to detect completion
- Codex needs `--yolo` or `--full-auto` for non-interactive fixes
tmux -S "$SOCKET" capture-pane -p -t agent-1 -S -500

**提示:**

- 为并行修复任务使用独立的git工作树(避免分支冲突)
- 在新克隆的仓库中运行codex前,先执行`pnpm install`
- 通过检测shell提示符(`❯`或`$`)来判断任务是否完成
- 对于非交互式修复,Codex需要添加`--yolo`或`--full-auto`参数

Cleanup

清理

  • Kill a session:
    tmux -S "$SOCKET" kill-session -t "$SESSION"
    .
  • Kill all sessions on a socket:
    tmux -S "$SOCKET" list-sessions -F '#{session_name}' | xargs -r -n1 tmux -S "$SOCKET" kill-session -t
    .
  • Remove everything on the private socket:
    tmux -S "$SOCKET" kill-server
    .
  • 终止单个会话:
    tmux -S "$SOCKET" kill-session -t "$SESSION"
  • 终止当前套接字下的所有会话:
    tmux -S "$SOCKET" list-sessions -F '#{session_name}' | xargs -r -n1 tmux -S "$SOCKET" kill-session -t
  • 删除私有套接字下的所有内容:
    tmux -S "$SOCKET" kill-server

Helper: wait-for-text.sh

辅助工具:wait-for-text.sh

{baseDir}/scripts/wait-for-text.sh
polls a pane for a regex (or fixed string) with a timeout.
bash
{baseDir}/scripts/wait-for-text.sh -t session:0.0 -p 'pattern' [-F] [-T 20] [-i 0.5] [-l 2000]
  • -t
    /
    --target
    pane target (required)
  • -p
    /
    --pattern
    regex to match (required); add
    -F
    for fixed string
  • -T
    timeout seconds (integer, default 15)
  • -i
    poll interval seconds (default 0.5)
  • -l
    history lines to search (integer, default 1000)
{baseDir}/scripts/wait-for-text.sh
会轮询面板内容,检查是否匹配正则表达式(或固定字符串),并支持超时设置。
bash
{baseDir}/scripts/wait-for-text.sh -t session:0.0 -p 'pattern' [-F] [-T 20] [-i 0.5] [-l 2000]
  • -t
    /
    --target
    面板目标(必填)
  • -p
    /
    --pattern
    要匹配的正则表达式(必填);添加
    -F
    表示匹配固定字符串
  • -T
    超时秒数(整数,默认15)
  • -i
    轮询间隔秒数(默认0.5)
  • -l
    要搜索的历史行数(整数,默认1000)