How to start tmux with attach if a session exists – Unix & Linux Stack Exchange

The answer is much simpler. Just put this in your ~/.tmux.conf file: # if run as “tmux attach”, create a session if one does not already exist new-session -n $HOST If you run tmux attach and there is a session, then it will attach to that session (whether it’s already attached or not). If there is not a session already then it will create one for you.

Source: How to start tmux with attach if a session exists – Unix & Linux Stack Exchange