跳到正文
Skillpedia
部署与云(DevOps)394k · #86

tmux

它能做什么

它指导 AI 智能体读取 tmux 会话的输出,并向其发送输入,尤其适用于已在运行的交互式工具。它适合把长时间运行的终端任务放在 tmux 中的开发者。

适用场景

  • ✓你想查看某个正在运行的终端工具正在输出什么的时候。
  • ✓tmux 会话中的某个工具正在等待输入、需要回复的时候。
  • ✓你需要启动、重命名或关闭某个 tmux 会话的时候。

技能链接

https://github.com/openclaw/openclaw/blob/main/skills/tmux/SKILL.md

复制后粘贴给你的 AI(Claude、ChatGPT 或 Cursor),让它按照说明操作。

使用方法

最简单的方法:复制下面的消息,粘贴给你的 AI。它会读取这个技能并按说明操作。

可直接粘贴的消息

请用这个技能帮我:https://github.com/openclaw/openclaw/blob/main/skills/tmux/SKILL.md 阅读该链接中的 SKILL.md 文件,并在我的任务中按照它的说明来做。
想让你的 AI 自己找到这样的技能吗?安装免费的 Skillpedia MCP:只需一行,每次任务前它都会在 15,000+ 个技能中搜索。1 分钟完成安装 →

可以这样问 AI

“请查看名为 worker 的 tmux 会话,告诉我它现在正在输出什么。”

每周 5 个新技能,1 分钟读完。

工作原理

技能列出会话和窗格,读取最近的输出,并在你要求时发送文字或按键。在批准或选择任何内容之前,它会确认自己理解了提示。

技术内容(原始 SKILL.md)

作者在 GitHub 上的英文原文。

tmux

Use for existing interactive tmux sessions. For one-shot commands, use normal shell. For new non-interactive background jobs, use background execution.

Basics

tmux ls
tmux list-windows -t shared
tmux list-panes -t shared:0
tmux capture-pane -t shared:0.0 -p
tmux capture-pane -t shared:0.0 -p -S -

Target format: session:window.pane, e.g. shared:0.0.

Send input

Literal text, then Enter:

tmux send-keys -t shared:0.0 -l -- "Please continue"
tmux send-keys -t shared:0.0 Enter

Special keys:

tmux send-keys -t shared:0.0 C-c
tmux send-keys -t shared:0.0 C-d
tmux send-keys -t shared:0.0 Escape

Use -l -- for arbitrary text. Split text and Enter to avoid paste/newline surprises.

Sessions

tmux new-session -d -s worker
tmux rename-session -t old new
tmux kill-session -t worker

Prompt checks

tmux capture-pane -t worker-3 -p | tail -20
tmux capture-pane -t worker-3 -p | rg "proceed|permission|Yes|No|❯"

Approve/select only when the prompt is understood:

tmux send-keys -t worker-3 -l -- "y"
tmux send-keys -t worker-3 Enter

Helpers

  • scripts/find-sessions.sh: discover sessions.
  • scripts/wait-for-text.sh: wait until captured pane contents contain text.

wait-for-text.sh searches echoed input and scrollback as well as process output. For command completion, use a unique marker whose full text is split across arguments in the command sent to tmux:

nonce="$(od -An -N8 -tx1 /dev/urandom | tr -d ' \n')"
marker="OPENCLAW_DONE_${nonce}"
tmux send-keys -t shared:0.0 -l -- "sleep 4; printf '%s%s\n' 'OPENCLAW_DONE_' '$nonce'"
tmux send-keys -t shared:0.0 Enter
scripts/wait-for-text.sh -t shared:0.0 -p "$marker" -F -T 30

The echoed command never contains the complete marker, and the nonce prevents an older completion line from matching.

Notes

  • capture-pane -p prints to stdout for scripts.
  • -S - captures full scrollback.
  • tmux sessions persist across SSH disconnects.
常见问题

它会不经询问就发送命令吗?

只有在提示被理解、操作明确时,它才会批准提示。

tmux 是用来执行一次性命令的吗?

不是。执行一次性命令时,普通的 shell 更简单;tmux 适用于已有的交互式会话。

它能等待任务完成吗?

可以。辅助脚本可以等待窗格显示某些文字,不过使用唯一的标记效果最好。

详情

作者的原始描述

Control tmux sessions/panes for interactive CLIs: list, capture output, send keys, paste text, monitor prompts.

repo: openclaw/openclaw

热度

GitHub 星标
394k
排名
#86
许可证
MIT
更新时间
2026/11/2

这个技能有用吗?

0

登录 后即可投票。

评论

  • …

同一仓库的更多技能

相似技能