My current workflow is:

  1. CTRL+SHIFT+T to launch a new terminal window. That starts a new zsh terminal.
  2. Type tmux to start tmux.

How can I have tmux load by default with a new terminal window?


There are at least two ways:

  1. Write something like

    if [ "$TMUX" = "" ]; then tmux; fi

    at the beginning of ~/.zshrc. Note the conditional test to a possible loop when tmux spawns its own zsh.

  2. Modify terminal launching command to something like

    xterm -e tmux

I prefer the second way, because sometimes I need to launch a terminal without tmux (for example when I need to reconnect to an existing session).

  • 2
    Or have different shortcuts for xterm -e tmux and plain xterm. – Nikolai N Fetissov Jun 21 '12 at 13:37
  • Yes, actually I meant it under "I prefer the second way" =) – rush Jun 21 '12 at 13:39
  • 1
    Executing tmux at the end of .zshrc will cause an endless loop of zsh starting tmux starting zsh starting tmux ... – Thor Jun 21 '12 at 14:56
  • How would one go about "modifying terminal launching command"? – eoinoc Jun 22 '12 at 9:04
  • @eoinoc it depends on your environment. For example, I'm using awesome wm, therefore I just need to modify string in my config file. In kde you need to edit hotkeys. And so on. – rush Jun 22 '12 at 9:11

There is actually a default plugin tmux for oh_my_zsh.

Add it to your plugins list then set ZSH_TMUX_AUTOSTART=true in your .zshrc

For more reference, go here


add it to your .zshrc

if [ -z "$TMUX" ]
    tmux attach -t TMUX || tmux new -s TMUX

then tmux will automatically connect to a session called TMUX when you launch your terminal.


Be careful with the echo tmux >> ~/.zshrc solution though, I remember that simply throwing a bash in a .cshrc file caused me trouble over SSH.

IIRC the problem occurred with non-interactive shells, so you should test for that.

case $- in *i*)
  if [ -z "$TMUX" ]; then exec tmux; fi;;
  • You're missing a space between " and ]. – n.st Apr 9 '14 at 1:17

Add "tmux" to your .zshrc file, which gets executed every time you start zsh. The quick way:

echo tmux >> ~/.zshrc
  • 1
    The thing with this, is that it starts a new session in every new instance and it bloats tmux with sessions that you've never exited (also tmux will complain about it). Not a good solution. – Eksapsy May 12 '19 at 18:16

Add this in your ~/.zshrc:

if [ -z $TMUX ]; then; tmux; fi

My compromise is to automatically start tmux if no sessions are running.

This way, only the first terminal window starts tmux. A following windows do not start tmux and you can decide to attach to a session or to not use tmux at all there.

To do so add the following at the beginning of ~/.zshrc:

if [[ ! $(tmux list-sessions) ]]; then 

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.