home / skills / openclaw / skills / tmux-remote-control

This skill enables remote control of tmux sessions to automate interactive CLIs by sending keystrokes and scraping pane output.

npx playbooks add skill openclaw/skills --skill tmux-remote-control

Review the files below or copy the command above to add this skill to your agents.

Files (3)
SKILL.md
3.4 KB
---
name: tmux
description: Remote-control tmux sessions for interactive CLIs by sending keystrokes and scraping pane output.
metadata:
  { "openclaw": { "emoji": "🧵", "os": ["darwin", "linux"], "requires": { "bins": ["tmux"] } } }
---

# tmux Skill

Use tmux only when you need an interactive TTY. Prefer exec background mode for long-running, non-interactive tasks.

## Default Server — No Custom Sockets

**Always use the default tmux server.** Do NOT use `-S` custom sockets. The user needs to `tmux attach` easily without knowing obscure socket paths.

## Session Naming

**Convention:** `oc-${project}-${feature}` (e.g. `oc-knowhere-date-range-picker`, `oc-deck-auth-flow`)

- `oc-` prefix = OpenClaw-managed, avoids collision with user sessions
- Easy to find: `tmux ls | grep oc-`

## Quickstart

```bash
SESSION=oc-myproject-feature

tmux new-session -d -s "$SESSION" -c ~/projects/myproject
tmux send-keys -t "$SESSION" 'claude --dangerously-skip-permissions' Enter
tmux capture-pane -p -J -t "$SESSION" -S -200
```

After starting a session, tell the user:

```
To monitor: tmux attach -t $SESSION
```

## Targeting panes and naming

- Target format: `session:window.pane` (defaults to `:0.0`).
- Keep names short; avoid spaces.
- Inspect: `tmux list-sessions`, `tmux list-panes -a`.

## Sending input safely

- Prefer literal sends: `tmux send-keys -t target -l -- "$cmd"`.
- Control keys: `tmux send-keys -t target C-c`.
- For interactive TUI apps like Claude Code/Codex, **do not** append `Enter` in the same
  `send-keys`. These apps may treat a fast text+Enter sequence as paste/multi-line input
  and not submit. Send text and `Enter` as separate commands with a small delay:

```bash
tmux send-keys -t target -l -- "$cmd" && sleep 0.1 && tmux send-keys -t target Enter
```

## Watching output

- Capture recent history: `tmux capture-pane -p -J -t target -S -200`.
- Attaching is OK; detach with `Ctrl+b d`.

## Spawning processes

- For python REPLs, set `PYTHON_BASIC_REPL=1` (non-basic REPL breaks send-keys flows).

## Orchestrating Coding Agents (Codex, Claude Code)

tmux excels at running multiple coding agents in parallel:

```bash
# Create sessions in different worktrees
tmux new-session -d -s oc-project-fix1 -c ~/projects/project-fix1
tmux new-session -d -s oc-project-fix2 -c ~/projects/project-fix2

# Launch agents
tmux send-keys -t oc-project-fix1 'claude --dangerously-skip-permissions' Enter
tmux send-keys -t oc-project-fix2 'codex --full-auto' Enter

# Send a prompt (text + Enter separated by delay)
tmux send-keys -t oc-project-fix1 -l -- "Fix the date picker styling." && sleep 0.1 && tmux send-keys -t oc-project-fix1 Enter

# Poll for completion (check if shell prompt returned)
for sess in oc-project-fix1 oc-project-fix2; do
  if tmux capture-pane -p -t "$sess" -S -3 | grep -q "❯"; then
    echo "$sess: DONE"
  else
    echo "$sess: Running..."
  fi
done

# Get full output
tmux capture-pane -p -t oc-project-fix1 -S -500
```

**Tips:**

- Use separate git worktrees for parallel fixes (no branch conflicts)
- `bun install` / `pnpm install` first before running agents in fresh clones
- Check for shell prompt (`❯` or `$`) to detect completion
- Codex needs `--yolo` or `--full-auto` for non-interactive fixes

## Cleanup

- Kill a session: `tmux kill-session -t "$SESSION"`.
- Kill all OpenClaw sessions: `tmux ls -F '#{session_name}' | grep '^oc-' | xargs -n1 tmux kill-session -t`.

Overview

This skill provides remote control of tmux sessions for interactive command-line agents and tools by sending keystrokes and scraping pane output. It is designed for short-lived interactive tasks where an actual TTY is required, and uses clear session naming and default-server behavior to keep sessions discoverable and user-friendly. Prefer background exec mode for long-running non-interactive work.

How this skill works

The skill creates and targets tmux sessions using the default server (no custom sockets) and a consistent naming convention (oc-${project}-${feature}). It sends literal keystrokes or control sequences to specific session:window.pane targets, optionally separating text and Enter with a short delay to avoid TUI paste issues. Pane output is scraped via tmux capture-pane for history polling and result retrieval.

When to use it

  • Running interactive CLIs or TUI agents that require a real TTY (e.g., code-writing agents, REPLs).
  • Orchestrating multiple parallel agent sessions in isolated worktrees for concurrent fixes.
  • When you need to let a human attach easily with tmux attach -t $SESSION.
  • Polling short-lived runs where scraping pane history to detect completion is practical.

Best practices

  • Always use the default tmux server; do not use -S custom sockets so users can attach normally.
  • Name sessions with the oc-${project}-${feature} prefix to avoid collisions and simplify discovery.
  • Send text with literal mode (tmux send-keys -l) and send Enter as a separate command after a small delay.
  • Target panes explicitly using session:window.pane and keep names short without spaces.
  • For Python REPLs set PYTHON_BASIC_REPL=1 to ensure send-keys behavior is reliable.
  • Use separate git worktrees for parallel agent runs to avoid branch conflicts.

Example use cases

  • Launch a coding agent in its own session, send a prompt, and poll the pane history for the shell prompt to detect completion.
  • Run two parallel fix sessions in different worktrees and capture each pane's output for comparison.
  • Start an interactive TUI tool that requires manual inspection, then instruct the user to tmux attach -t $SESSION to watch.
  • Capture the last few hundred lines from a session to archive an agent's result or log.

FAQ

Why avoid custom tmux sockets?

Custom sockets hide sessions behind obscure paths and prevent users from attaching with a simple tmux attach -t, so always use the default server.

How do I avoid paste issues when sending text to TUIs?

Send text with tmux send-keys -l and then send Enter separately after a short sleep (e.g., sleep 0.1) to avoid the app treating the sequence as a paste.

How can I detect when an agent finished?

Poll the pane with tmux capture-pane and check for the shell prompt or other completion markers (❯, $, etc.) in the recent history.