tmux Skill (Clawdbot)
Use tmux only when you need an interactive TTY. Prefer bash background mode for long-running, non-interactive tasks.
Quickstart (isolated socket, bash tool)
CODEBLOCK0
After starting a session, always print monitor commands:
CODEBLOCK1
Socket convention
- - Use
CLAWDBOT_TMUX_SOCKET_DIR (default ${TMPDIR:-/tmp}/clawdbot-tmux-sockets). - Default socket path:
"$CLAWDBOT_TMUX_SOCKET_DIR/clawdbot.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.
Finding sessions
- - List sessions on your socket:
{baseDir}/scripts/find-sessions.sh -S "$SOCKET". - Scan all sockets:
{baseDir}/scripts/find-sessions.sh --all (uses CLAWDBOT_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.
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.
Spawning processes
- - For python REPLs, set
PYTHON_BASIC_REPL=1 (non-basic REPL breaks send-keys flows).
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.
Orchestrating Coding Agents (Codex, Claude Code)
tmux excels at running multiple coding agents in parallel:
CODEBLOCK2
Tips:
- - Use separate git worktrees for parallel fixes (no branch conflicts)
- INLINECODE19 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
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.
Helper: wait-for-text.sh
INLINECODE27 polls a pane for a regex (or fixed string) with a timeout.
CODEBLOCK3
- -
-t/--target pane target (required) - INLINECODE30 /
--pattern regex to match (required); add -F for fixed string - INLINECODE33 timeout seconds (integer, default 15)
- INLINECODE34 poll interval seconds (default 0.5)
- INLINECODE35 history lines to search (integer, default 1000)
tmux 技能 (Clawdbot)
仅在需要交互式 TTY 时使用 tmux。对于长时间运行的非交互式任务,优先使用 bash 后台模式。
快速开始(隔离套接字,bash 工具)
bash
SOCKETDIR=${CLAWDBOTTMUXSOCKETDIR:-${TMPDIR:-/tmp}/clawdbot-tmux-sockets}
mkdir -p $SOCKET_DIR
SOCKET=$SOCKET_DIR/clawdbot.sock
SESSION=clawdbot-python
tmux -S $SOCKET new -d -s $SESSION -n shell
tmux -S $SOCKET send-keys -t $SESSION:0.0 -- PYTHONBASICREPL=1 python3 -q Enter
tmux -S $SOCKET capture-pane -p -J -t $SESSION:0.0 -S -200
启动会话后,始终打印监控命令:
监控方式:
tmux -S $SOCKET attach -t $SESSION
tmux -S $SOCKET capture-pane -p -J -t $SESSION:0.0 -S -200
套接字约定
- - 使用 CLAWDBOTTMUXSOCKETDIR(默认为 ${TMPDIR:-/tmp}/clawdbot-tmux-sockets)。
- 默认套接字路径:$CLAWDBOTTMUXSOCKETDIR/clawdbot.sock。
定位窗格和命名
- - 目标格式:session:window.pane(默认为 :0.0)。
- 保持名称简短;避免空格。
- 检查:tmux -S $SOCKET list-sessions,tmux -S $SOCKET list-panes -a。
查找会话
- - 列出套接字上的会话:{baseDir}/scripts/find-sessions.sh -S $SOCKET。
- 扫描所有套接字:{baseDir}/scripts/find-sessions.sh --all(使用 CLAWDBOTTMUXSOCKET_DIR)。
安全发送输入
- - 优先使用字面发送:tmux -S $SOCKET send-keys -t target -l -- $cmd。
- 控制键:tmux -S $SOCKET send-keys -t target C-c。
查看输出
- - 捕获最近历史: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 分离。
生成进程
- - 对于 Python REPL,设置 PYTHONBASICREPL=1(非基础 REPL 会破坏 send-keys 流程)。
Windows / WSL
- - tmux 在 macOS/Linux 上受支持。在 Windows 上,使用 WSL 并在 WSL 内安装 tmux。
- 此技能限定于 darwin/linux 平台,且需要 PATH 中存在 tmux。
编排编码代理(Codex, Claude Code)
tmux 擅长并行运行多个编码代理:
bash
SOCKET=${TMPDIR:-/tmp}/codex-army.sock
创建多个会话
for i in 1 2 3 4 5; do
tmux -S $SOCKET new-session -d -s agent-$i
done
在不同工作目录启动代理
tmux -S $SOCKET send-keys -t agent-1 cd /tmp/project1 && codex --yolo 修复错误 X Enter
tmux -S $SOCKET send-keys -t agent-2 cd /tmp/project2 && codex --yolo 修复错误 Y Enter
轮询完成状态(检查提示符是否返回)
for sess in agent-1 agent-2; do
if tmux -S $SOCKET capture-pane -p -t $sess -S -3 | grep -q ❯; then
echo $sess: 完成
else
echo $sess: 运行中...
fi
done
获取已完成会话的完整输出
tmux -S $SOCKET capture-pane -p -t agent-1 -S -500
提示:
- - 对并行修复使用单独的 git worktree(避免分支冲突)
- 在全新克隆中运行 codex 前先执行 pnpm install
- 检查 shell 提示符(❯ 或 $)以检测完成状态
- Codex 需要 --yolo 或 --full-auto 进行非交互式修复
清理
- - 终止会话: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。
辅助工具:wait-for-text.sh
{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)