Skip to main content
Back to Commands
MiscellaneousN/A (configuration command)

set-hook

Set (or unset) a hook that runs a tmux command automatically when an event occurs, such as a session being created or a window being linked. Flags mirror set-option.

Synopsis

bash
tmux set-hook [-agpRuw] [-t target-pane] hook-name [command]

Options

FlagDescription
-gSet a global hook
-aAppend so the hook runs multiple commands
-uUnset the hook
-RRun the hook immediately
-t target-paneTarget pane/session for the hook

Examples

Auto-apply the tiled layout to new windows

bash
tmux set-hook -g after-new-window 'select-layout tiled'

Run a script whenever a session is created

bash
tmux set-hook -g session-created 'run-shell ~/on-session.sh'

Default Keybinding

N/A (configuration command)

Default prefix is Ctrl+b

Pro Tips

  • List active hooks with show-hooks; many options also fire a *-changed hook
  • Use -a to attach several commands to one event