Skip to main content
skill CX Codex

clean-branches — Claude Code skill: tidy up your git branches

A skill that walks your local git branches, finds merged and orphaned ones, and deletes them one at a time with a closing report.

Install into Claude Code · Skills CLI (Vercel) All methods and platforms ↓
npx skills add dyoshikawa/rulesync --skill clean-branches -a claude-code
Open on GitHub

What clean-branches does

The skill runs in five steps. It starts by reading the current state: git branch --show-current, the branch list, git remote show origin and git branch -vv. From that it picks out the current branch, the default branch and any branch whose upstream is gone. Merged branches come from git branch --merged <default-branch>.

Next it refreshes remote refs with git fetch --prune, and git remote prune origin when needed. Deletion is limited to branches that are clearly done: merged into the default branch, or left without an upstream. The current and default branches are off limits, and unmerged ones only go after you approve force deletion with git branch -D. Anything ambiguous gets shown to you first.

Branches are removed one by one, never through a broad wildcard. The wrap-up lists what was deleted, what was skipped and why, and whether stale remote-tracking branches were pruned. Worth installing if merges have left you with a pile of branches and no appetite to sort them by hand.

What it helps with

  • drop local branches already merged into main
  • clear out branches whose upstream was deleted
  • refresh remote refs and prune vanished branches
  • get a report of what was deleted and what was skipped
  • delete branches one at a time instead of one wide command

Example prompts for the agent

  • clean up the local branches in this repo
  • remove merged branches and prune the remote ones
  • list the branches you'd delete and ask me first

How to install clean-branches

1Skills CLI (Vercel)

npx skills add dyoshikawa/rulesync --skill clean-branches -a claude-code

2Manually: put the files in place

~/.claude/skills/clean-branches/SKILL.md

Copy the whole skill folder; for one project use .claude/skills/clean-branches/

Step by step, with commands for each platform: How to install skills in Claude Code: five ways

Questions about clean-branches

How do I install clean-branches in Claude?

Run npx skills add dyoshikawa/rulesync --skill clean-branches -a claude-code. The skill lands in ~/.claude/skills/clean-branches/SKILL.md.

What does clean-branches do?

It finds local branches merged into the default branch plus branches with a deleted upstream, then deletes them one by one. It also runs git fetch --prune and reports back.

Will it delete a branch with unmerged work?

Unmerged branches are only touched after you explicitly approve force deletion, and then via git branch -D. The current and default branches are never deleted.

Source text

SKILL.md · MIT
---
name: clean-branches
description: Clean up unnecessary local branches and prune stale remote-tracking branches
targets:
  - "*"
---

# Clean Branches

Clean up unnecessary local branches and prune stale remote-tracking branches.

## Step 1: Inspect Current State

Run the following:

- `git branch --show-current`
- `git branch --format='%(refname:short)'`
- `git remote show origin`
- `git branch -vv`

Identify:

- The current branch
- The default branch (for example `main` or `master`)
- Branches whose upstream has been deleted

After identifying the default branch, list branches already merged into it:

- `git branch --merged <default-branch>`

If you want to use the remote-tracking branch as the source of truth, use:

- `git branch --merged origin/<default-branch>`

## Step 2: Refresh Remote State

Update remote refs and prune deleted remote branches:

```bash
git fetch --prune
```

If needed, also run:

```bash
git remote prune origin
```

## Step 3: Select Branches to Delete

Delete only branches that are clearly unnecessary.

Safe candidates include:

- Local branches already merged into the default branch you identified above
- Local branches whose upstream branch is gone and are no longer needed

Never delete:

- The current branch
- The default branch
- Branches that are not fully merged unless the user explicitly asks for force deletion

If there is any ambiguity, show the candidate branches to the user and ask for confirmation.

## Step 4: Delete Branches

For merged branches, delete them safely:

```bash
git branch -d <branch-name>
```

Only if the user explicitly approves force deletion for unmerged branches, use:

```bash
git branch -D <branch-name>
```

Delete branches one by one, not with a broad wildcard command.

## Step 5: Report Result

Summarize:

- Which branches were deleted
- Which branches were skipped and why
- Whether stale remote-tracking branches were pruned

© dyoshikawa · MIT · dyoshikawa/rulesync

Similar skills

All skills for Git and GitHub →

From the same set11

rebase-latest-main A skill that walks the agent through fetching origin/main, rebasing the current branch and resolving conflicts. Handy when your branch has drifted behind main. CX Codex +1 ★ 1,552repo stars prs-awaiting-author Lists open pull requests where the next move belongs to the author: failing CI, unaddressed review comments, or a maintainer question waiting on a reply. CX Codex +1 ★ 1,552repo stars porting-another-repository Reads a feature in your current repo and the target repo's conventions, then writes a porting plan into tmp/ as files you apply yourself. CX Codex +1 ★ 1,552repo stars goal-release Drives a release end to end: opens the PR, waits for green CI, merges it and updates the Homebrew formula. Handy when a version has to ship in one go. CX Codex +1 ★ 1,552repo stars git-worktree-runner A skill that teaches the agent to drive git worktrees through the gtr CLI: create, open in an editor, run commands, remove. CX Codex +1 ★ 1,552repo stars draft-issue-to-external-repository Drafts a GitHub issue for a repository you do not own: reads the project's templates and title style, settles scope with you, and saves the body to a file. CX Codex +1 ★ 1,552repo stars create-issue A skill that walks through issue creation step by step: gathers context, checks the codebase, drafts English text, and assigns labels. Handy when you want a tidy issue without doing it manually. CX Codex +1 ★ 1,552repo stars batch-all-issues A skill that walks every open issue one at a time: fact-checks each with web research, closes the ones needing no action, and drives the rest to merge. CX Codex +1 ★ 1,552repo stars

Project sponsors

Companies that keep this analytics open
Gold sponsor

Impressions, clicks and code copies — open statistics. We keep the numbers public for the same reason NeBlask itself is public. Become a sponsor