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

๐Ÿ“š Shared input helpers

MethodDescription
nameThe slug/name for the worktree (e.g. 'feature-x')

Hook State Helpers

๐Ÿ“š Shared hook state methods

MethodDescription
worktree_path!(path)Set the path where the worktree will be created

Output Helpers

๐Ÿ“š Shared output helpers

MethodDescription
output.worktree_pathGet the configured worktree path

Hook Exit Codes

Exit CodeBehavior
exit 0 (with path on stdout)Worktree created at the printed path
exit 1 / empty stdoutCreation fails

Important

output_and_exit for WorktreeCreate prints the bare path (not JSON). Do not emit JSON for this hook type.