Session Lifecycle
A session is the top-level container in tmux. Mastering session management means you always know where your work is and can get back to it in seconds.
After this lesson you can navigate between multiple sessions confidently and clean up dead sessions without disrupting active ones.
Creating Sessions
Basic (unnamed)
tmux
Creates an unnamed session. Works but hard to manage once you have many.
Named (recommended)
tmux new-session -s work
# or shorter
tmux new -s work
Named with Initial Window Name
tmux new -s work -n editor
Named, Detached (start in background)
tmux new -s build -d
Useful for scripts that start sessions programmatically.
Named, Starting a Specific Command
tmux new -s logs -d "tail -f /var/log/syslog"
Listing Sessions
tmux ls
# or
tmux list-sessions
Output:
build: 1 windows (created Mon Apr 7 04:00:10 2026) [220x50]
logs: 1 windows (created Mon Apr 7 04:00:15 2026) [220x50] (attached)
work: 2 windows (created Mon Apr 7 04:00:00 2026) [220x50]
The (attached) tag shows which session your current terminal has attached.
Attaching to Sessions
# attach to a specific session
tmux attach -t work
# or
tmux a -t work
# attach to the most recent session
tmux attach
Attach and Switch Clients
If someone else is attached to a session, you can detach them and take over:
tmux attach -t work -d
Using -d disconnects any other client currently attached to that session.
Detaching
From Inside a Session
Ctrl+b d
Detaching keeps the session and all its contents alive.
From the Command Line
tmux detach-client -t work
Renaming Sessions
# from inside the session
Ctrl+b $
# from outside
tmux rename-session -t oldname newname
Switching Between Sessions
# from inside any session
Ctrl+b s # opens interactive session list
Ctrl+b ( # switch to previous session
Ctrl+b ) # switch to next session
Killing Sessions
# kill a specific session
tmux kill-session -t work
# kill ALL sessions (shuts down tmux server)
tmux kill-server
kill-server destroys every session and every process running inside tmux. Use with caution.
Full Session Lifecycle Diagram
stateDiagram-v2
direction LR
[*] --> Created: tmux new -s name
Created --> Active: windows and panes running
Active --> Detached: Ctrl+b d
Detached --> Active: tmux attach -t name
Active --> Renamed: tmux rename-session
Renamed --> Active
Active --> Killed: tmux kill-session -t name
Detached --> Killed: tmux kill-session -t name
Killed --> [*]
Session Management Cheatsheet
| Action | Command | Shortcut (inside tmux) |
|---|---|---|
| New session | tmux new -s name | — |
| New detached session | tmux new -s name -d | — |
| List sessions | tmux ls | Ctrl+b s |
| Attach to session | tmux attach -t name | — |
| Detach | — | Ctrl+b d |
| Rename session | tmux rename-session -t old new | Ctrl+b $ |
| Switch sessions | — | Ctrl+b s / Ctrl+b ( / ) |
| Kill session | tmux kill-session -t name | — |
| Kill server | tmux kill-server | — |
Common Pitfalls
| Pitfall | What happens | Fix |
|---|---|---|
| Not naming sessions | Confusing list of numbers | Always use -s name |
Attaching without checking ls first | Overwrites wrong session | Run tmux ls before attaching |
Running kill-server instead of kill-session | All sessions destroyed | Be explicit: use kill-session -t name |
Hands-On Practice
# create multiple sessions
tmux new -s work -d
tmux new -s logs -d
tmux new -s monitoring -d
# list them
tmux ls
# attach to work
tmux attach -t work
# switch to logs: Ctrl+b s, select logs
# detach: Ctrl+b d
# clean up
tmux kill-session -t logs
tmux kill-session -t monitoring
tmux kill-session -t work