From h-superpowers
Use when implementation is complete, all tests pass, and you need to decide how to integrate the work - guides completion of development work by presenting structured options for merge, PR, or cleanup
How this skill is triggered — by the user, by Claude, or both
Slash command
/h-superpowers:finishing-a-development-branchThe summary Claude sees in its skill listing — used to decide when to auto-load this skill
Guide completion of development work by presenting clear options and handling chosen workflow.
Guide completion of development work by presenting clear options and handling chosen workflow.
Core principle: Verify tests → Present options → Execute choice → Clean up.
Announce at start: "I'm using the finishing-a-development-branch skill to complete this work."
Before presenting options, verify tests pass (applying verification-before-completion discipline — evidence, not assumption):
# Run project's test suite
npm test / cargo test / pytest / go test ./...
If tests fail:
Tests failing (<N> failures). Must fix before completing:
[Show failures]
Cannot proceed with merge/PR until tests pass.
Stop. Don't proceed to Step 2.
If tests pass: Continue to Step 2.
# Try common base branches
git merge-base HEAD main 2>/dev/null || git merge-base HEAD master 2>/dev/null
Or ask: "This branch split from main - is that correct?"
Environment note: Determine workspace state first:
GIT_DIR=$(cd "$(git rev-parse --git-dir 2>/dev/null)" 2>/dev/null && pwd -P)
GIT_COMMON=$(cd "$(git rev-parse --git-common-dir 2>/dev/null)" 2>/dev/null && pwd -P)
If GIT_DIR != GIT_COMMON and HEAD is detached (externally-managed workspace), present the reduced 3-option menu (no local merge):
Implementation complete. You're on a detached HEAD (externally managed workspace).
1. Push as new branch and create a Pull Request
2. Keep as-is (I'll handle it later)
3. Discard this work
Which option?
Otherwise (normal repo or named-branch worktree), present exactly these 4 options:
Implementation complete. What would you like to do?
1. Merge back to <base-branch> locally
2. Push and create a Pull Request
3. Keep the branch as-is (I'll handle it later)
4. Discard this work
Which option?
Don't add explanation - keep options concise.
# Operate in the MAIN repo, not inside the feature worktree
MAIN_ROOT=$(git -C "$(git rev-parse --git-common-dir)/.." rev-parse --show-toplevel)
cd "$MAIN_ROOT"
git checkout <base-branch>
git pull
git merge <feature-branch>
<test command> # verify tests on merged result BEFORE removing anything
# Then tear down the worktree (Step 5): native ExitWorktree(remove), or manual worktree remove
# Only AFTER the worktree is gone:
git branch -d <feature-branch>
Tear down the worktree (Step 5) first; the git branch -d shown above runs only after the worktree is gone.
Note: Keep the worktree after creating the PR (the branch is still active).
# Push branch
git push -u origin <feature-branch>
# Create PR
gh pr create --title "<title>" --body "$(cat <<'EOF'
## Summary
<2-3 bullets of what changed>
## Test Plan
- [ ] <verification steps>
EOF
)"
Then: Keep worktree (branch is still active for PR updates).
Report: "Keeping branch . Worktree preserved at ."
Don't cleanup worktree.
Confirm first:
This will permanently delete:
- Branch <name>
- All commits: <commit-list>
- Worktree at <path>
Type 'discard' to confirm.
Wait for exact confirmation.
If confirmed, switch to the base branch, tear down the worktree FIRST, then force-delete the branch:
git checkout <base-branch>
# Tear down the worktree (Step 5): native ExitWorktree(remove, discard_changes), or manual worktree remove
# Only AFTER the worktree is gone:
git branch -D <feature-branch>
Tear down the worktree (Step 5) first; the git branch -D shown above runs only after the worktree is gone.
Native teardown (preferred). If the worktree was created with EnterWorktree this session, use ExitWorktree — it returns the session to the original directory and removes or keeps the worktree safely (it only ever touches worktrees this session created):
ExitWorktree(action: "remove").ExitWorktree(action: "remove", discard_changes: true).ExitWorktree(action: "keep") (or leave in place) — branch stays active.If ExitWorktree reports no active worktree session (e.g., the worktree was created manually or in a different session), fall back to the manual cleanup below.
Manual fallback (non-native worktrees):
For Options 1 and 4:
Check if in worktree (match on the worktree's root path — git branch --show-current is empty on a detached HEAD and would make grep match every line):
WORKTREE_ROOT=$(git rev-parse --show-toplevel)
git worktree list | grep -F "$WORKTREE_ROOT"
If yes — change directory to the main repo BEFORE removing the worktree:
# CRITICAL: cd to main repo first. If your shell CWD is inside the worktree,
# removing it destroys the CWD and every subsequent Bash call will fail.
cd "$(git worktree list | head -1 | awk '{print $1}')"
# Now safe to remove
git worktree remove <worktree-path>
For Option 3: Keep worktree.
| Option | Merge | Push | Keep Worktree | Cleanup Branch |
|---|---|---|---|---|
| 1. Merge locally | ✓ | - | - | ✓ |
| 2. Create PR | - | ✓ | ✓ | - |
| 3. Keep as-is | - | - | ✓ | - |
| 4. Discard | - | - | - | ✓ (force) |
For Options 1 and 4, remove the worktree before deleting the branch (a branch backing an active worktree can't be cleanly deleted).
Skipping test verification
Open-ended questions
Removing worktree while CWD is inside it
cd to main repo root BEFORE git worktree removeAutomatic worktree cleanup
No confirmation for discard
These guardrails exist because the stakes — someone else's code, history, or work — don't forgive mistakes:
Always:
Called by:
Pairs with:
Guides creation, editing, and verification of skills for AI coding agents using test-driven development with subagent scenarios. Use when authoring or debugging skills.
npx claudepluginhub ehartye/hartye-superpowers --plugin h-superpowers