CLI 目录 横向对比 FCRS-1.0 标准 /llms.txt
← 返回 CLI 目录

tmux

$ tmux 社区开源 中风险
tmux · 文件检索与编辑 · ISC · macos / linux

tmux 基于客户端-服务端套接字架构管理持久化的终端会话、窗口与窗格。与纯交互式 TUI 不同,tmux 暴露了完善的无头控制命令(new-session -d、list-sessions -F、capture-pane -p、send-keys),非常适合托管与巡检常驻开发服务。

FCRS-1.0 综合评分
86 /100
良好 (Good)
中置信度 (源码/文档)
零摩擦安装命令
brew install tmux
CLI vs MCP 选型建议 优先选 CLI

后台会话管理与 tmux capture-pane -p 日志抓取直接与本地套接字通信即可,比 MCP 包装更迅捷稳定。

Agent 友好度体检单

— 原生 JSON 输出
✓ 字段裁剪
✓ 无头非交互
— 支持 Dry-Run
— 只读模式开关
— 支持 NO_COLOR
— 自省/Schema 发现
— 官方 SKILL.md

当前为静态评估(本机尚未安装或尚未运行探针)。可在本地运行 npm run data:probe 并提交 data/probes/ 升级为实测证据。

FCRS-1.0 六维评分拆解

Agent 友好度 19 / 25

具备高度可脚本化的客户端-服务端命令(-d 后台模式、-F 格式字段、capture-pane -p、send-keys),仅缺原生 --json 参数。

  • Detached -d mode and -F field formatting on list-* commands
  • capture-pane -p prints pane buffers cleanly to stdout
安全与权限边界 19 / 25

list-sessions 与 capture-pane 只读安全,但 send-keys 可向交互终端注入任意命令,且 kill-server 会终止全部会话。

  • send-keys and kill-session/kill-server can disrupt active user sessions
安装与运行摩擦 14 / 15

macOS、Linux 与 BSD 上近乎无处不在(Homebrew、apt、dnf),Windows 需借助 WSL 或 Cygwin。

  • Pre-installed or single-command install on virtually all Unix hosts
能力覆盖与边际价值 15 / 15

跨 Agent 轮次托管常驻进程、REPL 与交互式工具的行业标准工具。

  • Persistent detached sessions survive SSH drops and agent turns
维护与来源背书 10 / 10

经典 ISC 开源项目(tmux/tmux),长期保持高质量维护。

  • Decades-long stability and continuous upstream releases
文档与可验证性 9 / 10

详尽的 tmux(1) 手册页与 GitHub Wiki 完整记录了所有目标语法、格式变量与命令。

  • Complete manual page and wiki reference

安全边界、鉴权与放权指南

鉴权方式
无需鉴权
凭证存储位置

无需凭据;使用 /tmp/tmux-* 本地 Unix 域套接字,配置文件位于 ~/.tmux.conf。

潜在副作用
只读查询 本地写入 破坏性删除
费用与配额提示

100% 免费、离线、开源(ISC)。

可复制到 CLAUDE.md / AGENTS.md 的安全护栏
# tmux Agent Rules
- ALWAYS pass `-d` to `tmux new-session` so it never tries to attach interactively inside an agent shell.
- Use `tmux capture-pane -t <target> -p` to read logs and verify exact target session/pane names before calling `send-keys` or `kill-session`.

Agent 高频安全命令配方

只读查询(安全推荐)

使用自定义格式字段列出活跃 tmux 会话
tmux list-sessions -F "#{session_name}: #{session_windows} windows (attached=#{session_attached})"

借助 -F 格式化变量只读查询当前会话状态,无需挂载 TTY。

抓取后台窗格的近期输出
tmux capture-pane -t dev-server:0.0 -p -S -100

通过 -p 将 dev-server:0.0 窗格最后 100 行输出直接打印到 stdout。

受控写入与预演

安全启动分离的后台会话
tmux new-session -d -s dev-server "npm run dev"

传入 -d 启动常驻后台会话,不会接管调用方当前终端。

核心优势

  • + 支持分离启动(-d)、格式筛选(-F)及缓冲区抓屏(capture-pane -p)。
  • + 非常适合在多轮 Agent 任务间持久运行和观察开发服务器或交互式 REPL。

注意事项与踩坑点

  • ! 不加 -d 调用 new-session 或 attach 会在无 TTY 环境下失败或阻塞。
  • ! 无原生 --json 输出,除 WSL 外不支持原生 Windows。

已验证兼容的 Agent 宿主

Claude Code Codex CLI Gemini CLI