Worktrunk is a CLI for Git worktree management, designed for parallel AI agent workflows
fix(plugin): drop -D from WorktreeRemove hook to preserve unmerged branches (#2940)
Worktrunk Boteaa230bc058e
diff --git a/plugins/worktrunk/hooks/hooks.json b/plugins/worktrunk/hooks/hooks.jsonindex 9eb033da4..322b1cec4 100644--- a/plugins/worktrunk/hooks/hooks.json+++ b/plugins/worktrunk/hooks/hooks.json@@ -47,7 +47,7 @@"hooks": [{"type": "command",- "command": "jq -r '.worktree_path' | xargs bash \"${CLAUDE_PLUGIN_ROOT}/hooks/wt.sh\" remove -D --foreground"+ "command": "jq -r '.worktree_path' | xargs bash \"${CLAUDE_PLUGIN_ROOT}/hooks/wt.sh\" remove --foreground"}]}diff --git a/skills/wt-switch-create/SKILL.md b/skills/wt-switch-create/SKILL.mdindex 16f498f3f..939ffb9fc 100644--- a/skills/wt-switch-create/SKILL.md+++ b/skills/wt-switch-create/SKILL.md@@ -58,8 +58,10 @@ after it. Otherwise the task starts at the second token.Don't remove the worktree yourself. `ExitWorktree({action: "remove"})` (if theuser asks to leave) or the session-exit prompt routes through this plugin's-`WorktreeRemove` hook → `wt remove -D --foreground`. A worktree with uncommitted-changes won't be auto-removed without confirmation — that's intended.+`WorktreeRemove` hook → `wt remove --foreground`. A worktree with uncommitted+changes won't be auto-removed without confirmation — that's intended. A branch+with committed-but-unmerged work is retained (with a `wt remove -D <branch>`+hint) instead of being silently force-deleted.## Scopediff --git a/tests/integration_tests/config_show.rs b/tests/integration_tests/config_show.rsindex 172ae3ae1..950edce7c 100644--- a/tests/integration_tests/config_show.rs+++ b/tests/integration_tests/config_show.rs@@ -3979,6 +3979,24 @@ fn test_plugin_layout_is_consolidated() {}}+ // The WorktreeRemove hook must not force-delete unmerged branches (#2939).+ // Claude Code auto-fires WorktreeRemove on session exit for any worktree+ // with a clean working tree, so a hook command containing `-D` /+ // `--force-delete` silently discards committed-but-unpushed work — the only+ // recovery path is `git fsck`. The safe default retains unmerged branches+ // and prints a `wt remove -D <branch>` hint for the user to act on.+ let hooks = read("plugins/worktrunk/hooks/hooks.json");+ let hooks_json = json("plugins/worktrunk/hooks/hooks.json");+ let worktree_remove_cmd = hooks_json["hooks"]["WorktreeRemove"][0]["hooks"][0]["command"]+ .as_str()+ .expect("WorktreeRemove hook must define a command");+ assert!(+ !worktree_remove_cmd.contains(" -D") && !worktree_remove_cmd.contains("--force-delete"),+ "WorktreeRemove hook must not pass -D / --force-delete (silently destroys \+ committed-but-unpushed work on session-exit auto-remove; see #2939). \+ hooks.json:\n{hooks}"+ );+// The product description must not drift across tools. Byte-identical is// schema-impossible (Codex omits the activity clause, Gemini says// "extension"), but every manifest shares the canonical opening sentence.