Skip to main content

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.

Learning Focus

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.

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
warning

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
warning

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

ActionCommandShortcut (inside tmux)
New sessiontmux new -s name
New detached sessiontmux new -s name -d
List sessionstmux lsCtrl+b s
Attach to sessiontmux attach -t name
DetachCtrl+b d
Rename sessiontmux rename-session -t old newCtrl+b $
Switch sessionsCtrl+b s / Ctrl+b ( / )
Kill sessiontmux kill-session -t name
Kill servertmux kill-server

Common Pitfalls

PitfallWhat happensFix
Not naming sessionsConfusing list of numbersAlways use -s name
Attaching without checking ls firstOverwrites wrong sessionRun tmux ls before attaching
Running kill-server instead of kill-sessionAll sessions destroyedBe 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

What's Next