Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Hooks

Hooks let you run custom commands in response to worktree lifecycle events.

Configuration

Define hooks in .config/gwt.toml under [hooks.<event>]:

[hooks.post-create]
install = "npm ci"
setup = "cp .env.example .env"

[hooks.pre-merge]
lint = "npm run lint"
test = "cargo test"

[hooks.pre-remove]
cleanup = "rm -rf node_modules"

Each key under the event is a named command. Names are for identification only — the values are the shell commands that run.

Available events

EventWhen it firesBlocking
post-createAfter a worktree is createdYes
post-switchAfter switching to a worktreeYes
pre-removeBefore a worktree is removedYes
pre-mergeBefore merge verification startsYes
post-mergeAfter a successful mergeNo

Blocking events abort the operation if any hook command fails. For example, if a pre-merge hook fails, gwt merge stops before rebasing.

Non-blocking events log a warning on failure but continue the operation.

Built-in hook handlers

In addition to your custom commands, gwt’s internal plugins also respond to hook events:

PluginEventAction
Zellijpost-createCreates a tab for the new worktree
Zellijpre-removeCloses the worktree’s tab
Zellijpost-switchSwitches to the worktree’s tab
Gatewaypost-switchCleans up stale PID files
ClaudeVariousKeeps the AI agent in sync with worktree state

Custom hooks run alongside these built-in handlers.

Manually dispatching hooks

gwt hook post-create
gwt hook pre-merge

See hook command for details.