WorktreeCreate hook payload change causes undefined worktrees on Windows

Status Closed — not planned
Reported on v2.1.98
Maintainer reply None cached
Activity 3 comments · opened Apr 10, 2026 · closed May 23, 2026

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: WorktreeCreate command hook

Observed behavior

  • Claude tries to create an agent worktree.
  • The legacy hook reads missing fields as undefined.
  • git worktree add still runs, which can register a real worktree at a path like <repo>/undefined on branch undefined.
  • The hook then crashes on process.stdout.write(worktreePath) because worktreePath is undefined.
  • 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 cwd and name, create the worktree, and print the absolute worktree path.
  • Stale sample hooks should not silently create undefined branches 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 cwd and name for WorktreeCreate.
  • Keep fallbacks for base_path, branch_name, and worktree_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

View original on GitHub ↗

This issue has 3 comments on GitHub. Read the full discussion on GitHub ↗