tmux can broadcast commands to all panes, but the default behavior is a bit of a trap.

The break-pane command is the key, but it’s not about breaking anything. It’s about breaking out of the current pane’s input context.

Here’s how you can send a command to every pane in your current tmux session.

First, let’s set up a few panes to play with. This will give us a concrete example to work with.

tmux new-session -d -s broadcast_demo
tmux split-window -h
tmux split-window -v
tmux select-pane -t 0
tmux split-window -v
tmux select-pane -t 0

This creates a session named broadcast_demo with four panes: one large pane on the left, and three smaller panes on the right.

Now, let’s get into the broadcast command itself. The magic happens with tmux send-keys. You can send keys to a specific pane, a window, or even the entire session. To broadcast, we’ll target the root of the session.

The command structure looks like this:

tmux send-keys -t <target-session>:<target-window>.<target-pane> <keys>

For broadcasting to all panes in the current session and window, we can use a wildcard or simply omit the pane number. A common trick is to target a non-existent pane, which tmux interprets as "all panes in this window."

Let’s try sending a simple echo command to all panes.

First, make sure you’re inside your broadcast_demo session:

tmux attach-session -t broadcast_demo

Now, execute the broadcast command. We’ll target pane 99 (which doesn’t exist) to signal "all panes."

tmux send-keys -t 99 'echo "Hello from broadcast!"' C-m

The C-m is crucial – it’s the carriage return, which is equivalent to pressing Enter. Without it, the command would just be typed into each pane, not executed.

You should now see "Hello from broadcast!" appear in every single pane.

What if you want to broadcast to panes in different windows within the same session? This is where it gets a bit more involved. send-keys by default operates within a single window.

To broadcast across windows, you’ll need to iterate through them. You can get a list of windows using tmux list-windows -F '#{window_index}'.

Let’s demonstrate. First, create another window and split it:

tmux new-window -t broadcast_demo:1
tmux split-window -h -t broadcast_demo:1

Now, to send a command to all panes in all windows of the broadcast_demo session, you’d script it:

for win_idx in $(tmux list-windows -t broadcast_demo -F '#{window_index}'); do
  tmux send-keys -t broadcast_demo:$win_idx.99 'echo "Broadcasting across windows!"' C-m
done

This loop fetches each window index, and then send-keys targets pane 99 within that specific window, effectively broadcasting to all panes in broadcast_demo:$win_idx.

A more advanced use case is sending commands that require interactive input or are part of a larger script. For instance, you might want to update a package on all your running servers, each in its own tmux pane.

Consider this scenario: you have several panes, each running a different SSH session. You want to run sudo apt update on all of them simultaneously.

# Assuming you have panes already set up with SSH sessions
# For demonstration, let's just send the command
tmux send-keys -t 0 'sudo apt update' C-m
tmux send-keys -t 1 'sudo apt update' C-m
tmux send-keys -t 2 'sudo apt update' C-m
tmux send-keys -t 3 'sudo apt update' C-m

To do this as a broadcast, you’d use the same 99 pane trick:

tmux send-keys -t 99 'sudo apt update' C-m

If your sudo command requires a password, this broadcast will only work if the password prompt is consistently handled or if you’ve configured passwordless sudo for that command. For interactive passwords, broadcasting becomes problematic without further scripting.

A common pitfall is forgetting the C-m (Enter key). Without it, the command is typed, but not executed, leaving you with lines of half-typed commands in each pane. Another is targeting a specific pane number when you intend to broadcast. send-keys -t 0 will only send to pane 0, not all panes.

The 99 pane target is a convention; any pane number that doesn’t exist within the window will trigger the broadcast to all panes in that window. This is a documented, albeit slightly quirky, feature of send-keys.

The real power comes when you combine this with tmux’s scripting capabilities or external shell scripts. You can dynamically generate commands based on session state or external data and broadcast them to your entire tmux environment.

The next hurdle is often synchronizing input across panes when you don’t want to broadcast. This is achieved with set-window-option synchronize-panes on, which is a different, though related, tmux feature.

Want structured learning?

Take the full Tmux course →