workflow-cleanup-merged

Clean up local worktrees and merged branches after a GitHub PR.

2|8|Updated Apr 20, 2026
One-click install
npx skills add https://github.com/lugassawan/swe-workbench --skill workflow-cleanup-merged
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: workflow-cleanup-merged
Source: https://github.com/lugassawan/swe-workbench/tree/main/skills/workflow-cleanup-merged
Command: npx skills add https://github.com/lugassawan/swe-workbench --skill workflow-cleanup-merged

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes scripts (resource) components.

What problem does it solve?

Cleaning up after a merged GitHub PR often leaves behind stale worktrees and both local and remote branches, wasting disk space and confusing future work; this skill performs that cleanup safely and correctly.

Core Features & Use Cases

  • PR-merged verification using GitHub CLI: Confirms the PR is truly in the MERGED state (and reads mergedAt) before deleting anything, avoiding false positives caused by squash merges.
  • Worktree + branch cleanup with safety contracts: Frees the session from active worktrees, syncs local default branch with fast-forward only, and removes the merged branch and its remote counterpart.
  • Multiple removal strategies with robust fallbacks: Uses a rimba post-merge hook fast path when active, otherwise tries rimba removal, and finally falls back to a shell-based probe and git worktree remove with dirty/unpushed safeguards.

Quick Start

Invoke the workflow by running /swe-workbench:cleanup-merged after your PR is confirmed merged on GitHub, optionally providing the PR number.

Frequently Asked Questions about workflow-cleanup-merged

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I safely clean up local worktrees and branches after a GitHub PR is merged?

To safely clean up merged PR branches, you can use a workflow that verifies the GitHub PR merge state via gh CLI, syncs the default branch, and then removes local worktrees alongside local and remote branches.

Why does my branch cleanup script delete branches after a squash merge?

Squash merges can cause false positives in branch cleanup. To ensure squash-merge safety, this workflow verifies the PR state is MERGED and mergedAt is non-null via the GitHub CLI, deliberately avoiding git merge-ancestor checks.

What is the best way to delete stale git worktrees without losing unpushed changes?

The best way to delete stale git worktrees safely is using a staged deletion process. It uses a rimba hook fast path, with rimba and shell fallbacks applying git worktree remove with dirty and unpushed safeguards.

Does this branch cleanup workflow require the GitHub CLI to verify PR merges?

Yes, the branch cleanup workflow requires the GitHub CLI (gh) to verify PR merges. It confirms the PR is in the MERGED state and reads the mergedAt timestamp before proceeding with any local or remote branch deletion.

Can I fast-forward sync my local default branch while cleaning up merged PR branches?

Yes, you can fast-forward sync your local default branch during cleanup. The workflow syncs the local default branch with a fast-forward only strategy while removing the merged branch and its remote counterpart.