How to close a window in tmux?

Quick Answer

To close the current tmux window, run tmux kill-window, or press Ctrl+b then & to close the active window after confirming with y.

Ctrl+b+&
Green paper boat carrying three pale panes into a dark wastebasket

Detailed Explanation

The kill-window command removes the targeted window from the tmux session. Killing a window destroys every pane inside it.

Keyboard Shortcuts and Command-Prompt Flow

Inside tmux, you can close windows with key combinations or through the command prompt:

  • Ctrl+b & - Asks for confirmation in tmux's status line. Press y to confirm.
  • Ctrl+b : then type kill-window and press Enter to close the active window immediately without a confirmation prompt.

Targeting Specific Windows

Use the -t target flag to specify windows by index, session name, or exact window name:

# Kill window at index 1 in the current session:

tmux kill-window -t :1

# Kill window at index 3 in the session named "work":

tmux kill-window -t work:3

# Kill window named exactly "logs":

tmux kill-window -t =logs

Closing All Other Windows

Add the -a flag to close every window except the specified target:

$ tmux kill-window -a -t :1

Running tmux kill-window -a without a target flag keeps the active window and closes all other windows in the current session.

Pane, Window, and Session Comparisons

Operations in tmux target different levels of the component hierarchy:

  • Pane scope: Using Ctrl+b x or tmux kill-pane targets individual terminal splits. Ctrl+b x is pane scope and may close the window if it is the only pane in that window. For split management details, see how to close a tmux pane.
  • Window scope: Running tmux kill-window destroys every pane in that window immediately.
  • Session scope: Running tmux kill-session removes the entire session container and all windows inside it. For broader cleanup, see how to kill a tmux session.

Confirmation Bypass

To skip the prompt when using keyboard shortcuts, bind kill-window in ~/.tmux.conf:

bind-key & kill-window
by Alvin