Your Search Bar For Shrewd Tips

How To Close Tmux Window


Knowing how to close a tmux window makes it easier to keep terminal sessions organized and avoid leaving unused shells running. You can close the current window with a keyboard shortcut, use the tmux command prompt, or target a specific window from the command line. The right method depends on whether you want to close one window, remove a single pane, or leave a session running in the background.

This guide explains each option, what happens to processes in a closed window, and how to avoid accidentally ending the wrong part of your tmux session. The commands apply to the default tmux key bindings; if your configuration changes the prefix key, use your configured prefix instead of the default Ctrl-b.

What Is a Tmux Window?

A tmux session can contain multiple windows, and each window can contain one or more panes. Think of a session as a workspace, a window as a terminal tab, and a pane as a section of a window. Closing a window removes that window and all of its panes, while closing a pane removes only one section of the current window.

This distinction matters because the common shortcut for closing a pane is different from the shortcut for closing a window. Before using a close command, check whether you intend to remove the entire tmux window or just one pane inside it.

How to Close the Current Tmux Window with a Shortcut

The default keyboard shortcut for closing the current tmux window is Ctrl-b, followed by &. Press the keys in sequence: hold Ctrl and press b, release them, then press the ampersand key. On most keyboards, & is entered with Shift-7.

Tmux will ask you to confirm that you want to kill the window. Press y to confirm or n to cancel. Confirmation helps prevent accidental closures, particularly when a window contains several panes or long-running work.

  • Press Ctrl-b to send the default tmux prefix.
  • Press & to request that the current window be closed.
  • Press y to confirm, or n to keep the window open.

If you press Ctrl-b and then x, tmux asks whether to close the current pane instead. That is not the same as closing the window: the other panes in the window remain open. If you want to close the whole window, use &, not x.

Close a Tmux Window from the Command Prompt

You can also close the current window using tmux’s command prompt. Press Ctrl-b, then : to open the prompt at the bottom of the terminal. Enter the following command and press Enter:

kill-window

The command closes the current window and its panes. Unlike the Ctrl-b, & shortcut, a command entered this way generally does not ask for a separate confirmation. Check that the correct window is active before running it.

You can include the command prefix in a shell command outside the tmux prompt as well:

tmux kill-window

When run from a terminal connected to a tmux server, this closes the current window in the relevant session. If you have multiple sessions or want to be certain which window is affected, specify a target rather than relying on the current context.

Close a Specific Tmux Window by Target

Tmux lets you target a window by session name and window index. This is useful when you want to close a window without first switching to it. For example, to close window 2 in a session named work, run:

tmux kill-window -t work:2

The target format session:window identifies the session and the window within it. Replace work with your session name and 2 with the appropriate window index. Window indexes are often numbered from zero, but they can vary depending on your tmux configuration.

To inspect your sessions and windows before closing one, use:

tmux list-windows -a

This displays windows across available sessions. You can also run tmux list-windows from inside a session to see its windows. Review the listed session, index, and window name, then use the matching target with kill-window.

For example, if the output shows a window named logs at index 1 in the work session, you can target it with work:1. Avoid assuming that a window’s displayed name is its index; the target syntax normally uses the session and window index.

Close a Window by Exiting Its Shell

If a tmux pane is running a regular shell, you can type exit and press Enter to end that shell. Pressing Ctrl-d may also send an end-of-file signal, which commonly exits an interactive shell. When the shell is the pane’s only process, tmux usually closes that pane after the process ends.

If the pane is the only pane in its window, closing it also closes the window. If the window contains other panes, only the pane running the shell you exited closes; the rest of the window stays open. The outcome therefore depends on the number of panes and the processes running in them.

This method is convenient when you are finished with the shell itself, but it is not always the best way to close a window. A pane may be running a program instead of a shell, and that program may not respond to exit or Ctrl-d. In that case, use the window shortcut or the kill-window command.

Close a Window Without Closing the Session

Closing one window does not normally close the entire tmux session if other windows remain in that session. Tmux removes the selected window and leaves the remaining windows available. You can switch to another window before closing the current one or continue working in another window afterward.

