WorktreeCreate API
July 14, 2026 ยท View on GitHub
Available when inheriting from ClaudeHooks::WorktreeCreate:
Runs when Claude Code is about to create a git worktree. Special contract: the hook must print the worktree path as the last non-empty line of stdout and exit 0. An empty or missing path is treated as failure.
Input Helpers
| Method | Description |
|---|---|
name | The slug/name for the worktree (e.g. 'feature-x') |
Hook State Helpers
๐ Shared hook state methods
| Method | Description |
|---|---|
worktree_path!(path) | Set the path where the worktree will be created |
Output Helpers
| Method | Description |
|---|---|
output.worktree_path | Get the configured worktree path |
Hook Exit Codes
| Exit Code | Behavior |
|---|---|
exit 0 (with path on stdout) | Worktree created at the printed path |
exit 1 / empty stdout | Creation fails |
Important
output_and_exit for WorktreeCreate prints the bare path (not JSON). Do not emit JSON for this hook type.