Git Hook Integration
Automatically run wt setup on new worktrees using the post-checkout git hook.
Overview
The post-checkout hook triggers wt setup automatically whenever git worktree add creates a new worktree. It detects new worktrees by checking whether the previous HEAD is the null SHA (0000...).
Install
Or let the installer handle it interactively during ./install.sh.
Behaviour
- The hook exits
0even ifwtis not on PATH — it prints a warning and lets the checkout succeed. - It never blocks a git operation.
- A
.wt-setup-donemarker file prevents re-running setup if both the git hook and the Claude Code hook fire for the same worktree.
How It Works
The hook checks $3 (the branch checkout flag) and $1 (the previous HEAD). When previous HEAD is all zeros, git is performing an initial checkout into a new worktree:
Notes
The git hook approach works with any tool that calls git worktree add — including IDE integrations, scripts, and other CLIs. If you primarily use wt add, the hook is redundant but harmless.
For Claude Code specifically, the Claude Code hooks provide richer integration.