Skip to content

feat(plugin): add wt config plugins claude hook for the Claude hooks - #4304

Merged
max-sixty merged 6 commits into
mainfrom
plugin
Sep 28, 2026
Merged

max-sixty merged 6 commits into
mainfrom
plugin

Conversation

@max-sixty

Copy link
Copy Markdown
Owner

Adds a hidden wt config plugins claude hook subcommand that reads Claude Code's hook payload from stdin and acts on its hook_event_name: activity markers, the EnterWorktree approval, and WorktreeCreate / WorktreeRemove. This is the first half of getting the Claude Code plugin into Anthropic's plugin directory, whose validator blocks our current hooks/hooks.json because its commands compute paths (-C "$CLAUDE_PROJECT_DIR") and carry inline programs (bash -c '…$(jq …)…'). Once hooks.json runs this subcommand, every hook command is the same literal line and the plugin no longer needs jq.

hooks.json itself is unchanged here. The marketplace serves the plugin from main, so switching it before a release ships hook would break worktree creation for everyone on v0.79. The switch is a separate draft PR, to merge a few weeks after the release that ships this.

This was written by Claude Code on behalf of max-sixty

max-sixty and others added 5 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]>
worktrunk-bot
worktrunk-bot previously approved these changes Sep 27, 2026

@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.

codecov/patch fails on this head. Six of its seven missed lines are the PermissionRequest arm of handle_claude_hook plus the no-path early return in approves_enter_worktree. The existing PermissionRequest test in config_show.rs runs the command out of hooks.json, which still calls approve-enter-worktree. Nothing exercises the hook arm, and that arm has its own logic: unwrap_or(false) in place of ?, and setting the marker in-process where the old command relied on ||. #4305 would cover it indirectly once it switches hooks.json, but this PR lands first. The suggested test covers the allow path, a non-EnterWorktree decline, and an EnterWorktree without a path. It passes locally and is rustfmt-clean.

That leaves one miss, the current_dir() fallback used when CLAUDE_PROJECT_DIR is unset. run_hook always sets that variable, so covering the fallback would need an env_remove variant of the helper.

I dismissed my earlier approval until coverage is addressed, since AGENTS.md requires explicit approval before merging with codecov/patch red. I can push this test if you'd like.

Comment thread tests/integration_tests/claude_hook.rs Resolved
@worktrunk-bot
worktrunk-bot dismissed their stale review September 27, 2026 18:25

codecov/patch failed — the PermissionRequest arm of the new hook is untested

@max-sixty
max-sixty merged commit 2661ba1 into main Sep 28, 2026
39 checks passed
@max-sixty
max-sixty deleted the plugin branch September 28, 2026 06:44
max-sixty added a commit that referenced this pull request Oct 22, 2026
… hook` (#4305)

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](https://github.com/max-sixty/worktrunk/blob/d965d819f226ad7ac853efed8b2a996bb0c880a6/plugins/worktrunk/hooks/hooks.json#L72):
it clears `--create` for an existing local branch. Both the [base remove
hook](https://github.com/max-sixty/worktrunk/blob/d965d819f226ad7ac853efed8b2a996bb0c880a6/plugins/worktrunk/hooks/hooks.json#L82)
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_

---------

Co-authored-by: Claude Opus 5.5 (1M context) <[email protected]>
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