Use after completing and verifying a task. Checks git branch (feature → suggests finishing-a-development-branch), closes task, cleans up implementation plan files, recursively checks parents with confirmation, runs bd sync. Handles task completion workflow for beads.
Core principle: Ask before cascading.
This skill handles task completion: close task, clean up plan files, check parents recursively, sync. Always asks before closing parent tasks - even when "obviously" all children are closed.
| Step | Action | Key Point |
|---|---|---|
| 1. Branch Check | Validate git branch + PR | Feature + no PR → stop; Feature + PR → ask |
| 2. Find Task | Get in_progress leaf | Ask if multiple |
| 3. Close | bd close {task-id} | Use bd, not SQL |
| 4. Plan Cleanup | Find and remove plan file | Ask: delete / archive / keep |
| 5. Check Parent |
| Recursive parent check |
| With confirmation |
| 6. Ask | Before closing parent | Even if "obvious" |
| 7. Sync | bd sync | Always, at end |
| 8. Cleanup | Delete branch/worktree | Only if branch matches task; ask first |
Key behavior: Always ask before closing parents. Always check PR on feature branches. Always clean up plan files. Always run bd sync. Offer cleanup after sync.
Follow these steps in order. Do not skip steps.
git branch --show-current
If generic branch (main, master, develop, trunk): Continue to step 2.
If feature branch detected (feature/*, fix/*, chore/*, or any non-generic):
Check if PR exists for current branch:
gh pr view --json state,url 2>/dev/null || echo "NO_PR"
If NO PR exists:
STOP and inform user:
"You're on feature branch
{branch-name}with no PR.Use
superpowers:finishing-a-development-branchto properly complete this work (handles merge/PR/cleanup and task closure together)."
Then exit. Do not continue workflow.
If PR exists (any state: open, merged, closed):
ASK user:
"You're on feature branch
{branch-name}.PR exists: {url} (state: {state})
Proceed to close task on this branch? (yes/no)"
superpowers:finishing-a-development-branch if needed.bd list --status=in_progress
Filter for leaf tasks (no open children).
If multiple found: Ask which task is complete.
If none found: Inform "No in_progress leaf tasks. Check with bd list --status=in_progress"
bd close {task-id}
Use bd close. Do NOT use direct SQL.
Confirm task closed.
After closing the task, check if an implementation plan file exists and offer to clean it up.
Two sources, check in order:
Source A — task description link:
bd show {task-id}
Look for Plan: line in description. If found, extract the file path.
Source B — untracked/modified files in docs/plans/:
If no Plan: link in description, search for untracked or unstaged plan files:
git ls-files --others --modified -- 'docs/plans/'
Filter results:
If multiple candidates found: Show the list and ask user which file (or "none").
If no plan file found (neither source): Skip to step 5. Do NOT inform — silent skip.
Always ask. Never auto-delete.
Plan file found:
{path}What to do with it?
- Delete
- Archive (move to
docs/archive/)- Keep as is
If delete:
rm {path}
If archive:
mkdir -p docs/archive
mv {path} docs/archive/
If keep: Do nothing, proceed to step 5.
Only if task description contained a Plan: line AND user chose delete or archive:
Get current description, remove the Plan: line, update:
bd update {task-id} --description="{description-without-plan-line}"
Do NOT commit the file deletion/move. The branch cleanup in step 8 or the user's next workflow will handle git state.
After closing task, check if it has a parent:
bd show {task-id}
Look for parent relationship.
If task has parent:
bd show {parent-id}
Count open children.
If parent has NO open children (all closed):
Ask user:
"Parent task
{parent-id}now has all children closed.Close it too? (yes/no)"
If user says yes:
bd close {parent-id}If user says no:
If parent has open children:
If task has no parent:
Continue checking grandparents, great-grandparents, etc. until:
Always ask at each level. Do NOT auto-close parents.
bd sync
Always run at end, regardless of how many tasks closed.
Confirm sync completed.
Non-blocking: If cleanup fails, the task is already closed and synced. Cleanup failure is not critical.
CURRENT_BRANCH=$(git branch --show-current)
Check if $CURRENT_BRANCH contains the closed task's ID. If not — skip cleanup silently. The user ran flow:done from an unrelated branch (e.g. master).
Gather cleanup targets:
pwd | grep -q "\.worktrees/" — are we in a worktree?git branch -r | grep "$CURRENT_BRANCH" — does remote branch exist?Display the current branch explicitly and list what will be deleted:
You are on branch `feature/claude-tools-elf.6-delete-branches-worktrees`.
Delete branch and associated resources?
- Worktree: .worktrees/feature-claude-tools-elf.6-delete-branches-worktrees
- Local branch: feature/claude-tools-elf.6-delete-branches-worktrees
- Remote branch: origin/feature/claude-tools-elf.6-delete-branches-worktrees
(yes/no)
Show only items that exist. If no worktree, omit the worktree line. If no remote branch, omit the remote line.
cd to the main repo root (parent of .worktrees/)git worktree remove <path> (if in worktree)DEFAULT_BRANCH=$(git symbolic-ref refs/remotes/origin/HEAD | sed 's|refs/remotes/origin/||')
Fallback: try master, then main.git checkout $DEFAULT_BRANCHgit pullgit branch -d <branch> (safe delete; use -D only if PR confirmed merged)git push origin --delete <branch> (if remote exists)Error handling:
git worktree remove --force or manual cleanup. Don't block.git branch -d will refuse. Show warning. Offer git branch -D only if PR state is MERGED.No cleanup performed. User can clean up manually later.
✅ Check git branch
✅ Find in_progress leaf task
✅ Close task with bd close
✅ Find plan file (linked in description OR untracked in docs/plans/)
✅ Ask user: delete / archive / keep plan file
✅ Remove Plan: link from description after delete/archive
✅ Check parents recursively
✅ Ask before closing each parent
✅ Run bd sync at end
✅ Offer to clean up branch and worktree (Step 8)
✅ Delete local branch, remote branch, worktree (after confirmation)
✅ Switch to default branch and pull after cleanup
❌ Git operations unrelated to cleanup (commit, push, merge, etc.) ❌ Create branches ❌ Start next task (use flow:start) ❌ Update PRs or issues ❌ Run tests or builds ❌ Auto-close parents without asking ❌ Auto-proceed on feature branches without asking ❌ Force-delete without confirmation ❌ Search for branches beyond the current one ❌ Clean up branches for parent tasks (cascade closures) ❌ Block task closure if cleanup fails
Scope note: On feature branches without PR, this skill STOPS and refers to finishing-a-development-branch. On feature branches WITH PR, it asks user before proceeding. Cleanup (Step 8) is non-blocking and only applies when the current branch matches the closed task.
If you're thinking any of these, STOP and follow the workflow:
All of these mean: Follow workflow. Check branch AND PR. Ask before proceeding. Always check for plan files (linked AND unlinked). Run bd sync. Offer cleanup only if branch matches task.
| Excuse | Reality |
|---|---|
| "All children closed → close parent" | Ask first. User might add more children or want to review. |
| "Branch check unnecessary" | Feature branch needs different workflow. Always check. |
| "bd sync is obvious" | Obvious steps get skipped. Make it explicit. |
| "Use SQL for efficiency" | bd close has logging, events, validation. Use it. |
| "Parent obviously should close" | Obvious to you ≠ user wants it. Ask. |
| "Being helpful by auto-closing" | Asking IS being helpful. Assuming isn't. |
| "Feature branch → always block" | Check for PR first. If PR exists, ask user. |
| "PR exists → auto-proceed" | Still ask user. PR exists ≠ user wants to close here. |
| "Cleanup is obvious, just delete" | Ask first. User might want to keep the branch. |
| "Skip cleanup, not my job" | Step 8 is part of the workflow. Offer it. |
| "Plan cleanup is not part of completing" | Step 4 IS part of the workflow. Plan files are task artifacts. |
| "No Plan: link → skip plan search" | Always search docs/plans/ for untracked files too. Plans aren't always linked. |
| "Auto-delete the plan, it's obvious" | Always ask. User might want to archive or keep for reference. |
| "Plan file is outside my scope" | Plan files are task artifacts. Cleaning them up IS in scope (Step 4). |
| "Branch doesn't match, clean up anyway" | Only clean up if branch contains the closed task's ID. |
| "Force-delete, PR was merged" | Use safe delete (-d) first. Only offer -D if -d fails AND PR is MERGED. |
User: "Task done, flow:done"
Agent: [Closes task]
[Checks parent, sees all children closed]
[Automatically closes parent without asking]
Done!
Problems:
User: "Task done, flow:done"
Agent: [Checks branch: master, OK to proceed]
[Closes task claude-tools-abc.3]
Parent task claude-tools-abc now has all children closed.
Close it too? (yes/no)
User: yes
Agent: [Closes parent]
[Runs bd sync]
✓ Closed claude-tools-abc.3
✓ Closed claude-tools-abc (parent)
✓ Synced with remote
Done.
Correct because:
User: "flow:done"
Agent: [Closes task]
[Sees Plan: link in description]
[Deletes plan file automatically]
[Removes Plan: link from description]
Done!
Problems:
User: "flow:done"
Agent: [Closes task]
[No Plan: link in description → skips plan cleanup entirely]
[Doesn't check docs/plans/ for untracked files]
Done!
Problem: Plan file exists as untracked in docs/plans/ but agent only checked description.
User: "flow:done"
Agent: [Checks branch: master, OK]
[Closes task claude-tools-abc]
Plan file found: `docs/plans/2026-02-06-abc-impl-plan.md`
What to do with it?
1. Delete
2. Archive (move to docs/archive/)
3. Keep as is
User: 2
Agent: [Moves to docs/archive/]
[Removes Plan: link from description]
[Checks parent, has open children]
[Runs bd sync]
✓ Closed claude-tools-abc
✓ Plan archived to docs/archive/
✓ Synced with remote
Done.
Correct because:
User: "flow:done"
Agent: [Checks branch: master, OK]
[Closes task claude-tools-xyz "Quota module"]
[No Plan: link in description]
[Checks docs/plans/ for untracked files]
[Finds: quota-module-impl-plan.md (untracked, matches task title)]
Plan file found: `docs/plans/quota-module-impl-plan.md`
What to do with it?
1. Delete
2. Archive (move to docs/archive/)
3. Keep as is
User: 1
Agent: [Deletes file]
[Checks parent, has open children]
[Runs bd sync]
✓ Closed claude-tools-xyz
✓ Plan deleted
✓ Synced with remote
Done.
Correct because:
User: "Done with this feature, flow:done"
Agent: [On feature/add-auth branch]
[Closes task without checking for PR]
Problem: Proceeded on feature branch without checking PR status.
User: "Done with this feature, flow:done"
Agent: [Checks branch: feature/add-auth]
[Checks PR: no PR exists]
You're on feature branch `feature/add-auth` with no PR.
Use `superpowers:finishing-a-development-branch` to properly
complete this work (handles merge/PR/cleanup and task closure together).
Correct because:
User: "PR merged, flow:done"
Agent: [Checks branch: feature/add-auth]
[Checks PR: exists, merged]
You're on feature branch `feature/add-auth`.
PR exists: https://github.com/org/repo/pull/123 (state: MERGED)
Proceed to close task on this branch? (yes/no)
User: yes
Agent: [Continues to step 2, finds task, closes it]
[Runs bd sync]
✓ Closed claude-tools-xyz
✓ Synced with remote
Done.
Correct because:
User: "PR merged, flow:done"
Agent: [Checks branch: feature/claude-tools-elf.6-delete-branches-worktrees]
[Checks PR: exists, merged]
[Asks user, user says yes]
[Closes task claude-tools-elf.6]
[Checks parent: has open children, skip]
[Runs bd sync]
You are on branch `feature/claude-tools-elf.6-delete-branches-worktrees`.
Delete branch and associated resources?
- Worktree: .worktrees/feature-claude-tools-elf.6-delete-branches-worktrees
- Local branch: feature/claude-tools-elf.6-delete-branches-worktrees
- Remote branch: origin/feature/claude-tools-elf.6-delete-branches-worktrees
(yes/no)
User: yes
Agent: [cd to main repo root]
[git worktree remove .worktrees/feature-...]
[git checkout master]
[git pull]
[git branch -d feature/claude-tools-elf.6-...]
[git push origin --delete feature/claude-tools-elf.6-...]
✓ Worktree removed
✓ Switched to master
✓ Local branch deleted
✓ Remote branch deleted
Done.
Correct because:
Agent: [Closes task]
[Runs bd sync]
[Immediately deletes branch and worktree]
Problem: Didn't ask before cleanup. User might want to keep the branch.
Agent: [On master branch]
[Closes task claude-tools-elf.6]
[Runs bd sync]
✓ Closed claude-tools-elf.6
✓ Synced with remote
Done.
Correct because: Branch "master" doesn't contain task ID "elf.6", so cleanup is silently skipped.
User: "flow:done"
Agent: [Closes task]
[Asks about parent, closes]
Done!
Problem: Skipped bd sync at end.
User: "flow:done"
Agent: [Checks branch]
[Closes task]
[Asks about parent, closes if yes]
[Runs bd sync]
✓ Synced with remote
Done.
Correct because:
Found 2 in_progress leaf tasks:
1. claude-tools-abc: Feature X
2. claude-tools-def: Feature Y
Which task is complete? (enter 1 or 2, or task ID)
No in_progress leaf tasks found.
Check task status with:
bd list --status=in_progress
Task description has Plan: docs/plans/old-plan.md
File does not exist on disk.
Plan file referenced in description not found: docs/plans/old-plan.md
(already deleted or moved)
Removing stale Plan: link from description.
Found multiple plan file candidates in docs/plans/:
1. quota-module-impl-plan.md (untracked)
2. quota-implementation-plan.md (untracked)
Which file is the implementation plan for this task? (1, 2, or "none")
Closed claude-tools-abc.2.1
Parent claude-tools-abc.2 now has all children closed.
Close it too? (yes/no)
[User: yes]
Closed claude-tools-abc.2
Parent claude-tools-abc now has all children closed.
Close it too? (yes/no)
[User: yes]
Closed claude-tools-abc
No more parents. Running bd sync...
Closed claude-tools-abc.1
Parent claude-tools-abc still has open children:
- claude-tools-abc.2 (open)
Not asking to close parent (has open children).
Running bd sync...
git worktree remove .worktrees/feature-claude-tools-abc-login
Error: '.worktrees/feature-claude-tools-abc-login' contains modified or
untracked files, use --force to delete.
⚠️ Worktree has uncommitted changes. You can:
- git worktree remove --force .worktrees/feature-...
- Or clean up manually later.
Continuing with branch deletion...
git push origin --delete feature/claude-tools-abc-login