Skip to main content
command official · Anthropic

clean_gone — Claude Code command: branch cleanup and install

Finds local Git branches marked [gone], removes their associated worktrees, then deletes the branches. Use it to clear local branches whose remote copies are gone.

Install into Claude Code · Plugin marketplace All methods and platforms ↓
/plugin install commit-commands@claude-plugins-official
Open on GitHub

What clean_gone does

The command checks branch status with git branch -v and lists worktrees with git worktree list. For each [gone] branch, it removes an associated worktree if one exists, then deletes the branch with git branch -D. The agent reports what it removed; if there are no matching branches, it reports that no cleanup was needed.

Branch deletion is forced. Check the [gone] branch list before running it: every match is deleted, and associated worktrees are removed with --force. To install it in Claude Code, install commit-commands@claude-plugins-official and add .claude/commands/clean_gone.md.

What it helps with

  • find local branches marked [gone]
  • remove worktrees attached to stale branches
  • delete local branches whose remote copies were removed
  • check whether stale branch cleanup is needed

Example prompts for the agent

  • Run clean_gone and remove local branches marked [gone].
  • Check for worktrees tied to [gone] branches and delete them with the branches.
  • Find any [gone] branches and clean them up if present.

How to install clean_gone

1Plugin marketplace

/plugin install commit-commands@claude-plugins-official

2Manually: put the files in place

.claude/commands/clean_gone.md

Call it with /clean_gone. For all projects use ~/.claude/commands/

Questions about clean_gone

How do I install clean_gone in Claude Code?

Run /plugin install commit-commands@claude-plugins-official, then add .claude/commands/clean_gone.md.

What does clean_gone do?

It finds local branches marked [gone], removes their associated worktrees, and then deletes the branches.

How does clean_gone handle associated worktrees?

It checks the worktree list and runs git worktree remove --force for a worktree tied to a matching branch before deleting that branch.

Source text

clean_gone.md · Apache-2.0
---
description: Cleans up all git branches marked as [gone] (branches that have been deleted on the remote but still exist locally), including removing associated worktrees.
---

## Your Task

You need to execute the following bash commands to clean up stale local branches that have been deleted from the remote repository.

## Commands to Execute

1. **First, list branches to identify any with [gone] status**
   Execute this command:
   ```bash
   git branch -v
   ```
   
   Note: Branches with a '+' prefix have associated worktrees and must have their worktrees removed before deletion.

2. **Next, identify worktrees that need to be removed for [gone] branches**
   Execute this command:
   ```bash
   git worktree list
   ```

3. **Finally, remove worktrees and delete [gone] branches (handles both regular and worktree branches)**
   Execute this command:
   ```bash
   # Process all [gone] branches, removing '+' prefix if present
   git branch -v | grep '\[gone\]' | sed 's/^[+* ]//' | awk '{print $1}' | while read branch; do
     echo "Processing branch: $branch"
     # Find and remove worktree if it exists
     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
     # Delete the branch
     echo "  Deleting branch: $branch"
     git branch -D "$branch"
   done
   ```

## Expected Behavior

After executing these commands, you will:

- See a list of all local branches with their status
- Identify and remove any worktrees associated with [gone] branches
- Delete all branches marked as [gone]
- Provide feedback on which worktrees and branches were removed

If no branches are marked as [gone], report that no cleanup was needed.

© Anthropic · Apache-2.0 · anthropics/claude-plugins-official

Similar slash commands

All slash commands for Git and GitHub →

From the same set123

The whole set →

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