clean-branches

Delete local branches whose remote has been deleted ([gone]), including their worktrees. Use for branch cleanup after merging PRs.

40 stars

Best use case

clean-branches is best used when you need a repeatable AI agent workflow instead of a one-off prompt.

Delete local branches whose remote has been deleted ([gone]), including their worktrees. Use for branch cleanup after merging PRs.

Teams using clean-branches should expect a more consistent output, faster repeated execution, less prompt rewriting.

When to use this skill

  • You want a reusable workflow that can be run more than once with consistent structure.

When not to use this skill

  • You only need a quick one-off answer and do not need a reusable workflow.
  • You cannot install or maintain the underlying files, dependencies, or repository context.

Installation

Claude Code / Cursor / Codex

$curl -o ~/.claude/skills/clean-branches/SKILL.md --create-dirs "https://raw.githubusercontent.com/kdlbs/kandev/main/.agents/skills/clean-branches/SKILL.md"

Manual Installation

  1. Download SKILL.md from GitHub
  2. Place it in .claude/skills/clean-branches/SKILL.md inside your project
  3. Restart your AI agent — it will auto-discover the skill

How clean-branches Compares

Feature / Agentclean-branchesStandard Approach
Platform SupportNot specifiedLimited / Varies
Context Awareness High Baseline
Installation ComplexityUnknownN/A

Frequently Asked Questions

What does this skill do?

Delete local branches whose remote has been deleted ([gone]), including their worktrees. Use for branch cleanup after merging PRs.

Where can I find the source code?

You can find the source code on GitHub using the link provided at the top of the page.

SKILL.md Source

# Clean Branches

Remove local branches that have been deleted on the remote (marked `[gone]`), including any associated git worktrees.

## Steps

1. **Fetch and prune remote refs:**
   ```bash
   git fetch --prune
   ```

2. **List branches to identify [gone] status:**
   ```bash
   git branch -v
   ```
   Branches with a `+` prefix have associated worktrees that must be removed before deletion.

3. **List worktrees for reference:**
   ```bash
   git worktree list
   ```

4. **Remove worktrees and delete [gone] branches:**
   ```bash
   git branch -v | grep '\[gone\]' | sed 's/^[+* ]//' | awk '{print $1}' | while read branch; do
     echo "Processing branch: $branch"
     worktree=$(git worktree list | grep "\\[$branch\\]" | awk '{print $1}')
     if [ ! -z "$worktree" ] && [ "$worktree" != "$(git rev-parse --show-toplevel)" ]; then
       echo "  Removing worktree: $worktree"
       git worktree remove --force "$worktree"
     fi
     echo "  Deleting branch: $branch"
     git branch -D "$branch"
   done
   ```

5. **Report** which branches and worktrees were removed. If none were `[gone]`, say no cleanup was needed.

Related Skills

verify

40
from kdlbs/kandev

Run format, typecheck, test, and lint across the monorepo. Use after implementing changes.

tdd

40
from kdlbs/kandev

Implement changes using Test-Driven Development (Red-Green-Refactor). Use for bug fixes, new features, or any code change that should have test coverage.

spec

40
from kdlbs/kandev

Write a feature spec — the "what & why" of a kandev product feature, before coding. Use when the user says "let's spec X" or starts a new product feature.

simplify

40
from kdlbs/kandev

Simplify recently changed code — inline one-off abstractions, remove speculative code, reduce nesting, replace cleverness with clarity. Run after implementing a feature.

record

40
from kdlbs/kandev

Record an architectural decision (ADR) or save an implementation plan. Use after making significant design choices or completing features.

qa

40
from kdlbs/kandev

Verify a feature works after implementation. Actively try to break it — edge cases, error paths, integration wiring, and real usage flows.

push

40
from kdlbs/kandev

Commit and push to the current branch. Use --fixup to also wait for CI/CodeRabbit and fix issues.

pr

40
from kdlbs/kandev

Commit, push, and create a PR. Default is ready-for-review with auto-fixup. Use --draft to skip review/fixup.

pr-fixup

40
from kdlbs/kandev

Wait for CI checks and automated reviews (CodeRabbit, Greptile, Claude) on a PR, fix failures and address comments, then push.

playwright-cli

40
from kdlbs/kandev

Automate browser interactions, test web pages and work with Playwright tests.

fix

40
from kdlbs/kandev

Fix bugs and issues — reproduce, find root cause, minimal fix with regression test. Use when something is broken.

feature

40
from kdlbs/kandev

Guided feature development — brainstorm, explore codebase, design architecture, implement with TDD, and review. Use for new features or significant changes.