Clean Branches

SkillDev tools

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

Available today. Use it from your connected AI after setup.

Connect ahel once, and every AI you use reads what you have installed.

Then ask your AI: use the Clean Branches skill

What this skill tells your AI

The instructions your AI receives, as published by kdlbs/kandev in .agents/skills/clean-branches/SKILL.md and read by ahel’s review.

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

Steps

  1. Fetch and prune remote refs:

    git fetch --prune
    
  2. List branches to identify [gone] status:

    git branch -v
    

    Branches with a + prefix have associated worktrees that must be removed before deletion.

  3. List worktrees for reference:

    git worktree list
    
  4. Remove worktrees and delete [gone] branches:

    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.

Signals

GitHub stars
771
Forks
114
Last commit
Sep 2026
Advanced
Catalog kind
skill
Gateway key
clean-branches
Source
github.com/kdlbs/kandev