/jonhill90-skills:tmuxfrom jonhill90-skills
Uses tmux from an agent with explicit pane targeting, state inspection, verified input delivery, response polling, recovery, and multi-agent supervision. Use when an agent CLI, TUI, REPL, authentication flow, or other interactive command must retain terminal state across tool calls.
Ships in jonhill90-skills. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
Read when SKILL.md points to them; scripts run unread.
Use tmux when a task needs a persistent terminal state across tool calls.
tmux -V
If tmux is not installed, stop and ask the user to install it.
tmux sessions survive SSH drops, terminal closes, and laptop sleep. This makes them ideal for AI agent workflows:
Use a dedicated socket directory:
SOCKET_DIR="${TMUX_SOCKET_DIR:-${TMPDIR:-/tmp}/tmux-agent-sockets}"
mkdir -p "$SOCKET_DIR"
SOCKET="$SOCKET_DIR/agent.sock"
Use short session names with no spaces. Target panes by window name (e.g. session:shell) rather than numeric index (e.g. session:0.0) — numeric indexes depend on base-index/pane-base-index settings and are not portable.
SESSION="agent-work"
tmux -S "$SOCKET" new-session -d -s "$SESSION" -n shell
tmux -S "$SOCKET" send-keys -t "$SESSION":shell -l -- "echo ready"
sleep 0.1
tmux -S "$SOCKET" send-keys -t "$SESSION":shell Enter
tmux -S "$SOCKET" capture-pane -p -J -t "$SESSION":shell -S -200
After creating a session, show monitor commands:
tmux -S "$SOCKET" attach -t "$SESSION"
tmux -S "$SOCKET" capture-pane -p -J -t "$SESSION":shell -S -200
Always use explicit targets. Never rely on the "active" pane — it changes when you split, select, or switch windows.
A target built from an empty variable does not error — it silently hits the active pane. tmux send-keys -t "$SESSION:" with $SESSION empty targets whatever window is currently active, which on a shared supervisor session is often the supervisor's own pane. This is how a misdirected send loses its intended recipient's context while looking like nothing went wrong. Any target assembled from a prior command's output needs an explicit non-empty check before it is used:
IDX=$(tmux list-windows -t "$SESSION" -F '#{window_index} #{window_name}' \
| awk -v n="$WANT" '$2==n{print $1}')
[ -n "$IDX" ] || { echo "no window named $WANT" >&2; exit 1; }
| Format | Example | When to use |
|---|---|---|
session:window | work:shell | Single-pane windows |
session:window.{selector} | work:shell.{top} | Layout-relative (predictable splits) |
session:window.%ID | work:shell.%3 | Specific pane by ID (from list-panes) |
After a vertical split (split-window -v), use {top} and {bottom}.
After a horizontal split (split-window -h), use {left} and {right}.
Use {last} for the previously active pane.
tmux -S "$SOCKET" list-panes -t "$SESSION":shell \
-F '#{pane_id} #{pane_index} #{pane_width}x#{pane_height} #{pane_current_command}'
Use the %-ID (first column) when layout is unknown or complex.
Before sending input to a pane, confirm it contains what you expect:
# Capture and check — is this the pane I think it is?
tmux -S "$SOCKET" capture-pane -p -J -t "$SESSION":shell.{bottom} -S -5
If the content doesn't match your expectation (wrong shell, wrong directory, unexpected output), you have the wrong target. Fix the target before sending.
Before sending any input, verify the pane is in a state where your input will be interpreted correctly. This is the most common agent failure mode: correct pane, wrong pane state.
A pane might be:
Always capture-pane and inspect the last few lines before sending:
OUTPUT=$(tmux -S "$SOCKET" capture-pane -p -J -t "$TARGET" -S -5)
echo "$OUTPUT"
What to look for:
| Pane state | What you see in capture | Safe to send? | Action |
|---|---|---|---|
| Shell prompt idle | $, ❯, % at the end with no running process | Yes | Send your command |
| Command running | Output scrolling, no prompt visible | No | Wait for completion, or C-c first |
| Approval/confirm prompt | [Y/n], (y/N), Continue?, approve? | No — your text answers the prompt | Answer the prompt deliberately, or C-c to cancel |
| TUI active (editor, REPL) | Editor chrome, line numbers, REPL >>> | No — your text inserts into the TUI | Use TUI-appropriate input, or exit the TUI first |
| Agent thinking | Spinner, Thinking..., progress indicator | No — agent hasn't finished | Wait for agent to return to its prompt |
| Agent prompt waiting | Agent's input prompt visible (a boxed > in Claude Code, › in Codex) | Yes — for agent input | Send agent-directed input |
After capturing, decide your next keystroke. Paste does not equal send. Text sitting in the input line has not been submitted until you press Enter — but pressing Enter blindly is the most common agent mistake.
| You see in capture | Diagnosis | Correct action | Wrong action |
|---|---|---|---|
| Your text visible on the input line, shell prompt present, no output yet | Prompt pasted but not submitted | Press Enter to submit | Assuming paste == send; doing nothing |
[Y/n], (y/N), Continue?, approve? | Approval/confirm prompt active | Decide deliberately: send y, n, or C-c to cancel | Blindly pressing Enter (accepts default you may not want) |
| Output streaming, no prompt visible | Command or agent mid-task | Wait. Do not send anything. | Sending new input (queues or corrupts) |
Agent spinner, Thinking..., progress bar | Agent processing | Wait. Poll capture-pane until agent returns to its prompt. | Pressing Enter or sending text (interrupts agent) |
| Text on input line but you're unsure if the pane is ready | Ambiguous state | Capture again. Do not act on stale or unclear state. | Guessing and pressing Enter |
| Stale/unwanted text sitting in the input line | Queued input needs clearing | Send C-u (clear line) before sending new input | Pressing Enter (executes the stale text) |
| Blocking prompt or hung process you need to abort | Need to cancel | Send Escape (for TUI prompts) or C-c (for shell/process) | Sending C-c to a TUI that interprets it as copy, or Escape to a shell |
Key distinctions:
C-uclears the current input line without executing it — use when you see stale queued text.Escapedismisses TUI dialogs and prompts — use for agent approval UIs, editor prompts, or modal dialogs.C-cinterrupts the running process — use for shell commands, streaming output, or hung processes. In some TUIs,C-chas a different meaning (copy), so check first.- When uncertain, capture again. A second
capture-panecosts nothing. A wrong keystroke can corrupt state.
# What process owns the pane right now?
tmux -S "$SOCKET" list-panes -t "$TARGET" \
-F '#{pane_current_command} #{pane_pid}'
If pane_current_command is bash/zsh/fish, the shell is likely at a prompt. If it shows another process name (node, python, vim, claude), something is running — do not send shell commands.
Rule: Never send to a pane you haven't captured in this turn. Pane state changes between tool calls. Always capture, inspect, decide, then send.
tmux -S "$SOCKET" send-keys -t "$TARGET" -l -- "$cmd"
sleep 0.1
tmux -S "$SOCKET" send-keys -t "$TARGET" Enter
-l (literal) for text payloads.Enter separately with a short delay.C-c, C-d).After sending input, verify it landed. Two distinct checks using plain tmux:
| Check | What it answers | How to do it |
|---|---|---|
| Send confirmation | Did the text arrive in the target pane? | capture-pane + grep for the sent text |
| Response readiness | Has the command produced output or returned to prompt? | Poll with capture-pane in a loop, grep for output/prompt pattern |
tmux -S "$SOCKET" send-keys -t "$TARGET" -l -- "echo hello-canary"
sleep 0.1
tmux -S "$SOCKET" send-keys -t "$TARGET" Enter
sleep 0.3
OUTPUT=$(tmux -S "$SOCKET" capture-pane -p -J -t "$TARGET" -S -10)
if echo "$OUTPUT" | grep -q "hello-canary"; then
echo "SEND OK"
else
echo "SEND FAILED — text not found in target pane"
fi
Poll capture-pane until you see the expected output or a shell prompt:
# Simple poll loop — wait up to 15s for a pattern
DEADLINE=$(($(date +%s) + 15))
while true; do
OUTPUT=$(tmux -S "$SOCKET" capture-pane -p -J -t "$TARGET" -S -50)
if echo "$OUTPUT" | grep -qE 'Done|ready|❯|\$'; then
echo "Response detected"
break
fi
if [ "$(date +%s)" -ge "$DEADLINE" ]; then
echo "Timed out waiting for response"
break
fi
sleep 0.5
done
Never skip send verification. "I sent it" is not the same as "the pane received it." Silent failures (wrong target, pane not ready, socket mismatch) produce no error — only verification catches them.
When working with tmux panes, distinguish these four states clearly:
| State | What happened | How to detect | Common mistake |
|---|---|---|---|
| Text visible in pane | tmux rendered the text | capture-pane shows the text | Assuming visible = accepted |
| Input accepted | The process in the pane received the keystrokes | Process shows activity (spinner, "thinking...") | Assuming accepted = responded |
| Delivered to intended pane | The text landed in the pane you targeted | capture-pane -t $TARGET + grep confirms | Sending to active pane instead of explicit target |
| Process responding | The process is producing meaningful output | Polling capture-pane detects output pattern | Treating silence as "still working" when the send was lost |
Always confirm at least states 3 and 4 for critical operations.
If you sent input to the wrong pane:
capture-pane -t $INTENDED_TARGET — your text is absent.capture-pane -t $WRONG_TARGET — your text appeared here instead.C-c to the wrong pane if the command is running.# Cancel the accidental command in the wrong pane
tmux -S "$SOCKET" send-keys -t "$WRONG_TARGET" C-c
# Re-send to the correct pane
tmux -S "$SOCKET" send-keys -t "$CORRECT_TARGET" -l -- "$cmd"
sleep 0.1
tmux -S "$SOCKET" send-keys -t "$CORRECT_TARGET" Enter
# Check socket exists and permissions
ls -la "$SOCKET"
# Common fix: socket dir not writable
chmod 700 "$SOCKET_DIR"
# On shared systems, use TMUX_SOCKET_DIR to isolate
export TMUX_SOCKET_DIR="$HOME/.tmux-sockets"
mkdir -p "$TMUX_SOCKET_DIR"
# Try interrupt first
tmux -S "$SOCKET" send-keys -t "$TARGET" C-c
# If still hung, kill the pane's process
PANE_PID=$(tmux -S "$SOCKET" display-message -t "$TARGET" -p '#{pane_pid}')
kill -9 "$PANE_PID"
One agent supervising another in split panes — upward prompt flow, watcher loops, approval handling, recurring supervision — is in references/supervisor-lanes.md. The pane discipline above still applies: verify the target, check the state, send text and Enter separately, confirm it landed.
When a pane runs a TUI (agent CLI, REPL, editor):
capture-pane before sending. The TUI may have advanced, errored, or prompted since you last looked.pane_current_command from list-panes. If it shows bash/zsh instead of the TUI process, the TUI has exited.capture-pane + grep loop with appropriate patterns and timeouts for TUI readiness markers.# Check what process is running in the pane
tmux -S "$SOCKET" list-panes -t "$SESSION":shell \
-F '#{pane_id} #{pane_current_command}'
# list sessions and panes
tmux -S "$SOCKET" list-sessions
tmux -S "$SOCKET" list-panes -a
# capture output
tmux -S "$SOCKET" capture-pane -p -J -t "$SESSION":shell -S -400
# interrupt running command
tmux -S "$SOCKET" send-keys -t "$SESSION":shell C-c
Use one session per tool or repo for isolation.
# Claude Code
tmux -S "$SOCKET" new-session -d -s claude-main -n shell
tmux -S "$SOCKET" send-keys -t claude-main:shell -l -- "cd /path/to/repo && claude"
sleep 0.1
tmux -S "$SOCKET" send-keys -t claude-main:shell Enter
# Codex
tmux -S "$SOCKET" new-session -d -s codex-main -n shell
tmux -S "$SOCKET" send-keys -t codex-main:shell -l -- "cd /path/to/repo && codex"
sleep 0.1
tmux -S "$SOCKET" send-keys -t codex-main:shell Enter
When prompting these tools later, keep using the same session and split text/Enter.
For filesystem isolation between agents, create one git worktree per agent
before starting tmux sessions, and keep worktree logic out of this skill. (A
using-git-worktrees skill was referenced here previously; it is not
installed and is not part of this collection.)
Pattern: one worktree per agent, one tmux session (or pane) per worktree.
Run the self-test script to verify tmux mechanics work in your environment:
bash "$(dirname "$0")/scripts/self-test.sh" # or scripts/self-test.sh beside this SKILL.md
See scripts/self-test.sh — beside this file, wherever the skill is installed — for the full procedure. It creates an isolated tmux socket, verifies pane targeting, send verification, cross-pane isolation, and wrong-target recovery, then cleans up.
tmux -S "$SOCKET" kill-session -t "$SESSION"
tmux -S "$SOCKET" kill-server
All four sit in scripts/ beside this file.
| Script | Use |
|---|---|
self-test.sh | verify tmux mechanics in this environment |
find-sessions.sh | list agent sessions on a socket, or across all sockets with --all |
wait-for-text.sh | poll a pane until a pattern appears, with a timeout |
supervisor-watch.sh | watch a supervised pane and exit on ready / approval / timeout |
/loop (Claude Code) or a shell loop (other agents) for recurring supervision.What SKILL.md sets; muted values are Claude Code's defaults
Other plugins' skills for the same job
npx claudepluginhub jonhill90/skills --plugin jonhill90-skills44 skills in this plugin
/adopt-or-buildDecide, per component, whether to adopt an existing name, dependency, library, or tool or build it in-house, weighing blast radius over convenience. Use at the point a name or dependency is about to be chosen or recommended — before it is proposed, not after. Not for finding a technology's capability ceiling (research-the-limit), not the mechanism for genuinely different reviewer lenses (ask-a-council, which this skill may call), and not a substitute for attacking the chosen answer (devils-advocate, which this skill invokes as its final step)./ask-a-councilConvene several harnesses or models against one question, each doing a distinct job it can fail at — different evidence, a different objective, or a withheld conclusion — before an artifact becomes load-bearing and being wrong is expensive. Diversity comes from what each reviewer is given, never from a character it plays. Use when the failure modes genuinely differ in kind — a single reviewer's prompt would only catch what its own lens looks for. Not for a question a cheap deterministic check settles (run the check first); not for one reviewer's prompt (sanity-check owns that); not for dispatch mechanics or isolation boundaries (dispatching-subagents owns those); not for trusting a verdict already returned (verify-the-instrument owns that)./central-hub-mcpOrient on Central Hub through its read-only hub-mcp server — call hub_orient first, then only the targeted tool the answer still needs — and connect an AI harness to hub-mcp. Use when a session needs live Central Hub state (c1 cluster apps, the agent notebook, the bi-temporal fact graph, open PRs and CI), when hub-mcp tools appear in the tool list, or when configuring Claude Code, Codex CLI, Claude Desktop, Copilot, Antigravity, Pi, OpenClaw, Hermes, Paperclip, Rex, or another MCP client to reach hub-mcp./close-the-loopConfirm you have everything needed to finish a change before starting it — what to implement, how it will be tested, and which rules govern it. Use before non-trivial work, when reviewing a plan for completeness, or when preparing a PR that needs planning evidence./create-skillDesign, create, and validate portable Agent Skills with effective triggers, concise instructions, and reusable scripts, references, or assets. Use when adding a new skill, substantially restructuring an existing skill, or validating a skill's structure, frontmatter, links, and bundled scripts./decide-by-variantBuild several genuinely different real artifacts in the real medium with fake data, and let the human pick by looking, instead of asking a taste decision in prose. Use whenever a decision has no objectively right answer — a glyph, a layout, a default, a name, a wording, a sort order — and describing the options in words would cost the human more thought than looking at them would. Run determine-intent first — if the answer is already a known parameter, build nothing. Not for getting different positions from agents on one question (ask-a-council); not for attacking an answer once chosen (devils-advocate runs after a variant is picked, not instead of building one).