WorktreeCreate hook payload change causes undefined worktrees on Windows
Summary
Claude Code 2.1.98 appears to send a different WorktreeCreate hook payload than the older sample hook implementation expects. On Windows, a legacy hook that reads worktree_path / branch_name / base_path can end up creating a real worktree named undefined and then throwing when it tries to write undefined to stdout.
The failure I saw was:
WorktreeCreate hook failed: node "C:/Users/panit/.claude/hooks/worktree-create.js": Failed to create worktree: The "chunk" argument must be of type string or an instance of Buffer, TypedArray, or DataView. Received undefined
Environment
- Claude Code: 2.1.98
- OS: Windows
- Hook type:
WorktreeCreatecommand hook
Observed behavior
- Claude tries to create an agent worktree.
- The legacy hook reads missing fields as
undefined. git worktree addstill runs, which can register a real worktree at a path like<repo>/undefinedon branchundefined.- The hook then crashes on
process.stdout.write(worktreePath)becauseworktreePathisundefined. - Claude falls back to sequential execution with no worktrees.
Expected behavior
- The hook contract should be clear and stable, or the sample hook should be updated for the current payload.
- A current-format hook should be able to read
cwdandname, create the worktree, and print the absolute worktree path. - Stale sample hooks should not silently create
undefinedbranches or worktree directories.
Likely root cause
I verified that a working hook for 2.1.98 needs to treat the current payload as cwd + name for create, with legacy fallbacks for older field names.
Minimal fix that worked locally
- Read
cwdandnameforWorktreeCreate. - Keep fallbacks for
base_path,branch_name, andworktree_path. - Resolve repo root with
git rev-parse --show-toplevel. - Create the worktree at
<repo>/.claude/worktrees/<name>. - If the branch already exists, run
git worktree add <path> <branch>. - Otherwise, run
git worktree add <path> -b <branch>. - Print only the absolute created path to stdout.
Repro notes
The legacy hook shape that broke looked like this:
const worktreePath = data.worktree_path;
const branchName = data.branch_name;
const basePath = data.base_path;
execSync(`git worktree add "${worktreePath}" -b "${branchName}"`, { cwd: basePath });
process.stdout.write(worktreePath);
Thanks � happy to provide the full working replacement script if useful.
Working replacement hooks
Public gist: https://gist.github.com/pithpusher/8596767975959b8ceac96574b7dd4285
This issue has 3 comments on GitHub. Read the full discussion on GitHub ↗