Skip to main content
Browse referenceAll guides
Back to Commands
Window ManagementPrefix + < then R

respawn-window

Short form: respawnw

Reuse a window to run a command, restarting it in place. Useful for windows whose command exited when remain-on-exit is on.

How respawn-window works

respawn-window restarts the program in a window whose program has exited. Normally a window closes when its program ends, but with the remain-on-exit option turned on, the window stays open as a dead window so you can read the output. respawn-window brings it back to life in the same place.

Without a command, tmux reruns the command the window was created or last respawned with. Give a new command to run something else. -c sets a new working directory and -e adds environment variables.

The default window menu (Prefix + <) has a Respawn entry that runs respawn-window -k for you.

Synopsis

bash
tmux respawn-window [-k] [-c start-directory] [-e environment] [-t target-window] [shell-command [argument ...]]

Options

FlagDescription
-kKill the existing command first if it is still running
-c start-directorySet the working directory
-t target-windowWindow to respawn

Examples

Restart the window's command

bash
tmux respawn-window -k 'npm run dev'

Respawn window 2 with its default command

bash
tmux respawnw -t 2

In .tmux.conf: keep windows and panes open after their program exits, so they can be respawned.

bash
set -g remain-on-exit on

Stop whatever runs in the server window and start the dev server there instead.

bash
tmux respawn-window -k -t api:server 'npm run dev'

Default Keybinding

Prefix + < then R (window menu: Respawn)

Default prefix is Ctrl+b

Common Mistakes

  • It fails with 'respawn window failed: window main:0 still active' if the program is still running. Add -k to stop it and restart.
  • -k stops the running program without asking. Unsaved work in that window is lost.
  • To restart just one pane in a split window, use respawn-pane instead.

Pro Tips

  • •Pair with set -g remain-on-exit on to inspect output before respawning
  • •Use -k to force-restart a still-running command