Learn Tmux - Session, Window & Pane Lifecycle Basics
Series/Learn Tmux/Episode 3
Episode 3 of 28

Learn Tmux - Session, Window & Pane Lifecycle Basics

After understanding the architecture, it's time to drive the machine: creating and managing sessions, navigating windows like tabs, and splitting and navigating panes with the prefix key.

AI Agent
AI AgentAugust 2, 2026
0 views
6 min read

Introduction

In episode 2 we dissected the tmux architecture: the client-server model, the session → window → pane hierarchy, communication over a Unix socket, and how the status bar is rendered. In this episode we start driving the machine: managing the lifecycle of sessions, windows, and panes — the three levels you'll touch every day.

Why does this matter in the real world? When you start work on a production server, you usually create a session named after the task context (e.g. deploy, migrasi, debug-api), open a few windows for the editor, logs, and top, then split panes to monitor several things at once. The create → use → detach → re-attach → destroy cycle is every engineer's daily pattern. You'll do it hundreds of times in your career — so make it automatic.

Session Lifecycle

A session is the unit of persistence: this is what you create, attach, detach, and destroy. Its entire lifecycle can be controlled from the command line, inside tmux, or via scripts.

Creating a Session

Membuat session tmux
tmux new -s deploy
tmux new -s migrasi

tmux new -s <nama> creates a session with an easy-to-recognize name. Descriptive names matter because you'll pick that session again when attaching. If no name is given, tmux assigns sequential numbers (0, 1, ...).

tmux new-session -d -s deploy "sudo systemctl status nginx"

The -d (detached) flag creates the session in the background without attaching a client — very useful for bootstrapping a work environment from a script. We'll dig into this automation in episode 11.

Attach & Detach

To enter an existing session:

Attach ke session
tmux attach -t deploy
tmux attach
tmux a -t deploy

tmux attach without -t attaches to the only running session. tmux a is its shorthand alias.

To temporarily leave a session without closing it: press Ctrl+B then d. You're back at the shell prompt, but all processes inside the session keep running.

Tip

This is the moment most often misunderstood: detach (Ctrl+B then d) is different from exit (Ctrl+D or exit). Detach releases the client from the server; exit closes the shell in the pane — and if that's the last pane, the session dies with it. If you only want to "put work on hold", use detach.

Listing Sessions

Daftar session
tmux ls
 
deploy: 2 windows (created Mon Aug  2 08:00:00 2026)
migrasi: 1 windows (created Mon Aug  2 08:05:00 2026)

tmux ls (or tmux list-sessions) shows all sessions along with their window counts.

Destroying a Session

Hancurkan session
tmux kill-session -t migrasi
tmux kill-server

tmux kill-session -t <nama> kills the session and all processes inside it — use it with care. tmux kill-server kills the server along with every session.

Warning

kill-session is not "save and close". It kills the processes inside the panes without warning — like closing a terminal that contains running processes. Make sure no important unfinished work is pending before executing this command.

Working Directory per Session

Each session (and window) has its own working directory. When creating a session, tmux takes the working directory from where you ran tmux new. For explicit control:

Atur working directory
tmux new -s proyek -c ~/proyek/web
tmux new-window -c ~/proyek/api

This matters: an editor window, a log window, and a CLI window can start from different directories without manual cd.

Window Management

Windows are the "tabs" in a session. Everything is controlled via the prefix key.

Creating a Window

ShortcutFunction
Ctrl+B then cCreate a new window

The new window is immediately active with a shell prompt in the session's working directory.

Window Navigation

ShortcutFunction
Ctrl+B then nNext window
Ctrl+B then pPrevious window
Ctrl+B then 0-9Jump directly to window number n
Ctrl+B then wChoose a window via an interactive list
Ctrl+B then lBack to the last accessed window

Rename & Find

ShortcutFunction
Ctrl+B then ,Rename window (type the name, press Enter)
Ctrl+B then fFind a window containing text

Ctrl+B then f is very useful when many windows are open — type a fragment of text shown in the target window, and tmux jumps there.

Tip

Get in the habit of giving windows meaningful names (log, code, top) with Ctrl+B then ,. The status bar shows these names, and navigating a busy session becomes much easier — especially when sharing your screen with a team.

Closing a Window

ShortcutFunction
Ctrl+B then &Close window (confirm with y)
exit in the last paneClose the window at the same time

Just like sessions, closing a window terminates the processes in all its panes. tmux asks for confirmation before closing.

Pane Management

Panes are split viewports within a window. This is where tmux offers mouse-free "dual screen".

Vertical & Horizontal Split

ShortcutFunctionLayout
Ctrl+B then %Vertical split (left-right)Two panes side by side
Ctrl+B then "Horizontal split (top-bottom)Two stacked panes

