Session Management

tmux Session Management

A tmux session is a persistent workspace that groups windows and panes together and continues running in the background even after you disconnect. Sessions survive SSH drops, network changes, and terminal closures — making tmux the standard tool for remote server work.

Quick Session Command List

The most common commands for session lifecycle management. Use shorthand for speed or full-form for clarity.

Action Command (Full) Command (Short) Shortcut (Inside)
List Sessionstmux list-sessionstmux lsPrefix s
New Sessiontmux new-session -s nametmux new -s name
Attach Sessiontmux attach-session -t nametmux a -t name
Detach Sessiontmux detach-clienttmux detachPrefix d
Kill Sessiontmux kill-session -t name
Kill ALL Sessionstmux kill-server

What Are tmux Sessions?

A tmux session is a persistent workspace managed by the tmux server process. Sessions contain one or more windows, each of which can be split into multiple panes. This three-level hierarchy (session → window → pane) gives you complete control over your terminal workspace. Unlike a standard terminal, a tmux session keeps running after you close your terminal or lose your SSH connection — you can reattach to it from any terminal at any time.

How to Create a New tmux Session

Start a named session to organize your work. Named sessions are easier to find and reattach to later.

bash — create sessions

# Create a named session (attaches immediately)

$ tmux new-session -s mysession

$ tmux new -s mysession


# Create a session in detached mode (stays in background)

$ tmux new -s mysession -d


# Create an unnamed session (gets a numeric ID)

$ tmux new


# Create with a specific working directory

$ tmux new -s myproject -c ~/projects/myproject

Named Sessions

Give sessions meaningful names with -s name. Named sessions are easy to identify in tmux ls and easy to reattach to. Use project names: tmux new -s frontend.

Unnamed Sessions

tmux assigns numeric IDs to unnamed sessions (0, 1, 2…). These are fine for quick tasks but harder to manage when you have multiple sessions running.

Detached Mode -d

The -d flag creates the session in the background without attaching. Useful in scripts to set up environments before connecting.

How to "tmux list sessions"

View all currently running sessions with their names, window counts, and status.

bash — list sessions

# Short form

$ tmux ls

mysession: 3 windows (created Thu Apr 17 10:00:00 2026)

work: 1 window (created Thu Apr 17 11:00:00 2026) (attached)


# Full command

$ tmux list-sessions


# Custom format string

$ tmux ls -F '#{session_name}: #{session_windows} windows, created #{session_created}'


# Check if a specific session exists (returns 0 if yes)

$ tmux has-session -t mysession && echo "exists" || echo "not found"

How to "tmux attach" to a Session

Pick up exactly where you left off by reattaching to any running workspace.

bash — attach sessions

# Attach to a named session

$ tmux attach -t mysession

$ tmux a -t mysession


# Attach to the most recent session

$ tmux attach


# Attach and detach any other clients from this session

$ tmux attach -t mysession -d


# From SSH: first list sessions, then attach

$ ssh user@server

$ tmux ls

$ tmux attach -t mysession

How to "tmux detach" a Session

Keep your programs running safely in the background while disconnecting your terminal.

bash — detach sessions

# Key binding (inside tmux): Ctrl+b then d

$ Ctrl+b d


# From command line (detach current client)

$ tmux detach-client


# Detach ALL clients from every session

$ tmux detach-client -a

How to Rename a tmux Session

bash — rename session

# Rename from command line

$ tmux rename-session -t oldname newname


# Key binding (inside tmux): Ctrl+b then $

$ Ctrl+b $

(rename-session) newname█

How to "tmux kill session"

Stop a session and immediately terminate all processes running within it.

bash — kill session

# Kill a specific named session

$ tmux kill-session -t mysession


# Kill via command mode (inside tmux): Ctrl+b : kill-session

$ Ctrl+b :kill-session


# kill-session vs kill-server:

# kill-session ends ONE session; kill-server ends ALL sessions + the server

How to "tmux kill all sessions"

Stop every session at once — useful when resetting your environment.

bash — kill all sessions

# Kill the tmux server (terminates ALL sessions instantly)

$ tmux kill-server


# Kill all sessions individually (preserves server)

$ tmux ls | xargs -I{} tmux kill-session -t {}


# Shell script loop method

$ for s in $(tmux ls -F '#{session_name}'); do tmux kill-session -t "$s"; done

Session Scripting & Automation

Automate complex multi-window and multi-pane layouts at startup using shell scripts.

dev-session.sh — example startup script

#!/bin/bash

# Create session (detached) and set up layout

$ tmux new-session -d -s dev -c ~/projects/myapp


# Rename first window

$ tmux rename-window -t dev:0 'editor'


# Split the editor window and start vim

$ tmux send-keys -t dev:0 'nvim .' Enter

$ tmux split-window -h -t dev:0

$ tmux send-keys -t dev:0 'npm run dev' Enter


# Create a second window for git

$ tmux new-window -t dev -n 'git'


# Attach to the session

$ tmux attach -t dev

🔧 Session Managers: tmuxinator & tmuxp

For complex, repeatable layouts, consider dedicated session managers:

  • tmuxinator — YAML-based session layouts (Ruby gem)
  • tmuxp — Python-based session manager (JSON/YAML configs)

Frequently Asked Questions

What are tmux sessions?
A tmux session is a persistent workspace managed by the tmux server. It groups one or more windows together and continues running in the background after you detach or lose your connection. Sessions are the top level of the tmux hierarchy: session → window → pane.
How do I create a new tmux session?
Run tmux new-session -s mysession (or the shorthand tmux new -s mysession) to create and immediately attach to a named session. To create a session in the background without attaching, add the -d flag: tmux new -s mysession -d.
How do I list tmux sessions?
Run tmux ls (short for tmux list-sessions) to see all running sessions. Each line shows the session name, number of windows, creation time, and whether any client is attached. Use tmux ls -F '#{session_name}' for custom output format.
How do I attach to a tmux session?
Run tmux attach -t mysession (or tmux a -t mysession) to reattach to a named session. To attach to the most recently used session, simply run tmux attach. This works from any terminal — even over SSH from a remote machine — as long as the tmux server is running on that host.
How do I detach from a tmux session without killing it?
Press Ctrl+b then d to detach from the current session. The session and all programs running inside it continue in the background. You can also run tmux detach-client from the command line, or tmux detach-client -a to detach all connected clients.
How do I rename a tmux session?
From the command line: tmux rename-session -t oldname newname. From inside tmux: press Ctrl+b $ to enter a new name interactively at the bottom of the screen.
How do I kill a tmux session?
Run tmux kill-session -t mysession to permanently terminate a specific session and all its windows and panes. From inside tmux, use Ctrl+b : then type kill-session. Note: kill-session terminates one session; tmux kill-server terminates all sessions and the entire tmux server process.
How do I kill ALL tmux sessions at once?
To kill all sessions and shut down the tmux server: tmux kill-server. To kill all sessions individually (without stopping the server): tmux ls | xargs -I{} tmux kill-session -t {}. In a shell loop: for s in $(tmux ls -F '#{session_name}'); do tmux kill-session -t "$s"; done.

Related Resources

/commands/
Full tmux command reference
/cheat-sheet/
All key bindings at a glance
/config/
~/.tmux.conf reference
/doc/
Full documentation hub