git-cleanup

Sweep merged branches, orphaned worktrees, and dead upstream tracking from a git repository.

Updated Jun 6, 2026
One-click install
npx skills add https://github.com/hacker-cb/claude-code-plugins --skill git-cleanup-hacker-cb
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: git-cleanup
Source: https://github.com/hacker-cb/claude-code-plugins/tree/main/plugins/hcb-dev/skills/git-cleanup
Command: npx skills add https://github.com/hacker-cb/claude-code-plugins --skill git-cleanup-hacker-cb

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes scripts (resource) and references (resource) components.

What problem does it solve? Long-running repositories accumulate merged branches, stale worktrees, and dead upstream tracking that clutter the workspace and make it hard to tell what work is still live. This Skill audits that residue safely, proving each branch's work actually landed before anything is deleted. ## Core Features & Use Cases - Two sweep modes: session removes only what the current session created before closing it; all audits everything the repository has accumulated, including other sessions' leftovers. - Proof-based deletion: branches are deleted only when containment in the default branch or a forge-confirmed merge (including squash merges via gh/glab) proves the work landed; anything unproven is surfaced, not removed. - Risk-classed approval gate: every action is classified as nothing-lost, recoverable, or irreversible, and irreversible deletions always require explicit user confirmation with restore commands shown. - Use Case: Before closing a long Claude Code session, run the session sweep to delete the branches and worktrees it created, verifying each against the default branch and open pull requests first. ## Quick Start Run the git-cleanup skill with the argument "session" to remove the branches and worktrees this session created.

Frequently Asked Questions about git-cleanup

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

FAQPage Schema
How do I clean up merged git branches safely?▼

Run the sweep in `all` mode: it classifies every branch by whether its work is proven landed via git containment or a forge-confirmed merge, then deletes only proven branches after you approve the plan. Unproven branches are surfaced for your decision, never deleted.

How to remove stale git worktrees without losing work?▼

The sweep cross-checks each worktree against live session ownership and git state before removal. Dirty worktrees, submodule-containing trees, and paths that no longer answer on disk are classed irreversible and always require explicit confirmation.

Does git branch cleanup detect squash-merged pull requests?▼

Yes. A squash merge is invisible to plain git containment checks, so the scan queries the forge CLI (`gh` or `glab`) for merge commits the default branch carries. If the forge does not answer, the sweep narrows rather than deletes.

Can it delete remote branches or push to the remote?▼

No. The forge CLI is kept strictly read-only: it reads merged and open change requests but never pushes, deletes remote branches, or merges, closes, or edits any PR/MR. All deletions are local branches and worktrees only.

Why does the cleanup refuse to remove a worktree Claude Code created?▼

Claude Code leases worktrees to sessions that outlive their processes, and that lease is unreadable from inside the repository. The skill reports such worktrees instead of removing them, since git alone cannot prove no live session is using them.