I'm using the grouped session feature of tmux to attach to a single session from multiple clients with different screen sizes. Therefore I automatically perform a tmux new-session -t <session_name> in my ~/.bashrc. However, I'm running tmux on a remote host that I ssh to, so therefore I often disconnect ssh without manually killing my grouped session. After a while, this leaves behind a long list of unused sessions that haven't been killed

Is it possible to have tmux kill my grouped session when its client detaches (so long as it isn't the last session)?

1 Answer 1


The answer is to set the destroy-unattached option for extra grouped sessions. From my ~/.bashrc:

# Connect/create tmux grouped session automatically.                                                                                                                                                                                                                                                                                                                        
if [ -z "$TMUX" ]; then                                                                                                                                                                                                                                                                                                                                                     
    tmux new-session -t 0 \; set-option destroy-unattached || tmux new-session -s 0                                                                                                                                                                                                                                                                                          
  • 2
    The part after the || won't get executed because the first part always succeeds. I think this is better: tmux new-session -d -s 0; tmux new-session -t 0 \; set-option destroy-unattached
    – patstew
    Commented Nov 15, 2017 at 19:02

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .