SuperAPI AI Directory

terminal-session

Agents & models

View repository

Updated 10-15 20:28

About this skill

Terminal Session Control (tmux)

This skill works entirely through the existing exec tool to invoke the system-level tmux CLI, requiring no new tools or dependencies.


When to Use

✅ Scenarios where this skill should be used

  • Monitor the running status of Claude Code / Codex in tmux
  • Send input to interactive terminal programs (answer prompts, select options)
  • Read output from long-running processes in tmux
  • Operate the same background process across multiple conversation turns
  • Check the progress of background tasks in existing tmux sessions

❌ Scenarios where this skill should not be used

  • One-off shell commands(ls, grep, python script.py, etc.) → use exec
  • Starting a new background process(no interaction needed) → use exec to execute the command (append &)
  • Non-interactive scripts → use exec
  • Process is not in tmux → cannot be operated
  • Creating a new tmux session → use exec to execute tmux new-session(this skill focuses on operating existing sessions)
  • Native Windows (no WSL) → tmux is unavailable; inform the user that WSL2 is required

Common Session Naming Conventions

Session name Purpose
shared Main interactive session
worker-2 ~ worker-8 Parallel work session
ssh_prod Production SSH
claude_task Claude Code task session

Common Commands

List sessions

tmux list-sessions
tmux ls

Read output

# 读取当前屏幕最后 20 行
tmux capture-pane -t shared -p | tail -20

# 读取完整滚动历史
tmux capture-pane -t shared -p -S -

# 读取指定窗口/面板(格式: 会话:窗口.面板)
tmux capture-pane -t shared:0.0 -p

Send input

# 发送文本(不回车)
tmux send-keys -t shared "hello"

# 发送文本并回车
tmux send-keys -t shared "ls -la" Enter

# 特殊按键
tmux send-keys -t shared Enter        # 回车
tmux send-keys -t shared Escape       # Esc
tmux send-keys -t shared C-c          # Ctrl+C(中断)
tmux send-keys -t shared C-d          # Ctrl+D(EOF / 退出 REPL)
tmux send-keys -t shared C-z          # Ctrl+Z(挂起)

Window / pane navigation

# 切换窗口
tmux select-window -t shared:0

# 切换面板
tmux select-pane -t shared:0.1

# 列出会话所有窗口
tmux list-windows -t shared

Session management

# 创建新会话(后台运行)
tmux new-session -d -s newsession

# 创建并直接启动程序
tmux new-session -d -s claude_task 'claude-code /workspace/project'

# 关闭会话
tmux kill-session -t sessionname

# 重命名会话
tmux rename-session -t old new

# 检查会话是否存在
tmux has-session -t my_session 2>/dev/null && echo "存在" || echo "不存在"

Safely Sending Input (Important)

For interactive TUI programs (Claude Code, Codex, etc.),text and Enter must be sent separately, to avoid anomalies caused by multiline pasting:

# ✅ 正确:先发文本,短暂等待,再发 Enter
tmux send-keys -t shared -l -- "Please apply the patch in src/foo.ts"
sleep 0.1
tmux send-keys -t shared Enter

# ❌ 错误:一次性发送可能引发多行粘贴问题
tmux send-keys -t shared "Please apply the patch in src/foo.ts" Enter

Claude Code Session Operation Patterns

Check whether the session is waiting for input

# 查找常见提示符(❯、Yes/No、proceed、permission 等)
tmux capture-pane -t worker-3 -p | tail -10 | grep -E "❯|Yes.*No|proceed|permission|approve"

Confirm the Claude Code prompt

# 发送 y 确认
tmux send-keys -t worker-3 'y' Enter

# 选择编号选项
tmux send-keys -t worker-3 '2' Enter

Send a task to the session

tmux send-keys -t worker-4 -l -- "Fix the authentication bug in auth.js"
sleep 0.1
tmux send-keys -t worker-4 Enter

Check the status of all work sessions in batch

for s in shared worker-2 worker-3 worker-4 worker-5 worker-6 worker-7 worker-8; do
  echo "=== $s ==="
  tmux capture-pane -t $s -p 2>/dev/null | tail -5
done

Complete Workflow Example

Start Claude Code and interact

# 1. 创建会话并启动
tmux new-session -d -s coder 'claude-code /workspace'

# 2. 等待启动(约 3 秒),读取初始状态
sleep 3 && tmux capture-pane -t coder -p | tail -20

# 3. 安全发送任务指令
tmux send-keys -t coder -l -- "Refactor the auth module to use JWT tokens"
sleep 0.1
tmux send-keys -t coder Enter

# 4. 等待执行,周期读取输出
sleep 10 && tmux capture-pane -t coder -p -S -100

# 5. 如有确认提示,回答 y
tmux capture-pane -t coder -p | tail -5 | grep -q "proceed" && \
  tmux send-keys -t coder 'y' Enter

# 6. 完成后关闭会话
tmux kill-session -t coder

SSH Remote Operations

# 建立连接(禁用首次连接确认)
tmux new-session -d -s ssh_prod 'ssh -o StrictHostKeyChecking=no user@10.0.0.1'

# 等待登录完成
sleep 2 && tmux capture-pane -t ssh_prod -p | tail -5

# 执行远程命令
tmux send-keys -t ssh_prod 'df -h && free -m' Enter
sleep 2 && tmux capture-pane -t ssh_prod -p | tail -20

Notes

  • capture-pane must include -p to output to stdout (required in scripts)
  • -S - reads the full scrollback history;-S -200 reads the most recent 200 lines
  • Target format:会话:窗口.面板(e.g. shared:0.0)
  • tmux sessions survive after SSH disconnection, with no need to reconnect
  • Be sure to kill-sessionafter tasks are completed, to prevent zombie processes from piling up
  • exec The security policies of the tool remain in effect; dangerous commands will still be intercepted
https://skills.sh/steipete/clawdis/tmux