Worktrunk is a CLI for Git worktree management, designed for parallel AI agent workflows
fix(plugin): resolve WorktreeRemove against the worktree path, not the project dir (#3754)
Jude Wang3817df07956c
diff --git a/plugins/worktrunk/hooks/hooks.json b/plugins/worktrunk/hooks/hooks.jsonindex babae7b44..e0e1a51a1 100644--- a/plugins/worktrunk/hooks/hooks.json+++ b/plugins/worktrunk/hooks/hooks.json@@ -79,7 +79,7 @@"hooks": [{"type": "command",- "command": "bash -c 'p=$(jq -er .worktree_path) || exit 1; cd \"${CLAUDE_PROJECT_DIR:-.}\" || exit 1; [ -e \"$p\" ] || exit 0; bash \"$CLAUDE_PLUGIN_ROOT/hooks/wt.sh\" remove --foreground \"$p\"'"+ "command": "bash -c 'p=$(jq -er .worktree_path) || exit 1; [ -e \"$p\" ] || exit 0; bash \"$CLAUDE_PLUGIN_ROOT/hooks/wt.sh\" -C \"$p\" remove --foreground \"$p\"'"}]}diff --git a/tests/integration_tests/config_show.rs b/tests/integration_tests/config_show.rsindex c4a748ed3..41074cd3d 100644--- a/tests/integration_tests/config_show.rs+++ b/tests/integration_tests/config_show.rs@@ -3882,6 +3882,23 @@ fn test_plugin_layout_is_consolidated() {hooks.json:\n{hooks}");+ // The WorktreeRemove hook must resolve against the worktree path Claude+ // Code hands it, not the session's project dir. The `claude agents` view+ // spans every repo with a background session and is often launched from a+ // parent directory that merely contains them, so `CLAUDE_PROJECT_DIR` names+ // the wrong repo or none at all, `wt remove <path>` dies with `fatal: not a+ // git repository`, and the session row is left undeletable (#3754, after+ // the #3489 anchor proved insufficient). `-C "$p"` is layout-independent: a+ // linked worktree carries a `.git` file pointing at its owning repository.+ assert!(+ worktree_remove_cmd.contains("-C \"$p\"")+ && !worktree_remove_cmd.contains("CLAUDE_PROJECT_DIR"),+ "WorktreeRemove hook must resolve via -C \"$p\" (the worktree path Claude Code \+ handed it), never CLAUDE_PROJECT_DIR — the agents view is multi-repo, so no \+ single project dir is correct for every session (#3754). \+ command:\n{worktree_remove_cmd}"+ );+// The WorktreeCreate hook pipes `wt … --format=json | jq -er .path`. Without// `set -o pipefail` the pipeline's exit status is jq's, and `jq -er .path`// on the empty stdout of a failed `wt` exits 0 on jq 1.6 — so a `wt` failure