tmux
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
Chinesetmux 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 -200After 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 -200bash
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 -200Socket convention
套接字约定
- Use (legacy
OPENCLAW_TMUX_SOCKET_DIRalso supported).CLAWDBOT_TMUX_SOCKET_DIR - 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: (defaults to
session:window.pane).: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: (uses
{baseDir}/scripts/find-sessions.sh --all).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 in the same
Enter. These apps may treat a fast text+Enter sequence as paste/multi-line input and not submit; this is timing-dependent. Send text andsend-keysas separate commands with a small delay (tune per environment; increase if needed, or useEnterif sub-second sleeps aren't supported):sleep 1
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 EnterWatching 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 (non-basic REPL breaks send-keys flows).
PYTHON_BASIC_REPL=1
- 对于Python REPL,请设置(非基础REPL会破坏send-keys流程)。
PYTHON_BASIC_REPL=1
Windows / WSL
Windows / WSL
- tmux is supported on macOS/Linux. On Windows, use WSL and install tmux inside WSL.
- This skill is gated to /
darwinand requireslinuxon PATH.tmux
- tmux在macOS/Linux上受支持。在Windows上,请使用WSL并在WSL内部安装tmux。
- 本技能仅对/
darwin系统开放,且要求PATH中存在linux。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 fixestmux -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.shbash
{baseDir}/scripts/wait-for-text.sh -t session:0.0 -p 'pattern' [-F] [-T 20] [-i 0.5] [-l 2000]- /
-tpane target (required)--target - /
-pregex to match (required); add--patternfor fixed string-F - timeout seconds (integer, default 15)
-T - poll interval seconds (default 0.5)
-i - history lines to search (integer, default 1000)
-l
{baseDir}/scripts/wait-for-text.shbash
{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 - 超时秒数(整数,默认15)
-T - 轮询间隔秒数(默认0.5)
-i - 要搜索的历史行数(整数,默认1000)
-l