worktrunk icon indicating copy to clipboard operation
worktrunk copied to clipboard

Claude desktop app skips the plugin's WorktreeCreate hook (cause and workaround)

Open chatoo2412 opened this issue 3 weeks ago • 1 comments

Sharing this for anyone who hits it: nothing to fix on the worktrunk side, as far as I can tell.

What happens

With the Claude Code plugin installed, worktree sessions started from the Claude desktop app don't go through worktrunk. The app creates the worktree itself:

  • Path <repo>/.claude/worktrees/<name>-<6 hex>, branch claude/<name>-<6 hex>
  • No git hooks run. The app runs git -c core.hooksPath=/dev/null … worktree add --no-checkout … and fills the tree itself, so post-checkout hooks (including ones registered with hook.<name>.event in the global git config) are skipped

claude --worktree <name> from the CLI, on the same machine, goes through the plugin hook as expected.

Cause

The desktop app doesn't run a plugin's WorktreeCreate / WorktreeRemove hooks. This is tracked in anthropics/claude-code#29716. A comment there (2026-09-01) reports that the same hooks run once they are moved from the plugin's hooks/hooks.json into a settings file.

The Claude Code docs describe the same limit for the CLI: a plugin's WorktreeCreate hook doesn't run when the worktree is created before plugins load, and they recommend defining the hook in a settings file instead. https://code.claude.com/docs/en/hooks#worktreecreate

Workaround

Define the plugin's hooks in ~/.claude/settings.json, calling the same command, and disable the plugin. With both enabled, the CLI runs each hook twice, because Claude Code keeps a plugin's copy of a handler separate from the settings copy.

{
  "enabledPlugins": { "worktrunk@worktrunk": false },
  "hooks": {
    "UserPromptSubmit": [{ "hooks": [{ "type": "command", "command": "wt config plugins claude hook || true" }] }],
    "Notification": [{ "matcher": "", "hooks": [{ "type": "command", "command": "wt config plugins claude hook || true" }] }],
    "PreToolUse": [{ "matcher": "AskUserQuestion", "hooks": [{ "type": "command", "command": "wt config plugins claude hook || true" }] }],
    "PermissionRequest": [{ "matcher": "", "hooks": [{ "type": "command", "command": "wt config plugins claude hook || true" }] }],
    "Stop": [{ "hooks": [{ "type": "command", "command": "wt config plugins claude hook || true" }] }],
    "SessionEnd": [{ "matcher": "", "hooks": [{ "type": "command", "command": "wt config plugins claude hook || true" }] }],
    "WorktreeCreate": [{ "hooks": [{ "type": "command", "command": "wt config plugins claude hook" }] }],
    "WorktreeRemove": [{ "hooks": [{ "type": "command", "command": "wt config plugins claude hook" }] }]
  }
}

This mirrors plugins/worktrunk/hooks/hooks.json, with wt called directly instead of through hooks/wt.sh ($CLAUDE_PLUGIN_ROOT isn't set for settings hooks). It works because wt config plugins claude hook lives in the wt binary and doesn't depend on the plugin being enabled.

Disabling the plugin drops the /worktrunk and /wt-switch-create skills and the /wt-diff pane.

Related

Worktrees Claude Code creates without a WorktreeCreate hook (CLI included) skip the repository's git hooks as well. A setting to run them is requested in anthropics/claude-code#106388. Routing creation through wt avoids both issues, since wt uses a plain git worktree add.

Environment

  • worktrunk 0.81.0 (Homebrew)
  • Claude desktop app 5.11492.0, Claude Code CLI 2.1.318
  • macOS (darwin-arm64)

Maybe worth a note on the Claude Code docs page, but no action needed otherwise.

chatoo2412 avatar Nov 13 '26 02:11 chatoo2412

Thanks for tracking down the cause. The limitation belongs on the Agent Integration page, so #4777 adds one sentence to its worktree isolation section: the desktop app creates worktree sessions itself and skips plugin WorktreeCreate/WorktreeRemove hooks. It links anthropics/claude-code#29716. The PR is waiting on CI and a maintainer's review.

I left your settings-file workaround out of the docs. It costs the plugin's skills and the /wt-diff pane. The upstream thread also disagrees on whether settings hooks fire in the desktop app: the 2026-09-01 comment says they do, and the 2026-10-05 one says they don't, though that session ran over SSH. Your write-up here remains the reference for anyone who wants to make that trade.

worktrunk-bot avatar Nov 13 '26 02:11 worktrunk-bot