133

I have a pretty simple tmux session running with two open windows; one of them for local hacking and one of them for work.

What I'd like to do is to simply connect to the hacking window while leaving the work window open in another terminal. However, as soon as I connect to tmux, all commands are sent to both windows, so if I switch to another window, the same thing happens in the other terminal and vice-versa.

Is there a way for me to simply connect to each window separately?

1 Answer 1

181

The reason both clients switch windows at the same time is because they are both connected to the same session (the “current window” is an attribute of the session, not the client). What you can do is link one or more windows into multiple different sessions. Since each session has its own “current window”, you can then switch windows independently in each session.

The easiest way to use this feature is to use the “grouped sessions” feature of the new-session command:

$ tmux new-session -t 'original session name or number'

To see the sessions currently available:

$ tmux list-sessions

Each session in a group will automatically share the same set of windows: opening/linking (or closing/unlinking) a window in one session of the group automatically causes the same window to be linked (or unlinked) in all the other sessions of the group.

When you are done with your “extra” session, you can kill it with kill-session. The windows themselves will not be killed unless your session was the only one they were linked to. Alternatively, you can disconnect from your “extra” session like normal (Prefix d, or detach-client); if you do keep your “extra” session around (by simply detaching from it), you might want to give it a descriptive name (Prefix $, or rename-session) so that you easily identify it and reconnect to it later (you may also want to give the “original” session a name, too).


If you do not want to automatically share a dynamic set of windows, then you can use link-window (and unlink-window) to bring individual windows into (and out of) your own “personal” session; this offers non-automatic, and lower-level access to the same core functionality upon which “grouped sessions” are based (windows linked into multiple sessions).

4
  • 14
    Gread answer. Do you know how to prevent 2 open sessions from syncing their sizes? If I'm creating new session and the window is smaller, a lot of screen real estate in the original one is wasted.
    – defhlt
    Mar 23, 2013 at 11:25
  • 35
    I've found the answer to my Q: setw -g aggressive-resize on
    – defhlt
    Mar 23, 2013 at 12:35
  • 2
    This is supported as "rogue" mode in wemux.
    – blueyed
    Oct 14, 2015 at 11:27
  • When the panel splitted vertically if there is a panel tab bar, the window decreases the height of the panel bar @Chris Johnsen
    – alper
    Jul 21, 2020 at 2:13

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.