[Tmux Series 3] Practice Managing Sessions and Windows

한국어 버전

Manage Sessions and Windows

The real power of Tmux is that you can disconnect from your terminal without stopping your work. In this guide, project-a acts as a dev-server session and project-b acts as a notes or operations session so you can practice switching contexts without losing running processes.


What We’ll Do

  • Create and manage multiple sessions
  • Add windows and switch among them
  • Detach and reattach sessions
  • Confirm that long-running tasks survive session switches

Sessions vs. Windows

Before practicing the commands, it helps to separate the two ideas clearly.

  • A session is a top-level workspace that can stay alive after you detach.
  • A window is a tab inside one session.
  • Use different sessions for separate contexts such as different projects, SSH tasks, or long-running environments you want to revisit later.
  • Use multiple windows inside one session for related tasks in the same context, such as a dev server, logs, and notes.

In this post, project-a and project-b are two separate sessions. Inside project-a, you will later add another window for logs.


Quick Orientation

When you enter Tmux, the line at the bottom is the status bar.

  • The left side usually shows the current session name, such as project-a.
  • The middle area shows windows such as 0:api* or 0:api 1:logs*.
  • The number before : is the window index.
  • The text after : is the window name.
  • * marks the currently active window in that session.

Prerequisites

  • Terminal with Tmux installed
  • Basic familiarity with Tmux shortcuts

Practice 1: Create Multiple Sessions

Create the Project A session

Fire up a session, run a dev server, and detach.

tmux new -s project-a zsh · ~/workspace
Ready. Press Replay to run the scripted session.

Detach reminder: Press Ctrl+b, release, then press d to leave the session running in the background.

Detaching does not pause the session. It only disconnects your current terminal from it, so the shell and any running process keep going until you reattach or stop them.

What’s happening:

  • project-a is the session name running the dev server
  • 0:api* means window 0 is named api, and * marks it as the active window
  • After detaching, the server keeps running off-screen

Create the Project B session

tmux new -s project-b zsh · ~/workspace
Ready. Press Replay to run the scripted session.

Use project-b for quick notes or ops checks you’ll revisit briefly.

List sessions

tmux ls - session list zsh · ~/workspace
Ready. Press Replay to run the scripted session.

Reading the list:

  • project-a: 1 windows — currently a single window
  • project-b: 1 windows — same here
  • (created …) shows when each session started

Practice 2: Switch Sessions

Attach to a specific session

tmux attach -t project-a
tmux attach -t project-b

Reattaching restores the session exactly where you left it. In practice, that means you return to the last active window in that session with the running processes still alive.

Switch sessions from inside Tmux

Here’s the flow: you’re working in project-b, press Ctrl+b s, open the session chooser, pick project-a, and return to the last active window there.

Ctrl+b s - session switcher zsh · ~/workspace
Ready. Press Replay to run the scripted session.
  • Use arrow keys to highlight a session
  • Press Enter to switch
  • You return to the same running work without restarting it

Practice 3: Manage Windows

Create a new window

Attach to project-a, then create a fresh window.

Ctrl+b c - create window zsh · ~/workspace
Ready. Press Replay to run the scripted session.

Status bar update:

  • Changes from 0:api* to 0:api 1:logs*
  • Window 0 (api) keeps the dev server
  • Window 1 (logs*) is active and tails logs

By default, Tmux often names a window after the main process running in it. Renaming the window makes the workflow easier to scan later.

Switch between windows

Next window:

Ctrl+b n

Previous window:

Ctrl+b p

Jump to a specific window:

Ctrl+b 0    # window 0
Ctrl+b 1    # window 1

For windows 10 and above, use Ctrl+b ' and type the window number.

Rename a window

Ctrl+b , - rename window zsh · ~/workspace
Ready. Press Replay to run the scripted session.

What you see:

  1. (rename-window) prompt appears
  2. Enter logs
  3. Status bar updates to 0:api 1:logs*

View window list

Ctrl+b w

Sample list:

(0) 0: api
(1) 1: logs*

Close a window

Method 1:

Ctrl+b &

This is destructive: it closes the current window and terminates the processes running in it.

Confirmation:

Kill window logs? (y/n)

Type y.

Method 2:

exit

If the current window has only one pane, exit closes the window. If it has multiple panes, exit closes only the current pane.


Practice 4: Shut Down Sessions

Kill a specific session

tmux kill-session -t project-b

Use this when you want to stop only one session and leave the others running.

Kill every session

tmux kill-server

Use this carefully. It stops every Tmux session and every process running inside those sessions.


Key Shortcut Summary

Shortcut Action
Ctrl+b s Session selector
Ctrl+b c Create a window
Ctrl+b n Next window
Ctrl+b p Previous window
Ctrl+b 0-9 Jump to window by number
Ctrl+b , Rename current window
Ctrl+b w Show window list
Ctrl+b & Close window
Ctrl+b d Detach session

Troubleshooting

“Too many sessions, I’m lost”

Tip: Use clear names.

tmux new -s frontend-dev

“Window numbers starting at 0 bothers me”

Fix:

# Add to ~/.tmux.conf
echo 'set -g base-index 1' >> ~/.tmux.conf

# Reload from inside an active tmux session
tmux source-file ~/.tmux.conf

If no Tmux session is currently running, start one first or restart Tmux after updating the config. The new index setting applies cleanly to newly created windows.

“I detached, but is the process still running?”

Check:

tmux ls
tmux attach -t project-a

If the session still appears in tmux ls, its shell and running processes are still alive.


Practice Checklist

  • Created multiple sessions (project-a, project-b)
  • Listed sessions with tmux ls
  • Switched between sessions
  • Created a window (Ctrl+b c)
  • Renamed a window (Ctrl+b ,)
  • Navigated windows (Ctrl+b n/p)
  • Closed a window (Ctrl+b &)

Next Guide

👉 Tmux Series Part 4: Split Panes and Configure Tmux

💬 댓글

이 글에 대한 의견을 남겨주세요