Skip to main content
command CX Codex

clean-branches — Claude Code command: delete merged and stale branches

clean-branches — a command that systematically removes merged and inactive branches from Git. Keeps your repository clean by deleting obsolete branches and syncing local state with the remote.

no license ★ 1,357 updated 2026-03-01

Install into Claude Code · Manually: put the files in place All methods and platforms ↓
.claude/commands/clean-branches.md
Open on GitHub

What clean-branches does

clean-branches runs a complete branch audit: checks repository state, identifies the default branch, finds branches merged into main, and locates stale branches with no recent activity. It works step by step, analyzing first and asking for confirmation before deletion, making it safe to remove both local and remote-tracking branches.

The command uses standard Git tools: git branch --merged to find merged branches, git for-each-ref to analyze by commit date, and git remote prune to sync remote-tracking references. A built-in script protects critical branches—main, master, develop, staging, production—so they stay untouched.

It supports interactive mode with confirmation before each deletion, shows unmerged changes on a branch before removing it, and logs which branches were cleaned. If uncommitted changes exist, the command stashes them first.

What it helps with

  • Delete branches that have been merged into main
  • Remove stale branches inactive for more than thirty days
  • Sync local remote-tracking branches with the remote server
  • Prevent accidental deletion of critical branches
  • Generate a report of deleted branches

Example prompts for the agent

  • Clean up merged branches and synchronize the local repository state
  • Find and remove branches with no updates in the last month
  • Delete the feature/old-feature branch and sync with origin

How to install clean-branches

Manually: put the files in place

.claude/commands/clean-branches.md

Call it with /clean-branches. For all projects use ~/.claude/commands/

Questions about clean-branches

How do I install clean-branches in Claude Code?

Save the command file to .claude/commands/clean-branches.md. Claude Code will pick it up automatically when you load the project.

What does clean-branches do?

It scans your Git branches, identifies those merged into main and abandoned ones, removes them after verification, and syncs local state with the remote.

Which branches are protected from deletion?

The branches main, master, develop, staging, and production are protected and will not be deleted even if they are merged elsewhere.

Similar slash commands

All slash commands for Git and GitHub →
clean_gone official Anthropic clean_gone — a Claude Code command that removes local git branches flagged as [gone] — branches whose remote counterpart no longer exists. It also clears out any attached worktrees before deletion. CX Codex +1 ★ 47,914repo stars github-workflow transilienceai The github-workflow skill brings GitHub operations to your AI assistant: branches, commits, pushes, pull requests, issues, and code review. Handy when you ask your agent to commit changes, push code, create a PR, or manage branches. CX Codex +1 195installs worktree FlorianBruniaux Creates a separate git worktree folder for feature or fix branches. Useful when you need to work on multiple tasks in parallel without conflicts in your main branch. CX Codex +1 ★ 6,529repo stars update-branch-name giselles-ai update-branch-name — a Claude Code plugin that renames Git branches by adding semantic prefixes and enforcing naming conventions. Use it when your team requires branches to follow a specific format like feature/, bugfix/, or hotfix/. ★ 1,013repo stars speckit-git-feature spec-kit-core speckit-git-feature is a Claude Code skill that creates a Git branch from a task description within a Spec Kit project and reads its configuration. CX Codex +1 ★ 110repo stars new-branch-and-pr cursor new-branch-and-pr — a skill for Claude Code, Codex, Cursor, GitHub Copilot, Gemini CLI and OpenCode that runs a task through a full branch-and-PR cycle without manual steps. CX Codex +1 2,300installs

From the same set112

The whole set →
todo-branch todo-branch executes backlog items on your active Git branch through guided phases, step-by-step approvals, and a single final commit. CX Codex +1 ★ 1,357repo stars graphql-architect The graphql-architect subagent designs and improves GraphQL APIs, covering schemas, resolvers, federation, and subscriptions. Use it for new APIs, performance audits, or refactoring. CX Codex ★ 1,357repo stars bidirectional-sync bidirectional-sync — a slash command that pairs GitHub issues with Linear tasks and copies edits both ways, settling the ones that landed on both sides. CX Codex +1 ★ 1,357repo stars dx-optimizer dx-optimizer configures developer environments, project automation scripts, and Git hooks to eliminate workflow friction and speed up onboarding. CX Codex ★ 1,357repo stars performance-engineer performance-engineer is a Claude Code subagent for finding performance bottlenecks and planning optimization work. It joins tasks involving scalability, profiling, or load testing. CX Codex ★ 1,357repo stars semantic-architect semantic-architect is a Claude Code subagent that organizes dialogue context into tree structures and preserves persistent memory across sessions. CX Codex ★ 1,357repo stars golang-pro golang-pro — a Go-focused subagent for architecture, implementation, refactoring, concurrency, APIs, testing, and performance work in Claude Code. CX Codex ★ 1,357repo stars architect-reviewer architect-reviewer — a Claude subagent that reads a change for architectural fit: patterns, SOLID, dependency direction. Useful after structural edits or a new service. CX Codex ★ 1,357repo stars

Project sponsors

Companies that keep this analytics open