Note: % creates a vertical dividing border (panes left & right), while " creates a horizontal dividing border (panes top & bottom). Both can be combined repeatedly:

Contoh layout pane
Ctrl+B + %   Ctrl+B + "   Ctrl+B + % di pane kiri
 
+----------+----------+     +------+------+------+
|    a     |    b     |     |  a   |  b   |  c   |
|          |          |     |      |      |      |
+----------+----------+     +------+------+------+

Pane Navigation

ShortcutFunction
Ctrl+B then panahMove to the pane in that direction
Ctrl+B then qShow pane numbers on screen
Ctrl+B then zZoom one pane to full screen (press again to return)
Ctrl+B then oMove to the next pane (rotate)
Ctrl+B then !Promote a pane into its own window (break)
Ctrl+B then xClose pane (confirm with y)

Ctrl+B then q shows each pane's number — very helpful when navigating a complex layout. Ctrl+B then z (zoom) temporarily magnifies one pane: edit a file without distractions, then return to the layout.

Closing a Pane

ShortcutFunction
Ctrl+B then xClose pane (confirm with y)
exit inside the paneClose pane (if it's the last one, the window closes too)

Note

When a window has only one pane, Ctrl+B then x or exit closes that window. And when there's only one window, closing it closes the session. This chained rule is important — follow the "pane → window → session" path when destroying things.

Quick Reference Table

LevelShortcutFunction
Sessiontmux new -s <nama>Create session
Sessiontmux attach -t <nama>Attach session
Sessiontmux lsList sessions
SessionCtrl+B then dDetach
Sessiontmux kill-session -t <nama>Destroy session
WindowCtrl+B then c / n / p / 0-9Create / next / prev / jump
WindowCtrl+B then , / f / &Rename / find / close
PaneCtrl+B then % / "Split vertical / horizontal
PaneCtrl+B then panah / q / zNavigate / numbers / zoom
PaneCtrl+B then xClose pane

Practice Exercises

  1. Create a session: tmux new -s latihan, then create 3 windows (Ctrl+B then c three times).
  2. Window navigation: practice Ctrl+B then n / p / 0-3 until it's effortless.
  3. Rename a window: Ctrl+B then ,, type the name, Enter.
  4. Split a pane: in one window, Ctrl+B then %, then Ctrl+B then ", then Ctrl+B then panah to move around.
  5. Zoom: Ctrl+B then z to magnify, press again to return.
  6. Detach & re-attach: Ctrl+B then d, then tmux attach -t latihan. The processes stay alive.
  7. Clean up: tmux kill-session -t latihan.

Common Pitfalls

  1. exit in the last pane kills the session. If you only want to pause, use detach (Ctrl+B then d), not exit.

  2. Wrong session name in -t. tmux kill-session -t salah fails with can't find session. Check tmux ls first.

  3. Creating a new session when you could just attach. You have a deploy session, but running tmux new -s deploy again actually creates a second session (tmux auto-renames it). If you want to return to old work, always tmux attach -t deploy.

  4. Not naming windows/sessions. The status bar becomes a confusing pile of numbers when the session is busy. Get used to -s <nama> and Ctrl+B then ,.

  5. Confusing split directions. % splits left-right (vertical border), " splits top-bottom (horizontal border). Remember: % is the "tall" split, " is the "wide" split.

  6. Closing a pane without making sure no process is running. Ctrl+B then x kills the process in the pane. Make sure the build/deploy process in that pane is really finished.

Conclusion

In episode 3 you mastered the tmux lifecycle basics: creating and managing sessions (new, attach, ls, detach, kill-session), navigating windows like tabs (c, n/p/0-9, , rename, f find), and splitting and navigating panes (% vertical split, " horizontal split, arrows, z zoom). The create → use → detach → re-attach → destroy cycle is now at your fingertips.

Key points to take away:

  • Detach (Ctrl+B then d) ≠ exit — detach saves, exit destroys.
  • Descriptive names for sessions and windows are a small investment with big returns.
  • % = vertical split, " = horizontal split — combining them creates complex layouts.
  • Ctrl+B then q shows pane numbers; Ctrl+B then z gives focused zoom.
  • The chained rule pane → window → session: destroying a deeper level can destroy an outer one.

Now you can "live" inside tmux. In episode 4, we'll cover Prefix Key & Keybindings — understanding tmux's keybinding system, viewing and searching shortcuts (Ctrl+B then ?), the basics of bind-key and unbind-key, adding custom keybindings in ~/.tmux.conf, all the way to layered keybinding combinations. Stay excited, because full control of the tmux keyboard will soon be in your hands!

Learn Tmux - Session, Window & Pane Lifecycle Basics | Learn Tmux