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

Default ShortcutModification ShortcutAction
Ctrl+b dCtrl+Space dDetach from session

Detaching keeps the session and all its contents alive.

From the Command Line

tmux detach-client -t work

Renaming Sessions

Default ShortcutModification ShortcutAction
Ctrl+b $Prefix e sRename current session

From the command line:

tmux rename-session -t oldname newname

Switching Between Sessions

Default ShortcutModification ShortcutAction
Ctrl+b sCtrl+Space sOpen interactive session list
Ctrl+b (Alt+HomeSwitch to previous session
Ctrl+b )Alt+EndSwitch 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

Session Management Cheatsheet

ActionCommandDefault ShortcutModification Shortcut
New sessiontmux new -s nameCtrl+Space N
New detached sessiontmux new -s name -d
List sessionstmux lsCtrl+b sCtrl+Space s
Attach to sessiontmux attach -t name
DetachCtrl+b dCtrl+Space d
Rename sessiontmux rename-session -t old newCtrl+b $Prefix e s
Switch sessionsCtrl+b s / Ctrl+b ( / )Ctrl+Space s / Alt+Home / Alt+End
Kill sessiontmux kill-session -t nameCtrl+Space k
Kill servertmux kill-server

Shell Aliases

Three shell functions loaded from ~/.bash_aliases/TMUX/tmux.sh:

Quick Reference
Default CommandShell AliasDescription
tmux attach -t <name>ta <name>Attach to a named session (or switch-client inside tmux)
tmux lstlList all sessions
tmux new -s <name> -d + tmux attach -t <name>tns <name>Create new session and attach
Auto-loading

.bashrc sources ~/.bash_aliases_loader, which recursively loads all *.sh files under ~/.bash_aliases/. Add new alias files to any subdirectory — they load automatically.

# ~/.bash_aliases/TMUX/tmux.sh
ta() {
if [ -z "$1" ]; then echo -e "Usage: ta <session-name>"; return 1; fi
if [ -n "$TMUX" ]; then tmux switch-client -t "$1";
else tmux attach -t "$1"; fi
}
tl() { tmux ls "$@"; }
tns() {
if [ -z "$1" ]; then echo -e "Usage: tns <session-name>"; return 1; fi
tmux new-session -d -s "$1"
if [ -n "$TMUX" ]; then tmux switch-client -t "$1";
else tmux attach -t "$1"; fi
}

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