Agent skill
worktree-cleanup
Remove merged or stale git worktrees. Use after PRs are merged, work is done, or when worktrees are no longer needed.
Install this agent skill to your Project
npx add-skill https://github.com/majiayu000/claude-skill-registry/tree/main/skills/development/worktree-cleanup
SKILL.md
Worktree Cleanup
Remove worktrees safely to free disk space and maintain organization.
When to Use
- PR has been merged
- Worktree no longer needed
- Free disk space
- Maintain clean worktree list
Quick Reference
# Remove single worktree by path
git worktree remove worktrees/ProjectOdyssey-42-feature
# Auto-clean all merged worktrees
./scripts/cleanup_merged_worktrees.sh
Workflow
- Verify state - Check no uncommitted changes:
cd worktrees/ProjectOdyssey-42 && git status - Commit changes - Make sure all changes are committed and the task is finished
- Switch away - Don't be in the worktree you're removing
- Remove worktree - Use git command
- Verify - Run
git worktree listto confirm removal
Safety Checks
Before removing a worktree:
- Branch is merged to main (check GitHub PR status)
- No uncommitted changes (run
git statusin worktree) - Not currently using the worktree (be in different directory)
- PR is actually merged (check "Development" section on issue)
Error Handling
| Error | Solution |
|---|---|
| "Worktree has uncommitted changes" | Commit changes |
| "Not a worktree" | Verify path with git worktree list |
| "Worktree is main" | Don't remove primary worktree |
Scripts Available
scripts/cleanup_merged_worktrees.sh- Auto-clean merged worktrees
References
- See
worktree-createskill for creating worktrees
Recommended Agent Skills
Expand your agent's capabilities with these related and highly-rated skills.
agent-ops-spec
Manage specification documents in .agent/specs/. Use when user provides requirements, acceptance criteria, or feature descriptions that need to be tracked and validated against implementation.
agent-ops-state
Maintain .agent state files. Use at session start, after meaningful steps, and before concluding: read/update constitution/memory/focus/issues/baseline consistently.
agent-ops-spec
Manage specification documents in .agent/specs/. Use when user provides requirements, acceptance criteria, or feature descriptions that need to be tracked and validated against implementation.
agent-ops-testing
Test strategy, execution, and coverage analysis. Use when designing tests, running test suites, or analyzing test results beyond baseline checks.
agent-ops-testing
Test strategy, execution, and coverage analysis. Use when designing tests, running test suites, or analyzing test results beyond baseline checks.
agent-ops-state
Maintain .agent state files. Use at session start, after meaningful steps, and before concluding: read/update constitution/memory/focus/issues/baseline consistently.
Didn't find tool you were looking for?