Let's say I am using a tmux window with 4 panes (like the example in this question. Now I change some environment variable and I want the new value to be recognized in all 4 panes. Is there a simple way to respawn all 4 panes with one command?

I know that :respawn-pane -k works for any one pane, but it's tiresome to have to enter it 4 times. I also tried respawn-window, but that left me with a single new pane (it killed my 4-pane view).


  • That's an interesting idea. I seem to recall wondering if there was a tmux solution to propagating an environment variable change across open shells a few years ago, but I didn't find one at the time. Don't recall considering :respawn-pane though, so maybe the solution lies along that path. My solution ended up being a change from zsh to fish (for this and other reasons). fish has "universal variables" which take effect in all open shells when set/changed. May 13, 2021 at 17:40

2 Answers 2


If nothing else, it seems to be easily scriptable (although please see the comments for warnings on a better approach):

bash/zsh: for pane in $(tmux list-panes -a -F "#D"); do tmux respawn-pane -k -t $pane; done

fish: for pane in (tmux list-panes -a -F "#D"); tmux respawn-pane -k -t $pane; end

As I'm sure you are aware, this should be used with caution since it will end any and all processes that are running in any of the other panes.

  • Thanks, that's a good idea. I'm going to leave the question open a little longer (i.e., not accept the answer yet) to see if someone comes up with a way to do it natively in tmux. I appreciate your suggestion.
    – John
    May 16, 2021 at 18:15
  • 1
    Careful with using a for loop with the output of all. Would recommend including #{pane_active} in your format, then sort on that column. This way the last pane to be closed will be the active one you are on. If you dont do this the for loop will work though every entry in the list provided from the output of tmux list-panes -a -F "#D", and if your script is in the middle it will stop before the rest of the entries are complete.
    – Dave
    Aug 4, 2022 at 14:28
  • @Dave Great point! I'm probably not going to fix the answer itself right now, but let your comment serve as note to future readers. If a future reader needs assistance with the modification, please feel free to ask in a comment here tagging me or Dave. Aug 4, 2022 at 17:59

I'm not sure why I didn't mention this when the question was originally asked, but as an orthogonal answer, the use case in this question is one of the main reason why I switched to the fish shell a few years ago.

Fish has a feature called "universal variables" which get updated/changed in all running shell instances (and persisted). For example:

# Long form
set --universal --export some_sock /run/myapp.sock
# Short form
set -Ux some_sock /run/myapp.sock

All of my tmux panes that are running fish will have the new variable and/or updated value.

You must log in to answer this question.

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