Windows: Tabs That Survive Closing the Terminal

What a Window Is

A window in tmux is like a tab in a browser. Each window occupies the full terminal area and contains one or more panes. You switch between windows with a keystroke, and the current window is shown in the status bar at the bottom.

A session holds windows. A window holds panes. A pane holds a shell. Every keystroke you type goes to the currently focused pane of the currently focused window of the currently attached session.

Creating Windows

<prefix> c                   create a new window (blank shell)

The new window becomes the current window. Your old window is still there, ready to switch back to.

Create one in a specific directory:

<prefix> :new-window -c ~/code

Or from the shell, targeting a session:

tmux new-window -t work -c ~/code/api

Naming Windows

By default, tmux names a window after the command currently running (usually your shell, or whatever you last ran). The name shows in the status bar.

Rename the current window:

<prefix> ,

A prompt appears. Type the new name. Enter.

From the shell:

tmux rename-window -t work:0 editor

work:0 means "session work, window index 0". See targeting below.

Automatic renaming

tmux by default updates a window's name as processes start and stop. If you rename manually, that freezes the name. Many people disable automatic renaming in their config:

set -g automatic-rename off
set -g allow-rename off

In chapter 7 we tidy up config. For now, just know: once you rename, the name sticks.

<prefix> n                   next window
<prefix> p                   previous window
<prefix> l                   last (most recent) window
<prefix> 0 through 9         jump to window index 0..9
<prefix> '                   prompt for window index
<prefix> w                   interactive window list

For everyday use, <prefix> w is great. It shows every session with every window underneath, and you pick one with Enter:

(0) + work: 3 windows
      0: editor (2 panes)
      1: shell
      2: logs
(1) + api: 2 windows
      0: server
      1: tests

Window indices

Windows are numbered starting from 0 by default. If you find that weird (most people do, since the number-keys on your keyboard start at 1), set base-index in your config:

set -g base-index 1
setw -g pane-base-index 1

Now windows and panes start at 1. <prefix> 1 goes to the first window, which matches what the keyboard suggests.

Moving and Reordering Windows

<prefix> .                   prompt for new index. Swaps with the window there
<prefix> :swap-window -t 0   swap current window with window 0
<prefix> :move-window -t 3   move current window to index 3

Reorder windows after closing one in the middle:

<prefix> :movew -r           renumber sessions so indices are contiguous

Better: set this once in your config and forget it:

set -g renumber-windows on

Now whenever a window closes, the remaining ones shift down.

Closing Windows

Exit the shell in a single-pane window:

exit

Or explicitly kill the window:

<prefix> &                   confirm, then kill the window

Or from the command prompt:

<prefix> :kill-window
<prefix> :kill-window -t 3   kill window at index 3

If a window has background processes (a running dev server, a tail -f), exit won't close the shell until they finish. <prefix> & kills the whole window, process tree and all.

Finding Windows

Remember the name, not the index? Search across all sessions:

<prefix> f

Type a pattern. tmux lists every matching window across every session. Enter to jump.

Moving a Window Between Sessions

Suppose you started a window in the "scratch" session and decide it belongs in "work":

<prefix> :move-window -t work:

That colon at the end means "next available index in 'work'". Current window moves to the "work" session.

Or link it to both (rare but possible):

<prefix> :link-window -t work:

Now the same window appears in both sessions. Edits in one show up in the other. A useful oddity.

Targeting Syntax

Once you get past basics, you'll pass targets to commands. The full form:

session:window.pane

Examples:

work                    the session named "work"
work:0                  window 0 of session "work"
work:editor             window named "editor" in session "work"
work:0.1                pane 1 of window 0 of session "work"

You rarely need all four parts. tmux fills in the current values. From inside a session, :0 is "window 0 of the current session". From inside a window, .1 is "pane 1 of the current window".

A Real Window Workflow

One session, four windows, named after the jobs they do:

tmux new -A -s api
<prefix> , api<Enter>         rename window 0 to "api" (editor)
<prefix> c                    new window
<prefix> , shell<Enter>       rename to "shell"
<prefix> c
<prefix> , tests<Enter>
<prefix> c
<prefix> , logs<Enter>

Now the status bar reads something like:

[api] 0:api 1:shell 2:tests 3:logs*

Switching between them is <prefix> n, <prefix> p, or <prefix> 0..3. This structure stays stable for the whole life of the project. Detach in the morning, reattach after lunch, everything is where you left it.

Windows vs Panes vs Tabs

Coming from a graphical terminal with tabs, the natural mapping is:

  • Session ≈ a terminal application window (a top-level workspace)
  • Window ≈ a tab
  • Pane ≈ a split within the tab

That mental model is close enough to start with. The differences get interesting in chapter 4.

Common Pitfalls

"My window index starts at 0, not 1." Default. Set base-index 1 in .tmux.conf if you prefer.

"I renamed a window and then it went back to the command name." allow-rename on (the default in some builds) lets the shell update the window title via escape sequences. Turn it off in config: set -g allow-rename off.

"I closed window 1 and now I have windows 0 and 2." Expected until you set renumber-windows on. With that on, windows compact down automatically.

"<prefix> & asks me for confirmation." Press y. If you want it unconditional, rebind: bind & kill-window. But the confirmation prompt has saved me more than once.

"I want to move a pane to its own window." <prefix> ! breaks the current pane out into its own window. The reverse operation (combining a window into a pane of another) is <prefix> :join-pane -t :0, where :0 is the target window.

Next Steps

Continue to 04-panes.md to split windows into multiple shells.