Skip to content

feat(plugin): run every Claude hook through wt config plugins claude hook - #4305

Merged
max-sixty merged 11 commits into
mainfrom
plugin-hook-cutover
Oct 22, 2026
Merged

max-sixty merged 11 commits into
mainfrom
plugin-hook-cutover

Conversation

@max-sixty

@max-sixty max-sixty commented Sep 27, 2026 •

Copy link
Copy Markdown
Owner

Routes all eight Claude Code hook events through the existing Rust dispatcher added in #4304. Hook commands become literal invocations that pass the plugin directory validator, and the plugin no longer requires jq. The README requires wt v0.81.0 or later.

On wt v0.80.0 or earlier, worktree creation and removal fail, and activity markers and EnterWorktree auto-approval stop working. The latter hooks retain || true, so the failures stay nonblocking and EnterWorktree falls back to a permission prompt. The dispatcher preserves existing-branch reopening and safe removal of unmerged work. Updates the hook layout assertions and the skill's create-or-reopen guidance, and removes the obsolete shell pipeline explanation.

Local validation: the project gate passed for the corrected skills at 1a9ebd12c in an isolated target directory (5,392 tests passed, one skipped, plus Clippy, formatting, docs, and snapshots). Docs mirror sync and all five dispatcher integration tests pass. The later documentation-only follow-ups clarify the README's attribution of payload parsing and the measured cleanup behavior. claude plugin validate plugins/worktrunk passed its directory checks with the existing missing-version warning; it excludes the catalog's safety scan and policy review.

Independent Opus 5.5 review found no code defects and verified the older-version failure. Further passes reviewed the corrected skills, mirrors and live cleanup evidence with no remaining findings.

Cleanup was verified live on Claude Code 2.1.308 in an isolated repository: reopening an existing worktree through both claude --worktree and EnterWorktree({name}), then /exit, shows Keep / Remove with Keep selected. Keep leaves its branch and checkout intact and emits no WorktreeRemove. A fresh CLI-created worktree shows the same prompt; choosing Remove emits WorktreeRemove and removes the synthetic checkout and merged branch. The rationale now reflects that confirmation instead of claiming automatic cleanup.

Reopening is already present in the base create hook: it clears --create for an existing local branch. Both the base remove hook and the dispatcher check for .git and invoke wt -C <path> remove --foreground <path>, with no force flags. This cutover preserves that deletion scope and its safeguards.

This was written by Codex on behalf of max-sixty

max-sixty and others added 6 commits September 26, 2026 14:02
…follow them

Anthropic's plugin directory refuses a hook command whose path the shell
computes or that carries an inline program, which blocked submitting
plugins/worktrunk. Each Claude hook now runs one script under hooks/ by a
literal $CLAUDE_PLUGIN_ROOT path; the scripts keep the old commands'
behavior and the #2939, #3545, #3754, and #3921 guards, now pinned against
the script text.

Also fills in the listing metadata the directory reads (license, homepage,
repository, keywords, icon), discloses in the plugin README what each hook
runs, and pins the hook scripts to LF so a CRLF checkout can't drop
pipefail.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
The plugin directory scanner reads `$PWD` in the bundled skill reference as a
credential read and holds the plugin for review. direnv's own `expand_path`
resolves the path the same way, relative to the .envrc.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
One hidden subcommand reads Claude Code's hook payload and acts on its
event: activity markers, the EnterWorktree approval, and WorktreeCreate /
WorktreeRemove. Moving the plugin's hooks.json onto it leaves each hook
command a literal path, which Anthropic's plugin directory requires, and
drops the jq dependency.

hooks.json keeps its current commands here: the marketplace serves the
plugin from main, so switching it before a release ships `hook` would break
worktree creation for every installed wt. The switch follows the next
release. `approve-enter-worktree` stays for plugin copies installed before
`hook`, since marketplace installs don't update on their own.

