Multi-Session Patterns
Running multiple sessions lets you separate concerns cleanly: development, monitoring, deployment each live in their own named workspace.
Learning Focus
Design your sessions around context, not just habits. A good session naming convention reduces cognitive overhead during incidents.
When to Use Multiple Sessions
| Situation | Session Design |
|---|---|
| Ongoing development | work, staging, prod |
| Server maintenance | admin, logs, monitoring |
| Deployment | deploy, rollback, verify |
| Long-running jobs | build, migrate, export |
Recommended Session Structure
Development Server
Session: work
Window 0: editor → vim / nano / code-server
Window 1: server → npm run dev / python manage.py runserver
Window 2: git → git status, pull, push
Monitoring
Session: monitoring
Window 0: sysmon → htop | panes: top-left, top-right
Window 1: logs → tail -f app.log | panes: multiple log files
Deployment
Session: deploy
Window 0: deploy → deployment script running
Window 1: rollback → rollback script ready (not yet run)
Window 2: verify → health check commands
Creating a Multi-Session Setup
multi-session-setup.sh
#!/bin/bash
# Start development sessions
# Session 1: work
tmux new -s work -n editor -d
tmux new-window -t work -n server
tmux new-window -t work -n git
# Session 2: monitoring
tmux new -s monitoring -n sysmon -d
tmux send-keys -t monitoring:sysmon "htop" Enter
# Session 3: logs
tmux new -s logs -n app -d
tmux send-keys -t logs:app "tail -f /var/log/syslog" Enter
echo "Sessions ready. Attach with: tmux attach -t work"
Navigating Multiple Sessions
# From inside tmux:
Ctrl+b s → Interactive list of all sessions and windows
Ctrl+b ( → Previous session
Ctrl+b ) → Next session
The Ctrl+b s list is tree-shaped and lets you select any session/window with arrow keys + Enter.
Naming Conventions
| Pattern | Example | Benefit |
|---|---|---|
| Environment-based | work-prod, work-dev | Clear environment context |
| Task-based | deploy, migrate, build | Temporary, disposable |
| Role-based | editor, monitoring | Permanent daily-driver sessions |
tip
Use short, memorable names. You will type these dozens of times per day. w, m, d are valid session names too.
Switching Sessions in a Script
# Switch to a session from outside tmux
tmux switch-client -t work
# Only works if you are already attached to a tmux session somewhere
Cleaning Up Old Sessions
# List all sessions
tmux ls
# Kill a finished session
tmux kill-session -t deploy
# Kill all sessions except the one you are in
tmux kill-session -a
note
kill-session -a kills all other sessions except the currently attached one.
Common Pitfalls
| Pitfall | What happens | Fix |
|---|---|---|
| Too many unnamed sessions | Can't tell which is which | Always name sessions with -s |
| Forgetting to clean up finished sessions | Clutter and confusion | Kill session when job is done |
| Mixing work contexts in one session | Context switching overhead | One session per concern |