tmux sessions
I started to use tmux sessions a lot in the last months. Some of my learnings are in this post.
Creating a new session without opening a new terminal
From inside an existing tmux session, there is no need to open another terminal. Just create a new session directly:
Or use the shortcut:
The -d flag creates the session in the background (detached), so the current session stays in focus.
Switch to it afterwards (see below).
Listing sessions
From inside tmux, Ctrl-b s opens an interactive session picker that also shows the windows inside each session.
Switching between sessions
Ctrl-b s-
Opens the session list. Use arrow keys to pick one, Enter to switch.
Ctrl-b (-
Switch to the previous session.
Ctrl-b )-
Switch to the next session.
From the shell:
Tree view of sessions and windows
Ctrl-b w-
Opens an interactive tree view of every session, with each session expanded to show its windows (and panes). Navigate with the arrow keys, press Enter to jump straight to that window, or
xto kill the highlighted item.
Renaming a session
Ctrl-b $-
Prompts to rename the current session.
From the shell:
Showing the session name in the status bar
By default the tmux status bar does not make it obvious which session you are in.
Adding #S to status-right in ~/.tmux.conf displays the current session name.
Note that status-right is a single string and setting it replaces the previous value entirely -- so include everything you want shown:
set-option -g status-right '#[fg=cyan]#S #[fg=green]| #[fg=blue]#H #[fg=green]|#[fg=yellow]#(uptime | rev | cut -d":" -f1 | rev | sed s/,//g ) #[fg=green]| #[fg=blue]%Y-%m-%d %H:%M'
The #(...) form runs a shell command -- here a small uptime | rev | cut | rev | sed pipeline grabs just the three load averages from the end of uptime's output and strips the commas.
Rendered, this looks like:
This puts the session name in front of the hostname, current load and date/time, separated by |.
Reload the config with Ctrl-b :source-file ~/.tmux.conf to see the change immediately.
See also
Claude Code tmux window names -- an earlier post on auto-renaming tmux windows (rather than sessions) when running long-lived commands like Claude Code.
