claude-code - 💡(How to fix) Fix [BUG] Claude Desktop's worktree creation flow does not fire the WorktreeCreate hook

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…

Error Message

Error Messages/Logs

No error — the hook is silently skipped. /tmp/claude-worktree-create.log (a debug cat in the hook script) gets a new entry on every CLI --worktree invocation but never on a Desktop-initiated worktree.

Fix Action

Fix / Workaround

The same hook fires correctly when invoking claude --worktree <name> from the CLI, so the hook itself and the settings file are wired up correctly — Desktop just doesn't call into the hook dispatch path for this event.

When Desktop creates a worktree, it should dispatch the WorktreeCreate hook the same way the CLI does:

  1. Send the JSON payload (cwd, name, hook_event_name, …) to the hook command on stdin.
  2. Use the path the hook prints on stdout as the worktree location.
  3. Fail worktree creation (with the hook's stderr surfaced) if the hook exits non-zero.
  • #36205 — EnterWorktree tool ignores WorktreeCreate/WorktreeRemove hooks (similar bypass for the agent-tool path)
  • #46664 — Plugin-registered WorktreeCreate hooks never dispatched (different scope; both point at the dispatch table being incomplete)
  • #42336 — PostToolUse hooks not triggering in Desktop App (closed, but suggests hook plumbing has had gaps before)

Code Example

{
     "hooks": {
       "WorktreeCreate": [{
         "hooks": [{
           "type": "command",
           "command": "~/.claude/hooks/worktree-create.sh"
         }]
       }]
     }
   }

---

#!/usr/bin/env bash
   set -euo pipefail
   input=$(cat)
   { echo "=== $(date -u +%FT%TZ) ==="; echo "$input"; echo; } >> /tmp/claude-worktree-create.log
   cwd=$(jq -r '.cwd' <<<"$input")
   name=$(jq -r '.name' <<<"$input")
   parent=$(dirname "$cwd"); base=$(basename "$cwd")
   target="$parent/${base}-worktrees/$name"
   mkdir -p "$parent/${base}-worktrees"
   git -C "$cwd" worktree add "$target" >&2
   echo "$target"
RAW_BUFFERClick to expand / collapse

[BUG] Claude Desktop's worktree creation flow does not fire the WorktreeCreate hook

What's Wrong?

When Claude Desktop creates a git worktree (e.g. via the in-app "new worktree" / cowork flow), the WorktreeCreate hook configured in ~/.claude/settings.json is not invoked. The Desktop app instead creates the worktree directly under <repo>/.claude/worktrees/<name> and records it in ~/Library/Application Support/Claude/git-worktrees.json, bypassing the user's hook entirely.

The same hook fires correctly when invoking claude --worktree <name> from the CLI, so the hook itself and the settings file are wired up correctly — Desktop just doesn't call into the hook dispatch path for this event.

This makes the documented WorktreeCreate override mechanism (https://code.claude.com/docs/en/hooks) ineffective for Desktop users who want worktrees in a non-default location (e.g. a sibling directory <repo>-worktrees/<name> instead of <repo>/.claude/worktrees/<name>).

What Should Happen?

When Desktop creates a worktree, it should dispatch the WorktreeCreate hook the same way the CLI does:

  1. Send the JSON payload (cwd, name, hook_event_name, …) to the hook command on stdin.
  2. Use the path the hook prints on stdout as the worktree location.
  3. Fail worktree creation (with the hook's stderr surfaced) if the hook exits non-zero.

The Desktop's internal git-worktrees.json registry should record whatever path the hook returned, not a hard-coded .claude/worktrees/<name>.

Error Messages/Logs

No error — the hook is silently skipped. /tmp/claude-worktree-create.log (a debug cat in the hook script) gets a new entry on every CLI --worktree invocation but never on a Desktop-initiated worktree.

~/Library/Application Support/Claude/git-worktrees.json shows recent Desktop-created worktrees still under /Users/<me>/projects/<repo>/.claude/worktrees/<name> despite the hook being active.

Steps to Reproduce

  1. Add a WorktreeCreate hook to ~/.claude/settings.json:
    {
      "hooks": {
        "WorktreeCreate": [{
          "hooks": [{
            "type": "command",
            "command": "~/.claude/hooks/worktree-create.sh"
          }]
        }]
      }
    }
  2. Create ~/.claude/hooks/worktree-create.sh (chmod +x):
    #!/usr/bin/env bash
    set -euo pipefail
    input=$(cat)
    { echo "=== $(date -u +%FT%TZ) ==="; echo "$input"; echo; } >> /tmp/claude-worktree-create.log
    cwd=$(jq -r '.cwd' <<<"$input")
    name=$(jq -r '.name' <<<"$input")
    parent=$(dirname "$cwd"); base=$(basename "$cwd")
    target="$parent/${base}-worktrees/$name"
    mkdir -p "$parent/${base}-worktrees"
    git -C "$cwd" worktree add "$target" >&2
    echo "$target"
  3. From the CLI: cd <repo> && claude --worktree probe-cli → Hook fires; worktree appears at <parent>/<repo>-worktrees/probe-cli. /tmp/claude-worktree-create.log gets a new entry. ✅
  4. Fully quit Claude Desktop (⌘Q) and relaunch to clear any settings cache.
  5. In Desktop: start a new Claude Code session for a project, then enable the "Worktree" toggle for that session. → Worktree appears at <repo>/.claude/worktrees/<generated-name>. /tmp/claude-worktree-create.log is not updated. ❌
  6. Inspect ~/Library/Application Support/Claude/git-worktrees.json — the Desktop-created entry's path field points inside .claude/worktrees/, confirming the hook was bypassed.

Related Issues

  • #36205 — EnterWorktree tool ignores WorktreeCreate/WorktreeRemove hooks (similar bypass for the agent-tool path)
  • #46664 — Plugin-registered WorktreeCreate hooks never dispatched (different scope; both point at the dispatch table being incomplete)
  • #42336 — PostToolUse hooks not triggering in Desktop App (closed, but suggests hook plumbing has had gaps before)

Environment

  • Claude Desktop: 1.6259.1 (5095e7), build 2026-05-06T03:26:09Z, macOS
  • Claude Code CLI: 2.1.117
  • macOS: 26.4.1
  • Hook configured at user scope in ~/.claude/settings.json

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING

claude-code - 💡(How to fix) Fix [BUG] Claude Desktop's worktree creation flow does not fire the WorktreeCreate hook