tmux Skill
Use tmux only when you need an interactive TTY. Prefer exec background mode for long-running, non-interactive tasks.
Default Server — No Custom Sockets
Always use the default tmux server. Do NOT use -S custom sockets. The user needs to tmux attach easily without knowing obscure socket paths.
Session Naming
Convention: oc-${project}-${feature} (e.g. oc-knowhere-date-range-picker, oc-deck-auth-flow)
- -
oc- prefix = OpenClaw-managed, avoids collision with user sessions - Easy to find: INLINECODE6
Quickstart
CODEBLOCK0
After starting a session, tell the user:
CODEBLOCK1
Targeting panes and naming
- - Target format:
session:window.pane (defaults to :0.0). - Keep names short; avoid spaces.
- Inspect:
tmux list-sessions, tmux list-panes -a.
Sending input safely
- - Prefer literal sends:
tmux send-keys -t target -l -- "$cmd". - Control keys:
tmux send-keys -t target C-c. - For interactive TUI apps like Claude Code/Codex, 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. Send text and
Enter as separate commands with a small delay:
CODEBLOCK2
Watching output
- - Capture recent history:
tmux capture-pane -p -J -t target -S -200. - 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).
Orchestrating Coding Agents (Codex, Claude Code)
tmux excels at running multiple coding agents in parallel:
CODEBLOCK3
Tips:
- - Use separate git worktrees for parallel fixes (no branch conflicts)
- INLINECODE19 /
pnpm install first before running agents 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 kill-session -t "$SESSION". - Kill all OpenClaw sessions:
tmux ls -F '#{session_name}' | grep '^oc-' | xargs -n1 tmux kill-session -t.
tmux 技能
仅在需要交互式TTY时使用tmux。对于长时间运行的非交互式任务,优先使用exec后台模式。
默认服务器 — 无自定义套接字
始终使用默认的tmux服务器。 不要使用-S自定义套接字。用户需要能够轻松地tmux attach,而无需知道晦涩的套接字路径。
会话命名
约定: oc-${project}-${feature}(例如 oc-knowhere-date-range-picker、oc-deck-auth-flow)
- - oc-前缀 = OpenClaw管理,避免与用户会话冲突
- 易于查找:tmux ls | grep oc-
快速开始
bash
SESSION=oc-myproject-feature
tmux new-session -d -s $SESSION -c ~/projects/myproject
tmux send-keys -t $SESSION claude --dangerously-skip-permissions Enter
tmux capture-pane -p -J -t $SESSION -S -200
启动会话后,告知用户:
要监控:tmux attach -t $SESSION
定位窗格和命名
- - 定位格式:session:window.pane(默认为:0.0)
- 保持名称简短;避免空格
- 检查:tmux list-sessions、tmux list-panes -a
安全发送输入
- - 优先使用字面发送:tmux send-keys -t target -l -- $cmd
- 控制键:tmux send-keys -t target C-c
- 对于Claude Code/Codex等交互式TUI应用,不要在同一个send-keys中附加Enter。这些应用可能会将快速的文本+Enter序列视为粘贴/多行输入而不提交。将文本和Enter作为单独的命令发送,并添加小延迟:
bash
tmux send-keys -t target -l -- $cmd && sleep 0.1 && tmux send-keys -t target Enter
查看输出
- - 捕获最近历史:tmux capture-pane -p -J -t target -S -200
- 可以附加;使用Ctrl+b d分离
生成进程
- - 对于Python REPL,设置PYTHONBASICREPL=1(非基础REPL会破坏send-keys流程)
编排编码代理(Codex、Claude Code)
tmux擅长并行运行多个编码代理:
bash
在不同工作树中创建会话
tmux new-session -d -s oc-project-fix1 -c ~/projects/project-fix1
tmux new-session -d -s oc-project-fix2 -c ~/projects/project-fix2
启动代理
tmux send-keys -t oc-project-fix1 claude --dangerously-skip-permissions Enter
tmux send-keys -t oc-project-fix2 codex --full-auto Enter
发送提示(文本 + 带延迟的Enter)
tmux send-keys -t oc-project-fix1 -l -- 修复日期选择器样式。 && sleep 0.1 && tmux send-keys -t oc-project-fix1 Enter
轮询完成状态(检查shell提示符是否返回)
for sess in oc-project-fix1 oc-project-fix2; do
if tmux capture-pane -p -t $sess -S -3 | grep -q ❯; then
echo $sess: 完成
else
echo $sess: 运行中...
fi
done
获取完整输出
tmux capture-pane -p -t oc-project-fix1 -S -500
提示:
- - 使用单独的git工作树进行并行修复(无分支冲突)
- 在全新克隆中运行代理前,先执行bun install / pnpm install
- 检查shell提示符(❯或$)以检测完成状态
- Codex需要--yolo或--full-auto进行非交互式修复
清理
- - 终止会话:tmux kill-session -t $SESSION
- 终止所有OpenClaw会话:tmux ls -F #{session_name} | grep ^oc- | xargs -n1 tmux kill-session -t