Skip to main content
tmux

Sessions

Step 2 of 8

Sessions

A tmux session is a container for windows and panes. Sessions are independent — each has its own set of windows and can be detached/attached separately.

Sessions are perfect for organizing work by project, server, or task.

Creating sessions

Start a new session with a name:

$

If you don't provide a name, tmux uses a number (0, 1, 2...).

NOTE:

Use descriptive names: frontend, backend, prod-server, database-migration.

Listing sessions

From outside tmux:

$

Output shows all sessions:

project-a: 1 windows (created Tue Feb  4 10:30:15 2025)
frontend: 2 windows (created Tue Feb  4 09:15:00 2025)
backend: 3 windows (created Tue Feb  4 08:45:30 2025) (attached)

Inside tmux, use the command mode:

$

Or press Ctrl-b s to switch to an interactive session list.

Attaching to sessions

Attach to the most recent session:

$

Attach to a specific session:

$
NOTE:

Only one session can be attached at a time in a single terminal. If project-a is already attached elsewhere, you'll need to detach it first or use tmux attach -d -t project-a to force detach elsewhere.

Detaching from sessions

From inside tmux:

$

This is the detach key binding. The session keeps running in the background.

NOTE:

Think of detach as "minimize" — the session is still there, just not visible.

Switching between sessions

While inside tmux, switch to another session:

$

This shows an interactive list. Use arrow keys to select, then press Enter.

Or switch directly:

$

This prompts for a session name.

Renaming sessions

Rename the current session:

$

Or from command line:

$

Killing sessions

Close and delete a session from outside:

$

Kill all sessions:

$
NOTE:

kill-server closes everything — all sessions, windows, panes. Use carefully.

Practical workflow

Here's a common development workflow:

# Morning: start project session
tmux new -s project

# Do some work... (run tests, servers, etc.)

# Detach and go to lunch
Ctrl-b d

# Afternoon: reattach to where you left off
tmux attach -t project

# Everything is still running — servers, tests, vim sessions!

Multiple session organization

Organize your work by creating separate sessions:

# Web development
tmux new -s frontend
tmux new -s backend

# Server work
tmux new -s prod-server
tmux new -s staging-db

# Learning/experimentation
tmux new -s experiments

Each session maintains its own state, windows, and layout.

Session persistence

Sessions survive:

  • Network disconnects (SSH drops)
  • Closing your terminal window
  • Logging out of a remote server
  • Your computer going to sleep

This is why tmux is essential for remote work and long-running processes.

Key bindings summary

KeyAction
Ctrl-b dDetach from session
Ctrl-b sChoose session interactively
Ctrl-b $Rename session
Ctrl-b (Switch to previous session
Ctrl-b )Switch to next session

Command-line summary

CommandDescription
tmux new -s nameCreate new session
tmux lsList sessions
tmux attachAttach to most recent
tmux attach -t nameAttach to specific session
tmux detachDetach (works inside tmux)
tmux rename-session -t old newRename session
tmux kill-session -t nameKill a session
tmux kill-serverKill all sessions
NOTE:

Press Ctrl-b : to open command prompt, then type commands like new-session, list-sessions, rename-session. Tab-completion works here!


Next: Step 3 → Windows — Managing multiple windows within a session