Skip to main content
skill CX Codex

using-tmux-for-interactive-commands — Claude Code skill

Teaches an agent to drive vim, REPLs and interactive git rebase through detached tmux sessions. Useful when plain bash just hangs.

Install into Claude Code · Skills CLI (Vercel) All methods and platforms ↓
npx skills add obra/superpowers-lab --skill using-tmux-for-interactive-commands -a claude-code
Open on GitHub

What using-tmux-for-interactive-commands does

Plain bash cannot talk to programs that expect a real terminal. vim, git rebase -i, git add -p, a Python or Node REPL — they all wait for keystrokes and stall when launched as a normal command. This skill lays out the workaround: the agent starts a detached tmux session, pushes keys with send-keys and reads the screen with capture-pane -p.

Inside you get a quick-reference table, the tmux key names (Enter, Escape, C-c, arrow keys) and worked examples for a Python REPL, editing a file in vim and an interactive rebase. There is a section on the usual mistakes: capturing right after new-session and seeing a blank screen, forgetting to send Enter as its own argument, typing \n instead of a key name. It also reminds you to kill sessions so they do not pile up.

tmux has to be installed. The skill does not replace your normal Bash tool — for simple non-interactive commands it tells you to skip tmux entirely. One example points at a wrapper script from the author's own machine, so you either recreate that file or work with tmux directly.

What it helps with

  • edit a file in vim from the agent without touching a terminal
  • run an interactive git rebase -i and rewrite commit history
  • evaluate an expression in a Python REPL and grab the output
  • step through git add -p without typing by hand
  • drive full-screen tools like htop

Example prompts for the agent

  • Open vim /tmp/file.txt in a tmux session, insert a line and save the file
  • Start a Python REPL in tmux, compute math.pi and show me the output
  • Run git rebase -i HEAD~3 in a tmux session and squash the last commits

How to install using-tmux-for-interactive-commands

1Skills CLI (Vercel)

npx skills add obra/superpowers-lab --skill using-tmux-for-interactive-commands -a claude-code

2Manually: put the files in place

~/.claude/skills/using-tmux-for-interactive-commands/SKILL.md

Copy the whole skill folder; for one project use .claude/skills/using-tmux-for-interactive-commands/

Step by step, with commands for each platform: How to install skills in Claude Code: five ways

Questions about using-tmux-for-interactive-commands

How do I install using-tmux-for-interactive-commands in Claude?

Run npx skills add obra/superpowers-lab --skill using-tmux-for-interactive-commands -a claude-code. The skill file lands at ~/.claude/skills/using-tmux-for-interactive-commands/SKILL.md.

What does this skill do?

It gives the agent a pattern for controlling interactive CLI tools through tmux: create a detached session, send keys, capture the pane, kill the session. That covers vim, REPLs and interactive rebase.

When should I not use tmux?

For simple non-interactive commands the skill points you back to the regular Bash tool. It also does not fit programs that read input from stdin or one-shot commands with no interaction.

Source text

SKILL.md · MIT
---
name: using-tmux-for-interactive-commands
description: Use when you need to run interactive CLI tools (vim, git rebase -i, Python REPL, etc.) that require real-time input/output - provides tmux-based approach for controlling interactive sessions through detached sessions and send-keys
---

# 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

© obra · MIT · obra/superpowers-lab

Similar skills

All skills for Agent setup: memory, context, orchestration →

From the same set3

Project sponsors

Companies that keep this analytics open
Gold sponsor

Impressions, clicks and code copies — open statistics. We keep the numbers public for the same reason NeBlask itself is public. Become a sponsor