控制 tmux 窗格并在 AI 代理之间通信。当用户提到 tmux 窗格、跨窗格通信、向其他代理发送消息、读取其他窗格、管理 tmux 会话或与 tmux 中运行的进程交互时,请使用此技能。包含用于代理间消息传递的 tmux-bridge CLI 和用于直接会话控制的原始 tmux 命令。
smux
Tmux 窗格控制与跨窗格代理通信。所有跨窗格交互请使用 tmux-bridge(高级 CLI)。仅在需要底层控制时回退到原始 tmux 命令。
tmux-bridge — 跨窗格通信
一个 CLI,允许任何 AI 代理与任何其他 tmux 窗格交互。通过纯 bash 工作。每个命令都是原子性的:type 输入文本(不按 Enter),keys 发送特殊键,read 捕获窗格内容。
不要等待或轮询
其他窗格中的代理会通过 tmux-bridge 回复您。它们的回复会直接出现在您的窗格中,作为 [tmux-bridge from:...] 消息。不要 sleep、轮询、读取目标窗格以获取响应,或循环。输入您的消息,按 Enter,然后继续。
唯一需要读取目标窗格的情况是:
- 在与之交互之前(由读取守卫强制执行)
- 在输入后验证文本是否已输入,然后再按 Enter
- 与非代理窗格(纯 shell、正在运行的进程)交互时
读取守卫
CLI 强制执行先读后操作。除非您已先读取窗格,否则不能对其执行 type 或 keys。
tmux-bridge read <target>将窗格标记为“已读”tmux-bridge type/keys <target>检查该标记 — 如果未读取则报错- 成功执行
type/keys后,标记被清除 — 下次交互前必须再次读取
$ tmux-bridge type codex "hello"
error: must read the pane before interacting. Run: tmux-bridge read codex
命令参考
| 命令 | 描述 | 示例 |
|---|---|---|
tmux-bridge list |
显示所有窗格,包含目标、PID、命令、大小、标签 | tmux-bridge list |
tmux-bridge type <target> <text> |
输入文本,不按 Enter | tmux-bridge type codex "hello" |
tmux-bridge message <target> <text> |
输入文本,自动添加发送者信息和回复目标 | tmux-bridge message codex "review src/auth.ts" |
tmux-bridge read <target> [lines] |
读取最后 N 行(默认 50) | tmux-bridge read codex 100 |
tmux-bridge keys <target> <key>... |
发送特殊键 | tmux-bridge keys codex Enter |
tmux-bridge name <target> <label> |
为窗格设置标签(在 tmux 边框可见) | tmux-bridge name %3 codex |
tmux-bridge resolve <label> |
打印标签对应的窗格目标 | tmux-bridge resolve codex |
tmux-bridge id |
打印当前窗格的 ID | tmux-bridge id |
目标解析
目标可以是:
- tmux 原生格式:
session:window.pane(例如shared:0.1)、窗格 ID(%3)或窗口索引(0) - 标签:通过
tmux-bridge name设置的任意字符串 — 自动解析
读-操作-读 循环
每次交互遵循 读取 → 操作 → 读取。CLI 强制执行此流程。
向代理发送消息:
tmux-bridge read codex 20 # 1. 读取 — 满足读取守卫
tmux-bridge message codex 'Please review src/auth.ts'
# 2. 消息 — 自动添加发送者信息,不按 Enter
tmux-bridge read codex 20 # 3. 读取 — 验证文本已输入
tmux-bridge keys codex Enter # 4. 按键 — 提交
# 停止。不要读取 codex 以获取回复。代理会回复到您的窗格。
批准提示(非代理窗格):
tmux-bridge read worker 10 # 1. 读取 — 查看提示
tmux-bridge type worker "y" # 2. 输入
tmux-bridge read worker 10 # 3. 读取 — 验证
tmux-bridge keys worker Enter # 4. 按键 — 提交
tmux-bridge read worker 20 # 5. 读取 — 查看结果
消息约定
message 命令会自动添加发送者信息和位置:
[tmux-bridge from:claude pane:%4 at:3:0.0] Please review src/auth.ts
接收者会看到:谁发送的(from)、回复的确切窗格(pane)以及会话/窗口位置(at)。当您看到此头部时,请使用 tmux-bridge 回复到头部中的窗格 ID。
代理间工作流
# 1. 为自己设置标签
tmux-bridge name "$(tmux-bridge id)" claude
# 2. 发现其他窗格
tmux-bridge list
# 3. 发送消息(读-操作-读)
tmux-bridge read codex 20
tmux-bridge message codex 'Please review the changes in src/auth.ts'
tmux-bridge read codex 20
tmux-bridge keys codex Enter
对话示例
代理 A (claude) 发送:
tmux-bridge read codex 20
tmux-bridge message codex 'What is the test coverage for src/auth.ts?'
tmux-bridge read codex 20
tmux-bridge keys codex Enter
代理 B (codex) 在其提示中看到:
[tmux-bridge from:claude pane:%4 at:3:0.0] What is the test coverage for src/auth.ts?
代理 B 使用头部中的窗格 ID 回复:
tmux-bridge read %4 20
tmux-bridge message %4 '87% line coverage. Missing the OAuth refresh token path (lines 142-168).'
tmux-bridge read %4 20
tmux-bridge keys %4 Enter
原始 tmux 命令
当您需要 tmux-bridge 之外的直接 tmux 控制时使用这些命令 — 会话管理、窗口导航、创建窗格或底层脚本。
捕获输出
tmux capture-pane -t shared -p | tail -20 # 最后 20 行
tmux capture-pane -t shared -p -S - # 整个回滚缓冲区
tmux capture-pane -t shared:0.0 -p # 特定窗格
发送按键
tmux send-keys -t shared -l -- "text here" # 输入文本(字面模式)
tmux send-keys -t shared Enter # 按 Enter
tmux send-keys -t shared Escape # 按 Escape
tmux send-keys -t shared C-c # Ctrl+C
tmux send-keys -t shared C-d # Ctrl+D (EOF)
对于交互式 TUI,将文本和 Enter 分开发送:
tmux send-keys -t shared -l -- "Please apply the patch"
sleep 0.1
tmux send-keys -t shared Enter
窗格和窗口
# 创建窗格(优先于新窗口)
tmux split-window -h -t SESSION # 水平分割
tmux split-window -v -t SESSION # 垂直分割
tmux select-layout -t SESSION tiled # 重新平衡
# 导航
tmux select-window -t shared:0
tmux select-pane -t shared:0.1
tmux list-windows -t shared
会话管理
tmux list-sessions
tmux new-session -d -s newsession
tmux kill-session -t sessionname
tmux rename-session -t old new
Claude Code 模式
# 检查会话是否需要输入
tmux capture-pane -t worker-3 -p | tail -10 | grep -E "❯|Yes.*No|proceed|permission"
# 批准提示
tmux send-keys -t worker-3 'y' Enter
# 检查所有会话
for s in shared worker-2 worker-3 worker-4; do
echo "=== $s ==="
tmux capture-pane -t $s -p 2>/dev/null | tail -5
done
提示
- 读取守卫强制执行 — 每次
type/keys前必须读取 - 每次操作清除读取标记 — 在
type后,再次读取才能keys - 永远不要等待或轮询 — 代理窗格通过 tmux-bridge 回复到您的窗格
- 尽早为窗格设置标签 — 比使用
%NID 更方便 type使用字面模式 — 特殊字符按原样输入read默认读取 50 行 — 传递更大的数字以获取更多上下文- 非代理窗格是例外 — 您确实需要读取它们以查看输出
- 使用
capture-pane -p打印到标准输出(对脚本至关重要) - 目标格式:
session:window.pane(例如shared:0.0)






