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
tmux respawn-window [-k] [-c start-directory] [-e environment] [-t target-window] [shell-command [argument ...]]Options
| Flag | Description |
|---|---|
| -k | Kill the existing command first if it is still running |
| -c start-directory | Set the working directory |
| -t target-window | Window to respawn |
Examples
Restart the window's command
tmux respawn-window -k 'npm run dev'Respawn window 2 with its default command
tmux respawnw -t 2In .tmux.conf: keep windows and panes open after their program exits, so they can be respawned.
set -g remain-on-exit onStop whatever runs in the server window and start the dev server there instead.
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