clean-branches

$npx mdskill add kdlbs/kandev/clean-branches

Delete local branches whose remote has been deleted, including worktrees.

  • Cleans up stale local branches after merging PRs.
  • Depends on git commands: fetch, branch, worktree.
  • Identifies [gone] branches and associated worktrees via git branch -v.
  • Removes worktrees and deletes branches, reporting results.

SKILL.md

.github/skills/clean-branchesView on GitHub ↗
---
name: clean-branches
description: Delete local branches whose remote has been deleted ([gone]), including their worktrees. Use for branch cleanup after merging PRs.
---

# 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.

More from kdlbs/kandev

SkillDescription
acp-debugDebug an ACP agent CLI by spawning it, speaking raw JSON-RPC, and capturing every frame to a JSONL file. Use when the user asks to probe an agent's capabilities, compare agents, test a prompt against an agent, inspect raw ACP wire frames, or investigate why an agent fails to initialize.
add-integrationAdd a new third-party integration (Jira/Linear-style) — per-workspace credentials, 90s auth-health poller, settings page, link/import buttons. Use when scaffolding a new external service integration.
create-kandev-pluginCreate, modify, debug, test, package, or publish a Kandev runtime plugin in its dedicated repository. Use only when the requested work targets a Kandev plugin implementation or its release and marketplace lifecycle, including fixing a bug in an existing plugin. Do not use for agent skills, MCP servers, general integrations, or Kandev host, SDK, loader, and registry changes that do not also change a plugin.
docs-maintainerKeep public Kandev docs current when code or behavior changes affect CLI commands, config keys, install/deploy flows, workflows, executors, APIs, screenshots, or user-facing terminology. Use this before finishing any change with public documentation impact, and when reviewing whether a change needs docs.
harness-improvementImprove Kandev's AI harness from session learnings or explicit requests. Use when the user asks to record learnings, update or create skills, agents, subagents, commands, AGENTS.md/CLAUDE.md guidance, or adapt harness files across Claude, Codex, Cursor, or OpenCode.
kandev-approvalsClear the CEO approval queue when hire requests, budget grants, or other sensitive Office mutations are waiting for approve or reject decisions.
kandev-config-syncSynchronize Office workspace configuration with the .kandev folder when exporting reviewable config, importing committed config, seeding a workspace, or reviewing a config diff.
kandev-escalationEscalate to a human when required information, access, credentials, or a product decision blocks completion and no reasonable default is available.
kandev-projectsList and create Office projects, then place new tasks in the correct project when organizing workspace work by repository.
kandev-protocolFollow the core Office agent protocol on wakeup, including parsing KANDEV_* context, checking blockers, commenting progress, updating status, and using the CLI safely.