| name | terminal-multiplexer |
| description | Run and manage background terminal sessions using tmux. Use when the user needs to start long-running processes, run multiple commands in parallel, keep tasks alive after disconnecting, or check on background job status. Do NOT use for simple one-off commands or when user explicitly requests alternative tools (screen, nohup).
|
Terminal Multiplexer
Use tmux to manage background terminal sessions.
Prerequisites
Verify tmux is installed before use:
command -v tmux >/dev/null 2>&1 || {
echo "Error: tmux is not installed"
echo "Install with: brew install tmux (macOS) or apt install tmux (Linux)"
exit 1
}
When to Use
- Long-running processes (servers, builds, downloads)
- Parallel execution of multiple commands
- Keeping tasks alive after SSH disconnect
- Capturing output from background jobs
When NOT to Use
- Simple one-off commands that complete quickly
- When user explicitly requests alternatives (screen, nohup)
- Interactive applications requiring full terminal features
Core Commands
Session Management
tmux new-session -s <name>
tmux new-session -d -s <name>
tmux ls
tmux attach -t <name>
tmux rename-session -t <old-name> <new-name>
tmux kill-session -t <name>
Sending Commands
tmux send-keys -t <name> "<command>" C-m
tmux new-session -d -s api-server
tmux send-keys -t api-server "bun run dev" C-m
Capturing Output
tmux capture-pane -p -t <name>
tmux capture-pane -t <name> && tmux save-buffer /tmp/output.txt
tmux capture-pane -p -t <name> | tail -n 20
Common Workflows
Start a Background Server
tmux new-session -d -s server -n app
tmux send-keys -t server "npm start" C-m
Run Multiple Tasks in Parallel
tmux new-session -d -s jobs -n worker1
tmux send-keys -t jobs:worker1 "npm run build:client" C-m
tmux new-window -t jobs -n worker2
tmux send-keys -t jobs:worker2 "npm run build:server" C-m
Check if a Process Finished
tmux capture-pane -p -t <name> | tail -n 20
Monitoring a Background Process
tmux new-session -d -s build -n compile
tmux send-keys -t build:compile "npm run build 2>&1 | tee build.log" C-m
tmux capture-pane -p -t build:compile | tail -n 10
tmux send-keys -t build:compile "echo $?" C-m
tmux capture-pane -p -t build:compile | tail -n 1
Detaching and Reattaching
tmux attach -t <name>
tmux attach
Troubleshooting
Session Already Exists
tmux ls | grep <name>
tmux attach -t <name>
tmux kill-session -t <name>
tmux new-session -d -s <name>
Session Not Found
tmux ls
Command Not Executing in Session
tmux list-panes -t <name>
tmux send-keys -t <name> "<command>" C-m
sleep 2
tmux capture-pane -p -t <name>
Best Practices
- Name sessions descriptively (e.g.,
dev-server, test-runner)
- Kill sessions when done to free resources
- Use
tmux ls to check existing sessions before creating new ones
- Prefer detached sessions (
-d) for background tasks
- Use
tmux send-keys over tmux new-session for existing sessions