Agent skill
tmux
Use when you need a persistent terminal environment for long-running processes, programs requiring a TTY, REPLs, debuggers, TUI apps, or concurrent terminals — while the agent continues executing other commands.
Install this agent skill to your Project
npx add-skill https://github.com/l-lin/dotfiles/tree/main/home-manager/modules/share/ai/.config/ai/skills/tmux
SKILL.md
tmux (agent automation) skill
Purpose
You are not teaching the human tmux. You are using tmux yourself as a controllable terminal multiplexer to:
- run long-lived processes (servers, watchers, debuggers)
- interact with programs that need a TTY
- keep state across multiple commands (REPLs, shells)
- run multiple concurrent terminals (logs in one pane, debugger in another)
Prime directive (don't trash the user's tmux)
Use a dedicated session in the user's existing tmux server.
- Session name:
ai-agent-sandbox - Do NOT create a separate socket (
-L) — work within the user's existing tmux server - Only manipulate
ai-agent-sandbox, never touch user's other sessions
Targets (tmux addressing)
Always use explicit targets.
- full target format:
ai-agent-sandbox:<window>.<pane> - examples:
ai-agent-sandbox:main.1,ai-agent-sandbox:1.1
Check indexing first — don't assume 0 or 1:
tmux display-message -p "#{base-index}"
Standard workflow
1) Ensure session exists
tmux start-server
tmux has-session -t ai-agent-sandbox 2>/dev/null \
|| tmux new-session -d -s ai-agent-sandbox -n main
2) Create panes/windows as needed
tmux split-window -t ai-agent-sandbox:main -h
tmux select-layout -t ai-agent-sandbox:main even-horizontal
3) Send commands
tmux send-keys -t ai-agent-sandbox:main.1 "bash -lc 'rg -n \"TODO\" .'" C-m
- Prefer
bash -lc '…'for a predictable shell environment - Keep the tmux string simple; let
bash -lchandle quoting complexity
4) Synchronize — never use sleep
Use tmux wait-for for deterministic completion:
TOKEN="AI_AGENT_DONE_$$"
# send command in pane, signal token on finish
tmux send-keys -t ai-agent-sandbox:main.1 \
"bash -lc 'set -e; rg -n \"TODO\" .; tmux wait-for -S ${TOKEN}'" C-m
# block until done
tmux wait-for "${TOKEN}"
If the command might fail but you still need completion:
bash -lc 'set +e; <cmd>; echo EXIT:$?; tmux wait-for -S TOKEN'
5) Capture output
# last 200 lines
tmux capture-pane -p -t ai-agent-sandbox:main.1 -S -200
For full buffer, increase history first:
tmux set-option -t ai-agent-sandbox -g history-limit 20000
Common recipes
Long-lived server + health check
# start server in pane 1
tmux send-keys -t ai-agent-sandbox:main.1 "bash -lc 'bin/dev'" C-m
# check health in pane 2
tmux send-keys -t ai-agent-sandbox:main.2 "bash -lc 'sleep 1; curl -fsS localhost:3000/health'" C-m
Stream logs to disk:
LOG=/tmp/ai-agent-tmux-main1.log
: >"$LOG"
tmux pipe-pane -o -t ai-agent-sandbox:main.1 "cat >> '$LOG'"
Stop a stuck command
tmux send-keys -t ai-agent-sandbox:main.1 C-c
Interactive REPL / debugger
- Start REPL in a pane
- Send lines via
send-keys - Capture output after each step
- Synchronize with
wait-foror detect prompts via captured output
Guardrails
- Never
tmux kill-server— kill only your session - Always use explicit
-t <target> - Never
tmux attachunless the user asked for a live view - Don't rely on user keybindings; use the tmux CLI only
Cleanup
tmux kill-session -t ai-agent-sandbox
Recommended Agent Skills
Expand your agent's capabilities with these related and highly-rated skills.
napkin
Maintain a per-repo napkin as a continuously curated runbook (not a session log). Activates EVERY session. Read and curate it before work, keep only recurring high-value guidance, organize by priority-sorted categories, and cap each category at top 10 items..
datadog-pup
Use when interacting with Datadog resources using the `pup` CLI, especially for APM traces, metrics, monitors, notebooks, and synthetic tests.
writing-skill
Use when creating new skills, editing existing skills, or verifying skills work before deployment
clarifying-intent
Use when user asks to create, build, design, add, or generate something — especially when the request is vague, underspecified, or the scope is unclear. Use before starting creative work, features, components, or any new functionality.
code-simplifier
Simplifies and refines code for clarity, consistency, and maintainability while preserving all functionality. Use when asked to "simplify code", "clean up code", "refactor for clarity", "improve readability", or review recently modified code for elegance. Focuses on project-specific best practices.
clear-writing
Use when writing or editing any prose humans will read — documentation, commit messages, error messages, UI text, reports, or explanations. Also use when user says "write clearly", "clear writing", or "improve writing".
Didn't find tool you were looking for?