Loading...
Loading...
Tmux execution support for long-running and persistent commands. Load this skill when you need to: (1) run commands expected to exceed tool timeout (over 60s), (2) start persistent servers or dev processes, (3) run TUI/interactive applications, (4) execute parallel isolated tasks in separate sessions, (5) run remote commands over SSH that must survive disconnection, (6) handle tmux errors like 'capture-pane blocked in interactive_bash'. Trigger phrases: 'run in background', 'start server', 'long-running', 'tmux session', 'keep running', 'persistent process', 'dev server', 'training script', 'git clone large repo', 'docker build', 'capture-pane blocked'.
npx skill4agent add arthur0824hao/skills skill-system-tmux| Condition | Route | Examples |
|---|---|---|
| Estimated time > 60s | tmux | |
| Command does not self-terminate | tmux | |
| Requires TUI or interactive input | tmux | |
| Parallel isolated execution needed | tmux | Multiple agents, concurrent test suites |
| Remote execution over SSH | tmux | Commands that must survive connection drops |
| Atomic, non-interactive, fast (<30s) | direct bash | |
| Single-shot with expected output | direct bash | |
clonepushcheckoutnpm installpip installcargo builddocker buildmakewebpackFormat: {project}-{purpose}
Agent-created sessions (MANDATORY prefix):
oc-{purpose} # e.g., oc-audit, oc-verify, oc-render
oc-{project}-{task} # e.g., oc-skills-build, oc-subproject-test
User/infra sessions (no prefix required):
postgres-dev
frontend-watch
ml-trainingoc-oc-oc-exp-runneroc-*531# Kill any existing session with same name, then start fresh
tmux kill-session -t {session} 2>/dev/null || true
tmux new-session -d -s {session} bash -c '{command}'interactive_bashtmux_command: new-session -d -s {session}
tmux_command: send-keys -t {session} "{command}" Entertmux_command: new-session -d -s {session}
tmux_command: send-keys -t {session} "{command}" Entertmux_command: has-session -t {session}tmux_command: capture-pane -p -t {session}tmux_command: capture-pane -p -t {session} -S -1000/(\\$|>|#)\s*$/mtmux_command: kill-session -t {session}tmux_command: kill-session -t {session}
# (ignore error if doesn't exist)
tmux_command: new-session -d -s {session}tmux list-sessions -F '#{session_name} #{session_activity}' | grep '^oc-'tmux list-sessions -F '#{session_name}' | grep '^oc-' | xargs -I{} tmux kill-session -t {}$╰─# List sessions with last activity timestamp
tmux list-sessions -F '#{session_name} #{session_activity}'
# Compare #{session_activity} (epoch) against current time
# Capture pane of suspects to verify idle state# Find opencode processes whose parent tmux pane was killed
ps aux | grep opencode | grep -v grep
# Check if port is held by a zombie
lsof -i :{port} 2>/dev/null
# Force kill if needed (SIGTERM first, SIGKILL if unresponsive after 5s)
kill {pid} && sleep 5 && kill -0 {pid} 2>/dev/null && kill -9 {pid}oc-*interactive_bashtmux# Create session
tmux_command: new-session -d -s oc-my-session
# Send command
tmux_command: send-keys -t oc-my-session "npm run dev" Enter
# Read output
tmux_command: capture-pane -p -t oc-my-session
# Kill session
tmux_command: kill-session -t oc-my-sessionbashtimeoutbash(command="npm install", timeout=300000) # 5 min timeoutcapture-paneinteractive_bash'capture-pane' is blocked in interactive_bashinteractive_bashcapture-panepipe-panesave-bufferBash# WRONG — will be blocked:
# interactive_bash: tmux_command: capture-pane -p -t oc-dev-server
# CORRECT — use Bash tool:
tmux capture-pane -p -t oc-dev-server
# Capture with history (last 1000 lines):
tmux capture-pane -p -t oc-dev-server -S -1000
# Capture and grep for specific output:
tmux capture-pane -p -t oc-dev-server | grep -i "error\|ready\|listening"capture-panelist-sessionsdisplay-messageshow-optionsBashinteractive_bashsend-keysnew-sessionkill-sessionsession not foundcan't find session: oc-xxxtmux kill-session -t oc-build 2>/dev/null || true
tmux new-session -d -s oc-build bash -c 'make all'duplicate sessionduplicate session: oc-xxx# Reuse (send new command to existing session):
tmux send-keys -t oc-build "make clean && make all" Enter
# Or kill and recreate:
tmux kill-session -t oc-build 2>/dev/null || true
tmux new-session -d -s oc-build bash -c 'make all'no server runningno server running on /tmp/tmux-*/defaultnew-sessiontmux new-session -d -s oc-init echo "tmux ready"| tmux subcommand | Use | Use |
|---|---|---|
| Yes | Yes |
| Yes (preferred) | Yes |
| Yes | Yes |
| NO — blocked | Yes (required) |
| Avoid | Yes (preferred) |
| Yes | Yes |
| NO — blocked | Yes (required) |
| Avoid | Yes (preferred) |
| Don't | Do Instead |
|---|---|
| Route every command through tmux | Use direct bash for fast, atomic commands |
| Forget to kill sessions after use | Always clean up with |
Use generic session names like | Use descriptive names: |
Create agent sessions without | Always prefix: |
| Poll capture-pane in tight loops | Use 1-2s intervals between polls |
| Start a new session without killing old one | Always kill-before-new for same session name |
| Send commands without clearing the line first | Send |
| Leave sessions running after task completes | Run bulk reclaim (Pattern 6) at session end |
Use | Always use |
Retry blocked commands in | Switch to |
oc-*oc-exp-runnertmux send-keysmachines.jsontmux_sessionoc-*{
"schema_version": "2.0",
"id": "skill-system-tmux",
"version": "1.0.0",
"capabilities": ["tmux-route", "tmux-session-manage", "tmux-capture", "tmux-reclaim", "tmux-error-workaround"],
"effects": ["proc.exec"],
"operations": {
"route-command": {
"description": "Decide whether a command should use direct bash or tmux, and execute accordingly.",
"input": {
"command": { "type": "string", "required": true, "description": "The shell command to execute" },
"estimated_duration": { "type": "string", "required": false, "description": "Estimated duration: short (<30s), medium (30-120s), long (>120s)" }
},
"output": {
"description": "Execution result or session name for tmux-routed commands",
"fields": { "route": "string", "session": "string", "result": "string" }
},
"entrypoints": {
"agent": "Apply decision matrix from SKILL.md, then execute via bash or interactive_bash"
}
},
"manage-session": {
"description": "Create, list, kill, or check tmux sessions.",
"input": {
"action": { "type": "string", "required": true, "description": "Action: create, kill, list, check, capture" },
"session_name": { "type": "string", "required": false, "description": "Target session name" }
},
"output": {
"description": "Session status or captured output",
"fields": { "status": "string", "output": "string" }
},
"entrypoints": {
"agent": "Use interactive_bash with appropriate tmux subcommand"
}
},
"reclaim-resources": {
"description": "Bulk cleanup of stale agent tmux sessions and orphaned processes. Kills all oc-* sessions, detects idle non-agent sessions, and reclaims zombie processes holding ports.",
"input": {
"scope": { "type": "string", "required": false, "description": "Scope: agent-only (default, kills oc-* only), all-stale (includes idle non-agent sessions with user confirmation)" }
},
"output": {
"description": "Summary of killed sessions and processes",
"fields": { "sessions_killed": "array", "processes_killed": "array", "ports_freed": "array" }
},
"entrypoints": {
"agent": "Follow Pattern 6 (Bulk Resource Reclaim) in SKILL.md"
}
}
},
"stdout_contract": {
"last_line_json": false,
"note": "Agent-executed; uses interactive_bash tool for tmux operations."
}
}