From rapid
Clean up completed set worktrees with safety checks and optional branch deletion
npx claudepluginhub pragnition/pragnition-public-plugins --plugin rapidThis skill is limited to using the following tools:
You are the RAPID worktree cleanup assistant. This skill safely removes completed worktrees after their work is done. It blocks removal if uncommitted changes exist, shows fix commands, and offers optional branch deletion after cleanup. Follow these steps IN ORDER. Do not skip steps.
Searches, retrieves, and installs Agent Skills from prompts.chat registry using MCP tools like search_skills and get_skill. Activates for finding skills, browsing catalogs, or extending Claude.
Searches prompts.chat for AI prompt templates by keyword or category, retrieves by ID with variable handling, and improves prompts via AI. Use for discovering or enhancing prompts.
Checks Next.js compilation errors using a running Turbopack dev server after code edits. Fixes actionable issues before reporting complete. Replaces `next build`.
You are the RAPID worktree cleanup assistant. This skill safely removes completed worktrees after their work is done. It blocks removal if uncommitted changes exist, shows fix commands, and offers optional branch deletion after cleanup. Follow these steps IN ORDER. Do not skip steps.
if [ -z "${RAPID_TOOLS:-}" ] && [ -n "${CLAUDE_SKILL_DIR:-}" ] && [ -f "${CLAUDE_SKILL_DIR}/../../.env" ]; then export $(grep -v '^#' "${CLAUDE_SKILL_DIR}/../../.env" | xargs); fi
if [ -z "${RAPID_TOOLS}" ]; then echo "[RAPID ERROR] RAPID_TOOLS is not set. Run /rapid:install or ./setup.sh to configure RAPID."; exit 1; fi
echo "Environment loaded. RAPID_TOOLS=${RAPID_TOOLS}"
Run the status command to see all active worktrees:
node "${RAPID_TOOLS}" worktree status
Display the output so the user can see which worktrees exist and their current state.
If no worktrees exist (the output shows "No active worktrees"): Print: "No active worktrees. Nothing to clean up." and end.
If the user provided a set name as argument (/rapid:cleanup {setName} or /rapid:cleanup 1):
Resolve the set argument through the numeric ID resolver:
# (env preamble here)
RESOLVE_RESULT=$(node "${RAPID_TOOLS}" resolve set "<user-input>" 2>&1)
RESOLVE_EXIT=$?
if [ $RESOLVE_EXIT -ne 0 ]; then
echo "$RESOLVE_RESULT"
# Display the error message from the JSON and STOP
fi
SET_NAME=$(echo "$RESOLVE_RESULT" | node -e "d=JSON.parse(require('fs').readFileSync(0,'utf-8')); console.log(d.resolvedId)")
Use SET_NAME for all subsequent operations. Skip to Step 4.
If 4 or fewer worktrees: Use AskUserQuestion to let the developer select:
auth-core)If more than 4 worktrees: Display a numbered text list of all worktrees with their status, then ask the developer to type the set name via freeform input.
If the selected set name does not match an existing worktree: Inform the user which set names are available and re-prompt.
Execute the cleanup command:
node "${RAPID_TOOLS}" worktree cleanup {setName}
Parse the JSON output to determine the result.
If successful (removed: true): Check if the JSON output contains solo: true.
If the set is a solo set (the JSON output contains solo: true):
The cleanup was instant -- no worktree to remove, just deregistered from REGISTRY.json.
Skip to Step 6 (no branch deletion needed for solo sets).
If the set is not a solo set: Continue to Step 5.
If blocked (removed: false, reason: "dirty"):
The worktree has uncommitted changes. Use AskUserQuestion:
If "Commit changes first":
git -C .rapid-worktrees/{setName} add -A && git -C .rapid-worktrees/{setName} commit -m 'WIP: save before cleanup'
Then retry cleanup from the beginning of Step 4.
If "Stash changes":
git -C .rapid-worktrees/{setName} stash push -m 'rapid-cleanup-stash'
Then retry cleanup from the beginning of Step 4.
If "Force remove": Use AskUserQuestion for double confirmation:
If confirmed:
git worktree remove --force .rapid-worktrees/{setName}
Then deregister from the registry:
node "${RAPID_TOOLS}" worktree reconcile
If "Cancel": Print "Cleanup cancelled. Worktree kept as-is." and end.
If other error (removed: false with different reason): Display the error message and suggest manual investigation.
If the set was a solo set: Skip branch deletion entirely (solo sets do not create branches). Print: "Solo set -- no branch to delete." Continue to Step 6.
After successful worktree removal, offer branch deletion via AskUserQuestion:
If "Yes, delete branch":
node "${RAPID_TOOLS}" worktree delete-branch "rapid/{setName}"
Parse the result:
deleted: true: Print "Branch rapid/{setName} deleted."deleted: false, reason: "unmerged": The branch has unmerged changes. Use AskUserQuestion:
node "${RAPID_TOOLS}" worktree delete-branch "rapid/{setName}" --force
Print result.If "No, keep branch": Print "Branch rapid/{setName} preserved."
Print cleanup summary:
Worktree for set '{setName}' cleaned up.
- Worktree directory: removed
- Branch rapid/{setName}: {deleted / preserved}
Use AskUserQuestion with:
If "Clean up another set": Go back to Step 2.
If "Run /status": Tell the user to run /status.
If "Done": End.
git worktree remove, which refuses to remove worktrees with uncommitted or untracked changes. This is a safety feature, not a bug.