post-merge-cleanup
Use when the user asks to clean up, delete, or remove a merged feature branch. Delegates to the specialized branch-cleanup sub-agent to safely delete both local and remote branches after comprehensive validation (merge status, PR status, unpushed commits, uncommitted changes).
安装与使用
请根据来源仓库和你的 AI 工具说明安装此技能。先阅读技能文件和依赖要求,再添加到工作流。
查看来源 ↗使用指南技能说明
Post-Merge Cleanup Skill
This skill provides automated cleanup of merged feature branches with comprehensive safety validation.
When This Skill Activates
Use this skill when you detect the user wants to clean up a merged branch. Common trigger phrases:
- "Clean up after merge"
- "Delete merged branch"
- "Remove feature branch"
- "Post-merge cleanup"
- "Clean up my branch"
- "Delete the feature branch"
- "Cleanup after PR merge"
Key indicators:
- Mentions cleanup, delete, or remove
- References branch, merge, or PR completion
- Implies post-merge housekeeping
What This Skill Does
When activated, immediately delegate to the branch-cleanup sub-agent by using the Task tool:
Use the Task tool with:
- subagent_type: "branch-cleanup"
- description: "Clean up merged branch"
- prompt: "Clean up the current merged feature branch. Validate it's fully merged, then switch to main, pull latest changes, and delete both local and remote branches."
Why Delegate to Sub-agent?
The branch-cleanup sub-agent is specialized for this workflow and will:
- Detect the current feature branch
- Run comprehensive safety validations:
- ✅ Check for uncommitted changes
- ✅ Verify branch is merged to main
- ✅ Confirm GitHub PR is merged
- ✅ Ensure no unpushed commits
- Switch to main and pull latest
- Delete local feature branch
- Delete remote feature branch
- STOP if any validation fails 🛡️
User Experience
Before this skill:
User: "Switch to main, update it, then delete my feature branch"
Claude: [Runs commands manually without validation, may delete unmerged work]
With this skill:
User: "Clean up after merge"
Skill: [Auto-activates]
Sub-agent: [Validates thoroughly, then cleans up safely]
Result: ✅ Done automatically with comprehensive safety checks
Safety Features
The branch-cleanup sub-agent includes critical safety checks:
- Never deletes unmerged branches - Dual validation (git + GitHub)
- Prevents data loss - Checks for unpushed commits and uncommitted changes
- Protected branch detection - Never deletes main, master, develop, etc.
- Clear failure reporting - Shows exactly which validation failed and why
- Fail-fast behavior - Stops at first validation failure
Supporting Files
This skill directory includes:
-
SKILL.md(this file) - Skill definition and activation logic -
README.md- Detailed workflow documentation and examples
Configuration
No configuration required. The skill uses:
- Sub-agent:
branch-cleanup(must exist in ~/.claude/agents/) - Git commands for local validation
- GitHub CLI (
gh) for PR status validation - Remote:
origin(standard git remote name)
Troubleshooting
If the skill doesn't activate:
- Check that the user's message includes cleanup/delete + branch keywords
- Ensure the branch-cleanup sub-agent exists
- Verify you're in a git repository
If validation fails:
- The sub-agent will report exactly which check failed
- This is CORRECT behavior - it's protecting you from data loss
- Follow the sub-agent's recommendations to resolve the issue
If GitHub PR validation fails:
- Ensure
ghCLI is installed and authenticated - The sub-agent can fall back to git-only validation if needed
- Squash/rebase merges may show as unmerged in git (expected)
Edge Cases Handled
Squash/Rebase Merges
GitHub's squash and rebase merges don't preserve commits, so git may not recognize the branch as merged. The sub-agent will:
- Check GitHub PR status first
- If PR is merged but git doesn't show it, inform the user
- Recommend manual deletion with
-Dflag if confident
Remote Already Deleted
GitHub can auto-delete branches after merge. The sub-agent will:
- Skip or handle the "unpushed commits" validation gracefully
- Only delete the local branch
- Report that remote was already deleted
Protected Branches
If you're on main, master, develop, etc., the sub-agent will:
- Immediately refuse to proceed
- Explain it's a protected branch
- Suggest switching to a feature branch first
使用示例
查看来源仓库中的使用示例与配置说明。
查看来源 ↗来源历史
- 收录时间
- 2026-01-20
- 索引更新时间
- 2026-01-26
- Branch
- main
收录与同步日期属于本站记录。源码修改历史请查看来源仓库。
GitHub ↗chat Comments (0)
Sign in to join the discussion and leave a comment.
No comments yet. Be the first to share your thoughts!