Clearing tmux sessions can mean closing one session, removing several old sessions, or shutting down every session managed by a tmux server. The right command depends on what you want to keep. To close one session, use tmux kill-session; to close all sessions, use tmux kill-server. Before running either command, check which sessions are active so you do not accidentally end work you still need.
What Does It Mean to Clear a Tmux Session?
A tmux session is a persistent workspace that can contain one or more windows and panes. It may continue running after you detach from it or close your terminal. That persistence is useful for long-running tasks, but it can also leave behind sessions you no longer need.
People use “clear tmux sessions” to describe a few different actions:
- Close one session: End a specific workspace and its processes.
- Close several sessions: Remove selected workspaces or all sessions except one.
- Shut down tmux completely: Stop the tmux server and terminate every session it manages.
- Clear the terminal display: Remove visible text without closing the session or its processes.
These actions are not interchangeable. In particular, clearing the terminal screen does not clear or end a tmux session. The sections below show how to identify sessions and choose the safest command for your goal.
List Tmux Sessions Before Clearing Them
Start by listing the sessions running under the current tmux server. From a regular shell, enter:
tmux ls
This is a shortcut for tmux list-sessions. The output typically includes a session name, how many windows it contains, and whether it is attached. For example:
work: 2 windows (created Fri Nov 28 09:30:00 2026) (attached)
backup: 1 windows (created Fri Nov 28 08:10:00 2026)
Here, work and backup are session names. A session marked attached is currently connected to a terminal; an unattached session is still running but has no terminal connected to it. Both can be ended with the commands in this guide.
You can also list sessions while inside tmux. Press your prefix key—usually Ctrl-b—then press s to open the session chooser. Select a session to switch to it, or use the command prompt for a more direct cleanup. Checking the list first helps you confirm the exact target and avoid terminating the wrong workspace.
How to Clear One Tmux Session
To close a specific tmux session from a regular shell, run:
tmux kill-session -t session_name
Replace session_name with the name shown by tmux ls. For example, to close a session named backup, use:
tmux kill-session -t backup
The command ends the target session, including its windows and panes. Processes running inside those panes may receive a hangup signal or be terminated, so save files and stop important jobs first. Other sessions managed by the same tmux server remain available.
You can target a session by its name or, in many cases, by its numeric index. Names are usually easier to recognize and less likely to point to the wrong workspace. If your target is called 0, use a name or inspect the session list carefully so you know which session the target refers to.
If you are already inside the session you want to close, press Ctrl-b, then : to open tmux’s command prompt. Enter:
kill-session
This closes the current session. You can also enter kill-session -t session_name at the tmux command prompt to target a different session. If it was the last session on that server, the tmux server exits as well.
How to Clear All Tmux Sessions
To stop the tmux server and close every session it manages, run:
tmux kill-server
This is the most complete way to clear tmux sessions. It ends all sessions on the server, including sessions you are not currently attached to. Any processes running in their panes may be interrupted, so use this command only when you are sure that none of the sessions contain work you need.
Run tmux kill-server from a shell, or enter kill-server at the tmux command prompt after pressing Ctrl-b and :. If you have multiple tmux servers started with different socket names or configurations, a command may apply only to the server it connects to. Check your setup if sessions remain after shutting down a server.
After stopping the server, you can confirm that its sessions are gone by running:
tmux ls
If no server is running, tmux may report that it cannot connect to the server. That message usually means there are no sessions available through the default socket, rather than indicating that cleanup failed.
How to Kill All Tmux Sessions Except One
If you want to clear old sessions but keep one active workspace, use the -a option with kill-session and specify the session to preserve:
tmux kill-session -a -t session_to_keep
For example, to keep work and close every other session on the server, run:
tmux kill-session -a -t work
Take care to identify the session you want to retain before running this command. The target after -t is the session that remains; the other sessions are killed. If you are uncertain, list sessions first, copy the desired name, and verify the command before pressing Enter.
To keep your current session, you can usually use a current-session target from inside tmux, but specifying the session name explicitly is clearer and safer—especially when running cleanup from a script or a separate shell.
Close a Window or Pane Instead of a Session
Sometimes you do not need to clear the whole tmux session. If only one window or pane is no longer useful, close that part of the workspace and leave the rest running. In tmux, press Ctrl-b, then:
-
&: Close the current window. Tmux asks you to confirm. -
x: Close the current pane. Tmux asks you to confirm.
You can also use tmux commands. To kill a particular window, use kill-window with a target. To close a pane, use kill-pane. For example:
tmux kill-window -t session_name:window_index
tmux kill-pane -t session_name:window_index.pane_index
These commands affect the specified window or pane rather than ending every window in the session. Check the target format and current layout before using an index, since window and pane indexes can change as you rearrange or close parts of a workspace.
Clear the Tmux Screen Without Ending a Session
If by “clear tmux” you mean remove old text from the visible terminal, do not use kill-session or kill-server. Those commands terminate work rather than simply clearing the display. Inside a pane, run:
clear
You can also press Ctrl-l in many shells to clear the visible screen. This does not close the pane, window, or session, and it does not stop commands running in the background. The terminal’s scrollback may still contain earlier output, depending on your terminal emulator and settings.
There is also a difference between clearing a screen and restarting a shell. If you want a fresh command prompt but intend to keep the tmux session, start a new shell in a pane or window rather than killing the entire session. Choose the smallest cleanup action that solves the problem.
Common Tmux Session Cleanup Problems
If a command does not work as expected, these checks can help you find the cause:
-
“No server running” or a connection error: There may be no tmux server at the default socket, or the server may already have stopped. Run
tmux lsto check. -
“Session not found”: Check the exact session name with
tmux ls. Names are case-sensitive, and an outdated name will not match a renamed or closed session. - The session still appears: Confirm that you connected to the same tmux server or socket used to create it. Separate sockets can hold separate session lists.
-
A command closed too much: Use
tmux lsbefore cleanup and preferkill-session -t namewhen you only need to remove one session. - Important work stopped: Killing a session can interrupt jobs running in its panes. Save work and check long-running commands before closing it.
When automating tmux cleanup, avoid relying on broad commands unless that is explicitly the goal. A script that runs tmux kill-server can terminate unrelated sessions belonging to the same server. Targeting a specific session is generally safer, and checking the session list before and after cleanup makes scripts easier to troubleshoot.
Which Tmux Cleanup Command Should You Use?
Choose the command based on what you want to remove:
- Close one named session:
tmux kill-session -t session_name - Close every session except one:
tmux kill-session -a -t session_to_keep - Close every session on the server:
tmux kill-server - Close the current window or pane: use
Ctrl-bfollowed by&orx - Clear visible terminal text without closing anything: run
clearor pressCtrl-l
For most routine cleanup, begin with tmux ls and then kill only the session you have identified. Use kill-server only when you intend to end all tmux sessions managed by that server.
Conclusion
To clear tmux sessions, first decide whether you need to end one session, preserve a session while removing others, shut down the entire tmux server, or simply clear the terminal display. Use tmux ls to review active sessions, tmux kill-session -t session_name to close one, and tmux kill-server to close them all. If you only want a cleaner screen, use clear instead. Checking your target and saving important work before cleanup helps prevent accidental loss of running tasks.
Disclaimer: Articles are written by Humans, AI or Both. Verify Important information.