Skip to main content

Run a Second tmux Server with Its Own Config

You want to try a different tmux.conf (a new prefix, a different theme, a plugin you are not sure about) without disturbing the sessions you already have running.

The trick is that -f (alternate config) is not enough on its own. You also need -L (alternate socket), which forces tmux to start a completely separate server.

tmux -L test -f ~/.config/tmux/experiment.conf new-session -s scratch

Your normal tmux keeps running untouched. A different socket means a different server, with its own sessions, options, key bindings, and plugins.

Why -f alone does not work

tmux reads its config once, when the server starts.

If a server is already running on the default socket, tmux -f other.conf does not start anything; it just attaches you to the server that is already there, and your config file is ignored. No error, no warning.

-L <name> gives tmux a socket name it has never seen, so it has to start a new server, and that new server reads the -f file on the way up.

Set up a test config

Put the experimental config somewhere separate from your real one:

mkdir -p ~/.config/tmux
cp ~/.tmux.conf ~/.config/tmux/experiment.conf

Then edit ~/.config/tmux/experiment.conf freely. Nothing in it can affect your main server.

Every command needs the flag

This is the part that trips people up. tmux ls talks to the default server, not your test one:

tmux ls # your normal sessions
tmux -L test ls # the test server's sessions
tmux -L test attach # attach to the test server

Make it an alias while you are experimenting:

alias tmt='tmux -L test -f ~/.config/tmux/experiment.conf'

Now tmt new-session, tmt ls, and tmt attach all hit the test server.

Launching from inside your main tmux

tmux refuses to nest by default, so running the command from inside an existing session gives you:

sessions should be nested with care, unset $TMUX to force

Two options:

  • Open a plain terminal window and run it there. Cleanest.
  • Unset the marker if you want it in a pane anyway:
TMUX= tmux -L test -f ~/.config/tmux/experiment.conf new-session

If you do nest, give the test config a different prefix so your keystrokes do not get swallowed by the outer server:

set -g prefix C-b

With C-a outside and C-b inside, each server only sees the keys meant for it.

Where the sockets live

Sockets go in /tmp/tmux-$UID/ by default, or under $TMUX_TMPDIR if you have set it:

ls /tmp/tmux-$(id -u)/

You will see default plus any named sockets you have created. A socket file can linger after its server exits; tmux -L test ls answering no server running means it is dead regardless of the file being there.

-S sets a full socket path instead and overrides -L:

tmux -S /tmp/my-socket new-session

Use -L for the everyday case. -S is for when you need the socket in a specific place: shared between users, or on a different filesystem.

Tear it down

tmux -L test kill-server

That kills only the test server. Your main sessions are untouched.

Isolate the plugins too

If the test config loads TPM, it will install plugins into the same ~/.tmux/plugins directory your main setup uses. That is usually harmless, but it does mean the two servers share plugin state and versions.

To keep them fully separate, point the test config at its own TPM install:

# Must come before the plugin list and the tpm run line.
set-environment -g TMUX_PLUGIN_MANAGER_PATH '~/.tmux-test/plugins/'

set -g @plugin 'tmux-plugins/tpm'
set -g @plugin 'tmux-plugins/tmux-sensible'

run '~/.tmux-test/plugins/tpm/tpm'

Then clone TPM into that location once:

git clone https://github.com/tmux-plugins/tpm ~/.tmux-test/plugins/tpm

Press prefix then I inside the test server to install into the isolated directory. Deleting ~/.tmux-test removes every trace of the experiment.

Other uses for a second server

Separate servers are not only for testing config:

  • A work server and a personal server, so tmux ls in each context shows only what belongs there.
  • Scripted or automated sessions on their own socket, so a stray tmux kill-server in a script cannot take down your interactive work.
  • Trying a tmux upgrade or a new plugin against a throwaway server before committing to it.

Quick reference

ActionCommand
Start a test servertmux -L test -f ~/.config/tmux/experiment.conf new-session
List its sessionstmux -L test ls
Attach to ittmux -L test attach
Launch from inside tmuxTMUX= tmux -L test ... new-session
Use an explicit socket pathtmux -S /tmp/my-socket new-session
See existing socketsls /tmp/tmux-$(id -u)/
Kill only the test servertmux -L test kill-server