I have two tmux sessions (0 and 1), each with a set of windows. When I run tmux a, I attach to one of the two sessions, usually 1 but sometimes 0. I always want to attach to 0 if I don't specify a target-session.

I've been looking through the manpage and have found the following:

tmux a -t 0 - Specify session 0 explicitly. I'd rather set 0 as the default session and avoid specifying an argument.

If a session is omitted, the current session is used if available; if no current session is available, the most recently used is chosen.

There is no current session (because there are no clients attached yet), and the "most recently used" does not seem to apply: I can detach from session 0 but when I reattach I end up on session 1. This seems to be time-sensitive; if I detach and reattach very quickly, I return to session 0, but if I wait even 1 second, I attach to session 1.

Of course, I can create a shell alias for tmux a -t 0 and use that if there's no way to set a default attach session. I could also swap the windows between sessions so that the ones I want are in session 1 instead of 0. Both of these feel like workarounds that I hoped would be unnecessary.

I am running tmux 1.3-2+squeeze1.

1 Answer 1


It is time sensitive.

From the man page:

The target-session rules for attach-session are slightly adjusted: if tmux needs to select the most recently used session, it will prefer the most recently used unattached session.

Your shell alias is the way to go for this, it is not a workaround, but the way Unix/Linux works. Small tools to do small things to produce great results.

  • "if tmux needs to select the most recently used session, it will prefer the most recently used unattached session", but it still prefers session 1, even though neither one is attached and I detached from session 0 just moments ago. Must be a bug, if I am correctly understanding the behaviour. For reference, I have used an alias.
    – mrb
    Commented Nov 5, 2012 at 12:57
  • I did read that from your comments, that you were finding this. I assume that you confirmed your connections via session-list to know for sure and checked the access times tot he sockets. You are aware though that you are running an older version of TMux and so this could have be corrected. I run version 1.6, yours is 1.3.
    – vgoff
    Commented Nov 5, 2012 at 13:00

You must log in to answer this question.

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