| name | tmux |
| description | Manage tmux sessions for background processes. Use to run long-running commands, manage multiple terminals, and capture output from background processes. |
Tmux Session Manager
Run and manage background processes using tmux.
Prerequisites
Install tmux:
brew install tmux
apt install tmux
CLI Reference
Create Session
tmux new-session -d -s mysession
tmux new-session -d -s mysession -n mywindow
tmux new-session -d -s mysession -c /path/to/dir
tmux new-session -d -s mysession "npm run dev"
tmux new-session -d -s dev -n server -c /project "npm run dev"
List Sessions
tmux list-sessions
tmux ls
tmux list-sessions -F "#{session_name}: #{session_windows} windows"
Send Keys to Session
tmux send-keys -t mysession "npm test" Enter
tmux send-keys -t mysession:mywindow "command" Enter
tmux send-keys -t mysession "partial command"
tmux send-keys -t mysession C-c
tmux send-keys -t mysession C-d
tmux send-keys -t mysession Escape
tmux send-keys -t mysession Up
Capture Output
tmux capture-pane -t mysession -p
tmux capture-pane -t mysession -p -S -100
tmux capture-pane -t mysession -p -S -
tmux capture-pane -t mysession -p > output.txt
Kill Session
tmux kill-session -t mysession
tmux kill-server
Attach to Session
tmux attach -t mysession
tmux new-session -A -s mysession
Window Management
tmux new-window -t mysession -n windowname
tmux select-window -t mysession:windowname
tmux kill-window -t mysession:windowname
tmux list-windows -t mysession
Pane Management
tmux split-window -t mysession -h
tmux split-window -t mysession -v
tmux select-pane -t mysession:0.1
tmux kill-pane -t mysession:0.1
Workflow Patterns
Run Dev Server in Background
tmux new-session -d -s devserver -c /project "npm run dev"
tmux capture-pane -t devserver -p -S -50
tmux send-keys -t devserver C-c
tmux kill-session -t devserver
Run Tests with Output Capture
tmux new-session -d -s tests "npm test"
sleep 30
tmux capture-pane -t tests -p -S - > test-output.txt
tmux kill-session -t tests
Multiple Services
tmux new-session -d -s services -n frontend
tmux new-window -t services -n backend
tmux new-window -t services -n database
tmux send-keys -t services:frontend "npm run dev" Enter
tmux send-keys -t services:backend "go run main.go" Enter
tmux send-keys -t services:database "docker-compose up db" Enter
for win in frontend backend database; do
echo "=== $win ==="
tmux capture-pane -t services:$win -p -S -10
done
Long-Running Process
tmux new-session -d -s build "npm run build:production"
watch -n 5 "tmux capture-pane -t build -p -S -20"
while tmux has-session -t build 2>/dev/null; do
sleep 10
echo "Still running..."
done
echo "Build complete"
Socket Mode (for Agents)
When running in agent context, use a dedicated socket:
SOCKET_PATH="/tmp/agent-tmux-$$"
tmux -S $SOCKET_PATH new-session -d -s agent "command"
tmux -S $SOCKET_PATH send-keys -t agent "input" Enter
tmux -S $SOCKET_PATH capture-pane -t agent -p
tmux -S $SOCKET_PATH kill-server
rm -f $SOCKET_PATH
Best Practices
- Name sessions descriptively - Easy to identify later
- Use
-d for detached - Don't block the terminal
- Capture output regularly - Before killing sessions
- Set working directory - Use
-c /path for context
- Clean up sessions - Kill when done
- Use sockets for isolation - Prevent conflicts between agents