/flow:wt-destroyfrom flow
Destroy a worktree — close any PR, delete local and remote branches, and remove the worktree, discarding all uncommitted changes. Optionally takes a branch name argument; defaults to the current worktree.
Ships in flow. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description, though model invocation is off: only you can start it.
SKILL.md joins the conversation and stays.
None: SKILL.md is the whole skill.
Announce at start: "I'm using the wt-destroy skill to tear down a worktree."
pwdgit branch --show-currentgit worktree list --porcelaingit status --porcelaingh pr view --json number,url,state,title 2>&1 || echo NO_PRflowchart TD
A[Resolve target] --> B[Fetch PR info]
B --> C[Confirm with user]
C -- denied --> STOP
C -- confirmed --> D{PR exists?}
D -- yes --> E[Close PR]
D -- no --> F[Destroy worktree + branches]
E --> F
F --> G{Destroyed current dir?}
G -- yes --> H[Tell user to close session]
G -- no --> I[Report + offer more cleanup]
| Check | How to detect | Action |
|---|---|---|
| Target is the main worktree | Target path matches the first entry in the worktree list | STOP — tell user this is the main worktree |
| Branch argument doesn't match any worktree | No worktree entry has the given branch | STOP — tell user the branch was not found in the worktree list |
Uncommitted changes do NOT block execution — they are discarded.
| Variable | Source |
|---|---|
{BRANCH} | The skill argument if provided, otherwise the current branch |
{MAIN_WORKTREE} | Path of the first entry in the worktree list (the main worktree) |
{WORKTREE_PATH} | Worktree path matching {BRANCH} from the worktree list |
{NUMBER} | PR number — from Step 2 if argument provided, from ! context otherwise |
{DESTROYING_SELF} | true if current directory == {WORKTREE_PATH}, false otherwise |
If a branch name argument was provided, look up {WORKTREE_PATH} from the
worktree list by matching the branch field. If no argument, use the current
directory for {WORKTREE_PATH} and the current branch for {BRANCH}.
Determine {BRANCH}, {WORKTREE_PATH}, and {DESTROYING_SELF} from the
argument or current directory (see Variables above). Check preconditions and
STOP if they fail.
Skip this step if no argument was provided — the ! context already has PR info
for the current branch.
gh pr view {BRANCH} --json number,url,state,title 2>/dev/null || echo NO_PR
This fetches PR info for the target branch (which differs from the current branch). Save the result for use in Steps 3 and 4.
Use AskUserQuestion to confirm destruction. Include in the question:
{BRANCH}{WORKTREE_PATH}Example: "Destroy worktree for branch fix-foo at /path/to/fix-foo? This will
close PR #42 'Fix foo' and delete the local and remote branches."
If the user denies, STOP.
Skip this step if PR info shows NO_PR or the PR state is not OPEN.
gh pr close {NUMBER}
Tolerate errors — the PR may have already been closed or merged.
CRITICAL: This MUST be a single Bash invocation. If {DESTROYING_SELF}
is true, the shell's CWD will no longer exist after worktree remove and ALL
subsequent Bash tool calls will fail. Every command uses git -C to operate from
{MAIN_WORKTREE} regardless of the shell's CWD state.
Do NOT split these into separate Bash calls. Do NOT remove or reorder commands.
git -C {MAIN_WORKTREE} worktree remove --force {WORKTREE_PATH}; git -C {MAIN_WORKTREE} worktree prune; git -C {MAIN_WORKTREE} branch -D {BRANCH} 2>/dev/null; git -C {MAIN_WORKTREE} push origin --delete {BRANCH} 2>/dev/null; echo "===REMAINING WORKTREES==="; git -C {MAIN_WORKTREE} worktree list
Commands are joined with ; (continue regardless of errors). Individual failures
are tolerated — the branch or remote may already be gone.
Parse the output from Step 5. Everything after ===REMAINING WORKTREES=== is
the current worktree list.
If {DESTROYING_SELF} is true:
Summarize what was destroyed:
Then tell the user: "The current directory has been deleted. Please close this session and open a new one from a valid directory."
Do NOT run any further Bash commands or offer follow-up actions — the shell is broken.
If {DESTROYING_SELF} is false:
Summarize what was destroyed:
List remaining worktrees. If any look stale (e.g. branch no longer exists on remote), offer to destroy them.
Never:
{DESTROYING_SELF} = true)Always:
git -C {MAIN_WORKTREE} for all git commands (never cd)What SKILL.md sets; muted values are Claude Code's defaults
npx claudepluginhub salimhamed/claude-code-flow --plugin flow4 skills in this plugin
/wt-createUse when starting feature work that needs isolation from current workspace or before executing implementation plans - creates an isolated git worktree with smart directory selection and safety verification/wt-initGenerate a .worktreerc.yml config file for the current project by scanning for environment files, lock files, and dev tooling - use when setting up worktree workflows for a new project/wt-mergeSquash-merge the current branch's PR, clean up the worktree, return to main, and report remaining worktree statusOther plugins' skills for the same job