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)?


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                                                                                                                                                                                                                                                                                          
  • 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 Nov 15 '17 at 19:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.