Manual trigger: execute when the user explicitly requests cleaning up, deleting, or reclaiming long-unused worktrees.
Prerequisites
Must be executed on master: before execution git branch --show-current; if not master, abort and prompt the user to switch.
Workflow
Step 1: Select cleanup time range
Use AskQuestion to let the user choose a threshold:
- Prompt:
选择清理阈值:超过多久未使用的 worktree 将被清理? - Options:
1 周(corresponds to 7 days)2 周(corresponds to 14 days)1 个月(corresponds to 30 days)
Map the user's choice to days:
| Option | Days |
|---|---|
| 1 week | 7 |
| 2 weeks | 14 |
| 1 month | 30 |
Step 2: Preview expired Worktrees
Run the cleanup script to output a list of candidate branch names (one branch name per line), without performing deletion.
Select the script based on the operating system (via the OS Version in the user information):
Windows(PowerShell):
powershell -File .cursor/skills/cleanup-github-worktree/scripts/cleanup-worktree.ps1 -Days <天数>
macOS / Linux(Bash):
bash .cursor/skills/cleanup-github-worktree/scripts/cleanup-worktree.sh -d <天数>
Display the list of branch names output by the script to the user. If no expired worktrees are found, inform the user and end.
Step 3: User confirmation
Use AskQuestion to let the user confirm whether to continue:
- Prompt:
以上 <N> 个 worktree 将被清理(关闭 GitHub Issue、移除 worktree、删除本地分支),是否继续? - Options:
确认清理取消
When the user chooses to cancel, end the workflow.
Step 4: Batch execute close-github-worktree-done
For theeach candidate branchidentified in Step 2, use that branch name as the target branch and execute the close-github-worktree-done skill's Step 1 ~ Step 5 full process (skipping its Step 0 interactive selection).
- In batch scenarios, Step 3 closing the Issue can by default directly close the
openstatus (state=closed, state_reason=completed), without needing to AskQuestion again for each one; those alreadyclosedare skipped. - Branches with uncommitted changes: skip according to
close-github-worktree-doneStep 2 rules, and mark as "skipped (has uncommitted changes)" in the final report. - Failure to process a single branch does not interrupt the whole batch; continue processing the next one.
Step 5: Summary report
Show the user a summary of the cleanup results, including the processing status of each branch:
| Branch name | GitHub Issue | worktree | Local branch | Notes |
|---|---|---|---|---|
| bug-12994 | ✅ closed | ✅ Removed | ✅ Deleted | |
| feat-11524 | ⏭ Skipped | ✅ Removed | ✅ Deleted | Branch name has no issue number |
| pref-12948 | — | — | — | Skipped (has uncommitted changes) |
Script description
| Script | System | Path |
|---|---|---|
| cleanup-worktree.ps1 | Windows | .cursor/skills/cleanup-github-worktree/scripts/cleanup-worktree.ps1 |
| cleanup-worktree.sh | macOS/Linux | .cursor/skills/cleanup-github-worktree/scripts/cleanup-worktree.sh |
Script responsibilities:
- Via
git worktree list --porcelainget all worktrees - Skip the main worktree (the first one) and bare entries
- Via
git log -1 --format=%ct <branch>get the branch's last commit time; for detached HEAD, fall back to the directory modification time - Filter entries exceeding the threshold,Output only the list of candidate branch names(one per line), for parsing by Step 2 of this skill