worktrunk icon indicating copy to clipboard operation
worktrunk copied to clipboard

Claude Code 2.1.325 refuses a WorktreeCreate path through a symlink inside the project; the wt hook prints the unresolved path

Open worktrunk-bot opened this issue 2 weeks ago • 1 comments

Claude Code 2.1.325 changed EnterWorktree to refuse a WorktreeCreate hook answer whose path goes through a symlink inside the project (CHANGELOG, 2.1.325: "Changed EnterWorktree to refuse a WorktreeCreate hook path that goes through a symlink inside the project; have the hook print the real path"). Worktrunk's hook prints the path from wt switch --format=json as-is (handle_claude_hook), and for a newly created worktree that path is the templated one, not the resolved one.

So a user whose worktree-path places worktrees inside the repository through a symlinked directory (for example {{ repo_path }}/.worktrees/... with .worktrees linked elsewhere) would have EnterWorktree / /wt-switch-create refuse the worktree that wt just created. Users with the default sibling layout, or no symlink inside the project, are unaffected.

Reproduced with a debug build at b0fd63dd1927100c83a8326ae21f0d3f4304c971, paths shortened (I haven't run Claude Code 2.1.325 itself here, so the refusal side is from the changelog only):

$ ln -s /tmp/real .worktrees    # inside the repo
$ # worktree-path = "{{ repo_path }}/.worktrees/{{ branch | sanitize }}"
$ wt switch --create feat --no-cd --format=json
{
  "action": "created",
  "branch": "feat",
  "path": "/…/proj/.worktrees/feat",
  ...
}

The worktree itself lands in the link target (/tmp/real/feat), but the printed path goes through the .worktrees link.

A likely fix is to canonicalize the path in the WorktreeCreate arm before printing it (dunce::canonicalize, as operational_worktree_path in src/commands/worktree/switch.rs already does for existing worktrees). Whether wt switch --format=json should report the resolved path more generally is a separate question.

worktrunk-bot avatar Nov 15 '26 23:11 worktrunk-bot

#4814 has the fix. The WorktreeCreate hook now resolves the path from wt switch --format=json before printing it, so a worktree-path that runs through a symlinked directory inside the repository reaches Claude Code as the real path. The new regression test failed on the old code and passes with the fix. CI is still running on the PR, and a maintainer needs to merge it. I haven't tried it against Claude Code 2.1.325 itself.

worktrunk-bot avatar Nov 15 '26 23:11 worktrunk-bot