安装方式
手动下载安装
下载 ZIP 后解压到技能目录即可安装。若在桌面客户端 WebView中直接下载出现异常,本站会改为提示页 + 原始链接,请按页内说明操作。
下载 ZIP (oss-superpowers-lab-using-tmux-for-interactive-commands-v1.0.0.zip)触发指令
/using-tmux-for-inter
跨平台安装指引
该技能声明兼容以下 1 个平台,将 ZIP 解压到对应目录即可被识别。
unzip oss-superpowers-lab-using-tmux-for-interactive-commands-v1.0.0.zip -d ~/.claude/skills/
目录不存在时请先
mkdir -p 创建;启用 Skill 后请重启对应 Agent 让配置生效。
使用指南
用 tmux 跑交互式命令
vim、交互式 git rebase -i、Python REPL 等需要 真 TTY 的程序,不能 用普通非交互 bash 一条命令糊弄过去。用 tmux 分离会话 + send-keys / capture-pane 可编程控制。
何时用 tmux
适合: vim/nano、交互 git、全屏 TUI、需要 readline/控制序列的程序。
不适合: 纯非交互命令、可用 stdin 重定向搞定的一发命令。
速查
| 任务 | 命令 |
|------|------|
| 新建后台会话 | tmux new-session -d -s <名> <命令> |
| 发键 | tmux send-keys -t <名> '文本' Enter |
| 抓屏 | tmux capture-pane -t <名> -p |
| 结束 | tmux kill-session -t <名> |
| 列表 | tmux list-sessions |
核心模式
tmux new-session -d -s edit_session vim file.txt
tmux send-keys -t edit_session 'i' 'Hello' Escape ':wq' Enter
tmux capture-pane -t edit_session -p
tmux kill-session -t edit_session
流程
new-session -d起会话- 视情况 sleep 0.1–0.5s 等程序起来
send-keys(Enter、Escape、C-c、方向键等用 tmux 键名,不要用\n代替 Enter)capture-pane -p看状态- 重复 3–4
kill-session清理
工作目录
tmux new-session -d -s git_session -c /path/to/repo git rebase -i HEAD~3
常见错误
- 一起动就 capture → 空白屏 → 先 sleep
- 忘了单独发
Enter→ 命令未执行 - 用
\n而非Enter - 不
kill-session→ 会话泄漏
价值
可脚本化 vim、交互 git、REPL 调试等,而无需自写 PTY;tmux 已处理好伪终端。
# Using tmux for Interactive Commands
## Overview
Interactive CLI tools (vim, interactive git rebase, REPLs, etc.) cannot be controlled through standard bash because they require a real terminal. tmux provides detached sessions that can be controlled programmatically via `send-keys` and `capture-pane`.
## When to Use
**Use tmux when:**
- Running vim, nano, or other text editors programmatically
- Controlling interactive REPLs (Python, Node, etc.)
- Handling interactive git commands (`git rebase -i`, `git add -p`)
- Working with full-screen terminal apps (htop, etc.)
- Commands that require terminal control codes or readline
**Don't use for:**
- Simple non-interactive commands (use regular Bash tool)
- Commands that accept input via stdin redirection
- One-shot commands that don't need interaction
## Quick Reference
| Task | Command |
|------|---------|
| Start session | `tmux new-session -d -s <name> <command>` |
| Send input | `tmux send-keys -t <name> 'text' Enter` |
| Capture output | `tmux capture-pane -t <name> -p` |
| Stop session | `tmux kill-session -t <name>` |
| List sessions | `tmux list-sessions` |
## Core Pattern
### Before (Won't Work)
```bash
# This hangs because vim expects interactive terminal
bash -c "vim file.txt"
```
### After (Works)
```bash
# Create detached tmux session
tmux new-session -d -s edit_session vim file.txt
# Send commands (Enter, Escape are tmux key names)
tmux send-keys -t edit_session 'i' 'Hello World' Escape ':wq' Enter
# Capture what's on screen
tmux capture-pane -t edit_session -p
# Clean up
tmux kill-session -t edit_session
```
## Implementation
### Basic Workflow
1. **Create detached session** with the interactive command
2. **Wait briefly** for initialization (100-500ms depending on command)
3. **Send input** using `send-keys` (can send special keys like Enter, Escape)
4. **Capture output** using `capture-pane -p` to see current screen state
5. **Repeat** steps 3-4 as needed
6. **Terminate** session when done
### Special Keys
Common tmux key names:
- `Enter` - Return/newline
- `Escape` - ESC key
- `C-c` - Ctrl+C
- `C-x` - Ctrl+X
- `Up`, `Down`, `Left`, `Right` - Arrow keys
- `Space` - Space bar
- `BSpace` - Backspace
### Working Directory
Specify working directory when creating session:
```bash
tmux new-session -d -s git_session -c /path/to/repo git rebase -i HEAD~3
```
### Helper Wrapper
For easier use, see `/home/jesse/git/interactive-command/tmux-wrapper.sh`:
```bash
# Start session
/path/to/tmux-wrapper.sh start <session-name> <command> [args...]
# Send input
/path/to/tmux-wrapper.sh send <session-name> 'text' Enter
# Capture current state
/path/to/tmux-wrapper.sh capture <session-name>
# Stop
/path/to/tmux-wrapper.sh stop <session-name>
```
## Common Patterns
### Python REPL
```bash
tmux new-session -d -s python python3 -i
tmux send-keys -t python 'import math' Enter
tmux send-keys -t python 'print(math.pi)' Enter
tmux capture-pane -t python -p # See output
tmux kill-session -t python
```
### Vim Editing
```bash
tmux new-session -d -s vim vim /tmp/file.txt
sleep 0.3 # Wait for vim to start
tmux send-keys -t vim 'i' 'New content' Escape ':wq' Enter
# File is now saved
```
### Interactive Git Rebase
```bash
tmux new-session -d -s rebase -c /repo/path git rebase -i HEAD~3
sleep 0.5
tmux capture-pane -t rebase -p # See rebase editor
# Send commands to modify rebase instructions
tmux send-keys -t rebase 'Down' 'Home' 'squash' Escape
tmux send-keys -t rebase ':wq' Enter
```
## Common Mistakes
### Not Waiting After Session Start
**Problem:** Capturing immediately after `new-session` shows blank screen
**Fix:** Add brief sleep (100-500ms) before first capture
```bash
tmux new-session -d -s sess command
sleep 0.3 # Let command initialize
tmux capture-pane -t sess -p
```
### Forgetting Enter Key
**Problem:** Commands typed but not executed
**Fix:** Explicitly send Enter
```bash
tmux send-keys -t sess 'print("hello")' Enter # Note: Enter is separate argument
```
### Using Wrong Key Names
**Problem:** `tmux send-keys -t sess '\n'` doesn't work
**Fix:** Use tmux key names: `Enter`, not `\n`
```bash
tmux send-keys -t sess 'text' Enter # ✓
tmux send-keys -t sess 'text\n' # ✗
```
### Not Cleaning Up Sessions
**Problem:** Orphaned tmux sessions accumulate
**Fix:** Always kill sessions when done
```bash
tmux kill-session -t session_name
# Or check for existing: tmux has-session -t name 2>/dev/null
```
## Real-World Impact
- Enables programmatic control of vim/nano for file editing
- Allows automation of interactive git workflows (rebase, add -p)
- Makes REPL-based testing/debugging possible
- Unblocks any tool that requires terminal interaction
- No need to build custom PTY management - tmux handles it all