Be careful when closing the last window in a session. A session with no windows cannot continue as a usable workspace, so tmux normally destroys it. If your goal is to keep the session available while you step away, detach instead of killing a window or exiting its only shell.

To detach from a session with the default key bindings, press Ctrl-b, then d. Detaching leaves the session running in the background; it does not close its windows or terminate their processes. Later, you can reconnect with tmux attach, or specify a session if you have more than one.

Window Closure vs. Pane Closure and Detaching

These actions can sound similar, but they have different effects. Choose the one that matches what you want to happen:

  • Close a window: Press Ctrl-b, then &, or run kill-window. The window and all of its panes are removed.
  • Close a pane: Press Ctrl-b, then x, or use kill-pane. Other panes in the window remain open.
  • Detach from a session: Press Ctrl-b, then d. The session stays alive and can be attached again later.
  • Exit a shell: Type exit or try Ctrl-d. This ends the shell in the current pane and may close the window if it was the only pane.

If you are unsure which action you need, detaching is usually the safer option when you want to preserve your work. Closing a window can terminate programs in every pane it contains, whereas detaching leaves them running.

What Happens to Programs in a Closed Window?

When you kill a tmux window, tmux closes all panes belonging to that window. Programs running in those panes may be terminated, including shells, editors, build commands, and monitoring tools. Unsaved work in an interactive program can be lost, so save files and stop important jobs before closing the window.

Closing a window is different from detaching. A detached session remains active, so its programs can continue running even when you close the terminal emulator. Killing a window, by contrast, removes the tmux environment those pane processes are running in. Do not use kill-window as a substitute for detaching if you need those processes to keep running.

If you use tmux’s remain-on-exit setting, a pane may stay visible after its process ends, depending on your configuration. That can change what you see after exiting a shell, but it does not make a killed window equivalent to a detached session.

Common Problems When Closing Tmux Windows

If Ctrl-b does not work, your tmux prefix may have been changed in your configuration. Check your tmux settings for a prefix option, or use the command prompt if you can access it. A terminal emulator or operating system shortcut can also intercept key combinations before tmux receives them.

If the wrong pane closes, you may have pressed x instead of &. Remember that Ctrl-b, then x targets a pane, while Ctrl-b, then & targets a window. Confirm the prompt and the active window before approving the action.

If a command reports that a target cannot be found, verify the session name and window index with tmux list-windows -a. The window may belong to a different session, or its index may not be what you expected. Use the full target, such as work:1, to reduce ambiguity.

Can You Reopen a Closed Tmux Window?

Tmux does not provide a built-in undo command that restores a killed window with its former panes and running programs. You can create a replacement window with Ctrl-b, then c, or run new-window from the tmux command prompt. However, the new window will not automatically restore the old window’s processes or unsaved work.

Some users install session-management tools that can save and restore parts of a tmux layout. These tools may help recreate windows and panes, but they cannot guarantee recovery of every running program or unsaved file. Treat closing a window as a destructive action and save important work first.

Conclusion

The quickest way to close a tmux window is to press Ctrl-b, then &, and confirm with y. You can also run kill-window from the tmux command prompt or target a specific window with a command such as tmux kill-window -t work:2. Use Ctrl-b, then x to close only a pane, and Ctrl-b, then d to detach without stopping your session. Knowing the difference helps you close the right part of tmux while keeping the work you want to preserve.


Disclaimer: Articles are written by Humans, AI or Both. Verify Important information.

Shrewdnia

Shrewdnia

Shrewdnia is a destination for curious minds seeking clarity, knowledge, and informed perspectives. Through insightful articles and practical guides our passionate team explores a wide range of topics designed to help readers understand the world around them, make smarter decisions, and stay informed in an ever-changing landscape.


💡 Every question sparks discovery, and every perspective enriches the conversation. Share your thoughts and insights in the comments 👇

Back to blog

Leave a comment

JOIN THE SHREWDNIA COMMUNITY FORUM

What do you think?

Have an opinion, experience, or question about this topic? Join the Shrewdnia Forum and share your thoughts with other readers.

Join the Forum →