一键导入
speckit-worktree-clean
Remove stale or merged worktrees and reclaim disk space
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
菜单
Remove stale or merged worktrees and reclaim disk space
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
基于 SOC 职业分类
Think before building. Use when the user asks to reason about, analyze, evaluate, compare options, make an architecture decision, choose between approaches, think through a problem, or assess trade-offs. Also use when the user asks 'why did we...', 'should we...', 'what are our options', 'is this the right approach', or wants to frame/reframe a problem.
Archive a feature specification into main project memory after merge, resolving gaps and conflicts
Generate spec-kit configuration tailored to the existing codebase
Incrementally adopt SDD for existing features with reverse-engineered specs
Auto-discover project structure, tech stack, frameworks, and architecture patterns
Verify bootstrap output matches actual project structure and conventions
| name | speckit-worktree-clean |
| description | Remove stale or merged worktrees and reclaim disk space |
| compatibility | Requires spec-kit project structure with .specify/ directory |
| metadata | {"author":"github-spec-kit","source":"worktree:commands/speckit.worktree.clean.md"} |
Remove worktrees for branches that have been merged or are no longer needed. Safely cleans up .worktrees/ directory entries and reclaims disk space.
$ARGUMENTS
You MUST consider the user input before proceeding (if not empty). The user may specify a branch name to clean (e.g., "005-api-gateway"), "merged" to clean all merged worktrees, or "all" to clean everything.
.specify/ directory.worktrees/ directory exists and contains worktreesScan worktrees: List all worktrees and classify them:
Build cleanup plan: Based on user input, determine what to remove:
| User Input | Action |
|---|---|
| Specific branch name | Remove that worktree only (with confirmation) |
merged | Remove all merged worktrees |
stale | Remove all stale worktrees (30+ days inactive) |
all | Remove all worktrees except main (with strong warning) |
| No input | Remove merged and orphaned only (safest default) |
Present cleanup plan: Show a preview before making any changes:
# Worktree Cleanup Plan
| # | Branch | Status | Action | Disk Size |
|---|--------|--------|--------|-----------|
| 1 | 005-api-gateway | ✅ Merged | Remove | ~45 MB |
| 2 | 002-old-feature | ❌ Orphaned | Remove | ~32 MB |
| 3 | 004-chat-system | 🟡 Idle | Keep (not merged) | ~41 MB |
**Will remove**: 2 worktrees (~77 MB)
**Will keep**: 1 worktree
Confirm with user: Ask for explicit confirmation before proceeding. Removing worktrees with uncommitted changes is destructive.
Check for uncommitted changes: Before removing each worktree:
git -C .worktrees/{branch}/ status --porcelain to check for uncommitted workExecute cleanup: For each worktree to remove:
git worktree remove .worktrees/{branch-name} to safely removegit worktree unlock .worktrees/{branch-name} first.worktrees/ directorygit worktree prune after all removals to clean up stale referencesReport: Output a summary:
.worktrees/git worktree prune to clean up stale administrative files