Also fills in the plugin listing metadata (license, homepage, repository,
keywords, icon) and documents in the plugin README what each hook runs.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
… hook`

Each hook in hooks/hooks.json is now the same literal command, with the
event logic in `wt`. Anthropic's plugin directory accepts it, since no
command computes a path or carries an inline program, and the plugin no
longer needs jq, so it leaves the dev and test tool lists too.

The marker events end in `|| true`: a wt without `hook` exits 2, which
Claude Code reads as blocking the prompt, tool call, permission, or stop.
The worktree events need a wt that has `hook`.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
# Conflicts:
#	plugins/worktrunk/README.md
#	tests/integration_tests/claude_hook.rs

@worktrunk-bot worktrunk-bot left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is feedback on a draft, not a merge verdict. Mark the PR ready when you want the full review.

The new hook commands match the old ones, event by event. The only issue I found is in the prose: two new sentences say hooks/wt.sh reads the payload and dispatches on its event. wt.sh only finds wt and execs it; the dispatch happens in handle_claude_hook. Someone reading these docs to debug a hook would go looking in the shell script. The inline suggestions reword both sentences.

Comment thread plugins/worktrunk/README.md Resolved
Comment thread plugins/worktrunk/AGENTS.md Resolved
max-sixty pushed a commit that referenced this pull request Oct 10, 2026
…md does (#4399)

`skills/wt-switch-create/rationale.md` numbered its "The design" steps
one way and referred to them another. The list gave 1 to the
`EnterWorktree({name})` route, 2 to the `wt` + `EnterWorktree({path})`
route, and 3 to the tool-error recovery. The rest of the file uses
`SKILL.md`'s numbering, where 1 is picking the branch name, 2 is the
name route, and 3 is the `wt`/path route with the recovery inside it.
Read against the list, "step 3 `cd`s into another repo" pointed at the
recovery and "step 2's worktrees are not described as durable" pointed
at the path route, so both were wrong.

This renumbers the list to 2 and 3, notes that step 1 needs no
rationale, and folds the recovery into step 3. Every later `step N`
reference now matches both files. The generated mirror under
`plugins/worktrunk/skills/` was refreshed with `test_docs_are_in_sync`.
This is a docs-only change, so it adds no test.

The pipefail-wrapper section in the same file also no longer matches
`hooks.json`, which has no `xargs` stage now. I left it alone because
draft #4305 deletes that section.

Co-authored-by: worktrunk-bot <[email protected]>
@max-sixty
max-sixty marked this pull request as ready for review October 22, 2026 06:09

@worktrunk-bot worktrunk-bot left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The rationale still tells readers that EnterWorktree({name}) fails on an existing branch, both in the design step and the later failure description. With these hook commands, handle_claude_hook calls wt switch without --create when the branch exists; test_claude_hook_worktree_create verifies that it reopens the worktree. Both rationale copies need to describe that behavior so the skill's recovery guidance does not send users down the failure path for a successful entry.

@worktrunk-bot worktrunk-bot left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The new WorktreeCreate route reopens an existing branch, but the exit cleanup needs a safety check. The skill's rationale says an untouched EnterWorktree({name}) session triggers WorktreeRemove; that handler runs wt remove --foreground on the returned path, and the test_remove_foreground snapshot shows it deleting both a clean checkout and its merged branch. If Claude Code also sends WorktreeRemove after reopening a worktree that existed before the session, simply entering it and exiting would delete it. The previous hook failed on an existing branch, so this is a new deletion path.

Please verify that Claude Code does not clean up a reopened worktree, or preserve pre-existing worktrees and branches on that path. This is a data safety hold under the PR review guidance in .claude/skills/running-tend/references/review-pr.md; @max-sixty needs to review it before merge.

@max-sixty
max-sixty merged commit a63c1c3 into main Oct 22, 2026
38 checks passed
@max-sixty
max-sixty deleted the plugin-hook-cutover branch October 22, 2026 08:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants