Tmux is a terminal multiplexer that lets you run multiple terminal sessions, windows, and panes—often while keeping long-running work available after you disconnect. Knowing how to close a tmux session is just as useful as knowing how to create one. You can end a single session, close it from inside or outside tmux, or stop the tmux server entirely. You can also detach without closing anything, which is important when you want your work to keep running. This guide explains each option, shows the commands to use, and helps you choose the right one without accidentally terminating other sessions.
Closing a Tmux Session: The Quick Answer
To close a particular tmux session from a regular terminal, run tmux kill-session with its session name:
tmux kill-session -t mysession
Replace mysession with the name or ID of the session you want to end. To close the current session from inside it, use the tmux command prompt: press your tmux prefix key, then type :kill-session and press Enter. The default prefix is Ctrl-b, so the full sequence is Ctrl-b, :, kill-session, Enter.
Closing a session ends the tmux environment and its running processes. If you only want to leave and reconnect later, detach instead: press Ctrl-b, then d.
Close a Session From Outside Tmux
Running tmux kill-session -t session_name from your normal shell is usually the clearest way to close a session. The -t option identifies the target session, so you can end the right one without entering it first. For example:
tmux kill-session -t project
This closes the session named project. Any applications running in that session—such as a shell, editor, or foreground command—may be terminated. Other tmux sessions remain open.
If you are unsure which sessions are active, list them first:
tmux ls
The output shows session names and IDs, along with information such as the number of windows. You might see entries like project: 2 windows or work: 1 windows. Use the name shown before the colon as the target. If a session name contains spaces or special characters, use the exact name carefully; choosing a simple name when creating sessions can make later commands easier.
You can also target a session by its numeric ID when one is shown. Session names are generally easier to recognize, but IDs can be helpful if names are duplicated or unclear. If tmux reports that the target session does not exist, run tmux ls again and check the spelling, capitalization, and current session list.
Close the Current Session From Inside Tmux
When you are already working inside the session you want to close, open tmux’s command prompt and run kill-session. With the default prefix, press Ctrl-b, release the keys, press the colon key, enter the command, and press Enter:
Ctrl-b → : → kill-session → Enter
This ends the current session. If you have changed your tmux prefix in your configuration file, use your configured prefix instead of Ctrl-b. The command prompt method is useful when you are certain you are in the correct session and do not want to switch to a separate shell to close it.
Alternatively, if a shell is running in the only pane of the only window, type exit or press Ctrl-d. When that shell ends, tmux may close the window and then the session if no other windows remain. This is a natural way to finish a session, but it is not always equivalent to explicitly killing it: other panes or windows may still be open, so the session can remain active.
Close a Session by Exiting Its Shell
Typing exit closes the current shell. Pressing Ctrl-d usually sends the same end-of-file signal from an interactive shell. If that shell is the only process keeping a pane open, the pane closes. If it is the last pane in the last window, the tmux session will generally end as well.
This approach works well when you are done with the shell and want to shut down the session naturally. It is less reliable as a way to close an entire session when you have split panes, multiple windows, or other running programs. For example, exiting one shell may close one pane while an editor or another shell keeps the rest of the session alive. To make sure the whole session ends, use kill-session.
Before exiting, save files and stop any commands that should not be interrupted. Closing a session can end foreground programs, and unsaved changes may be lost. Background processes may behave differently depending on how they were started, but you should not assume they will continue after their tmux session is closed.
Detach Instead of Closing the Session
Detaching is different from closing. It disconnects your terminal client while leaving the tmux session and its processes running. This is useful on a remote server, for a long-running build, or whenever you want to return to the same terminal later.
To detach with the default prefix, press Ctrl-b, then d. You should return to your normal shell, while the session remains available. Check that it is still running with tmux ls, then reconnect with:
tmux attach -t mysession
Substitute the session’s actual name for mysession. If you simply close your terminal window or disconnect from SSH, tmux sessions commonly remain active, but detaching explicitly is a more predictable habit. If your goal is to keep work running, do not use kill-session or kill-server; use detach instead.
Close One Session Without Affecting Others
A tmux server can manage several independent sessions. Killing one session does not normally close the others. This makes the targeted command the best choice when you want to clean up a finished task while preserving other work:
-
tmux ls— display active sessions. -
tmux kill-session -t project— close only the session namedproject. -
tmux ls— check which sessions remain.
For example, you could keep a session named monitoring running while closing a completed test-run session. Always include -t and the intended target when working from outside tmux. This makes your command explicit and helps avoid closing the wrong session.
Tmux also provides an option to close all sessions except the current one: tmux kill-session -a. Use it cautiously. It removes every other session managed by that tmux server, which may include sessions owned by different tasks or terminals. Review tmux ls before using it, especially on shared machines.
Close Every Tmux Session and Stop the Server
If you intend to shut down the entire tmux server, use:
tmux kill-server
This terminates the server and closes all sessions it manages, including sessions you may have detached. It is a much broader action than tmux kill-session -t mysession. Running it can stop work across several projects, so verify that no session contains anything you need before proceeding.
To review what will be affected, run tmux ls first. If no server is running, tmux may display a message such as no server running; that usually means there are no active sessions to close. Avoid using kill-server as a routine way to exit one session. A targeted kill-session command is safer when you only want to end a single workspace.
Close a Session From the Tmux Command Prompt
Tmux commands can be entered directly in the command prompt, which is convenient when you are already attached. Press the prefix key followed by a colon, then type a command. To close a named session, enter:
kill-session -t project
To close the current session, enter kill-session without a target. Press Enter to run the command. You can also run tmux commands from a shell with the tmux command at the beginning, as in tmux kill-session -t project. The shell form is useful for scripts and remote administration; the command-prompt form is handy during interactive work.
If the command prompt is unfamiliar, remember that it is separate from the shell prompt. The colon opens tmux’s command line, where you enter tmux commands without typing the leading tmux. A common mistake is to type tmux kill-session into the tmux command prompt; there, enter only kill-session and any options.
Common Problems When Closing Tmux Sessions
-
The session name is wrong: Run
tmux lsand copy the exact session name or ID. Names are case-sensitive. -
The session stays open after you type
exit: Another pane or window may still be active. Usetmux kill-session -t nameto close the entire session. - You closed the wrong thing: Closing a pane, window, session, or server has a different scope. Check your target before confirming a command.
-
Tmux says no server is running: There may be no active sessions, or the server may already have stopped. Run
tmux lsto confirm. -
You wanted to leave work running: Detach with
Ctrl-b, thend, rather than killing the session.
If a session appears to hang while closing, a process may be waiting for input or refusing to exit. You can inspect the session by attaching to it, save any important work, and stop the process normally. If you are certain the session can be terminated, use the targeted kill command. Be especially careful with forceful process termination, which can cause data loss or leave files in an incomplete state.
Useful Tmux Commands at a Glance
-
tmux ls— list active sessions. -
tmux attach -t name— reconnect to a session. -
tmux kill-session -t name— close one named session. -
tmux kill-session— close the current session when run from its tmux command prompt, or target the current session from an appropriate tmux context. -
tmux kill-session -a— close all sessions except the current one. -
tmux kill-server— stop the server and close all its sessions. -
Ctrl-b, thend— detach without ending the session.
The scope of each command matters. A pane is one terminal area, a window can contain one or more panes, a session can contain multiple windows, and the server can manage multiple sessions. Choose the narrowest action that matches what you want to close.
Conclusion
The simplest way to close a tmux session is tmux kill-session -t name, using the session’s name or ID. From inside the session, open the tmux command prompt and run kill-session. You can also exit a shell, though that only ends the session when no other panes or windows remain. If you want to keep your work running and reconnect later, detach with Ctrl-b, then d. Finally, reserve tmux kill-server for situations where you deliberately want to close every session. Checking tmux ls before acting helps ensure you close exactly what you intend.
Disclaimer: Articles are written by Humans, AI or Both. Verify Important information.