Clean Branches logo

Clean Branches

Community
gupsammy
clean-branches

This skill should be used when the user says "clean up branches", "delete merged branches", or "prune stale branches". Use whenever the user mentions branch cleanup, pruning, or stale branch deletion — even if they don't say "clean-branches" explicitly.

Overview

Publishergupsammy
RepositoryClaudest
Skill nameclean-branches
Stars
275
Forks
16
Bundled files
1
Links
  • Markdown instructions

    A SKILL.md file the model loads on demand, so it only costs tokens when a request actually matches.

  • Works with any LLM

    AI skills are plain Markdown, not provider-specific code, so this works with GPT, Claude, Gemini, Grok, or a local model.

  • 1 bundled files

    Scripts, templates, and references the model can read while it works. Files are read-only and never executed.

  • Open source

    Published by gupsammy on GitHub. Read the source before you install it.

Installation

Install the Clean Branches AI skill in TypingMind to use it with any LLM, or drop it into another agent that reads SKILL.md.

1

Install in TypingMind

TypingMind installs a skill straight from its GitHub folder — it reads SKILL.md, bundles the resource files, and stores the result locally.

  1. Open the app and go to Plugins → Skills.
  2. Choose "Install from GitHub".
  3. Paste the skill folder URL below and confirm.
    https://github.com/gupsammy/Claudest/tree/main/plugins/claude-coding/skills/clean-branches
  4. Enable the skill in any chat where you want it available.
Plugins → Skills → Add skill → From GitHub URL, then paste the folder URL and press Continue.
2

Install in another agent

Any agent that reads the Agent Skills format can use this skill — copy the folder into that agent's skills directory.

Claude Code — .claude/skills
git clone --depth 1 https://github.com/gupsammy/Claudest.git /tmp/Claudest
mkdir -p .claude/skills
cp -r /tmp/Claudest/plugins/claude-coding/skills/clean-branches .claude/skills/clean-branches
Restart Claude Code after copying so it picks up the new skill.

Use it in TypingMind

Enable Clean Branches in any TypingMind chat and the model takes it from there. Its name and description sit in the system prompt, and the moment a request matches, the model loads the full instructions itself — you never invoke it by hand, and it costs no tokens until it is actually used.

The model loads Clean Branches on its own as soon as a request matches it.

Works with any AI model

AI skills are plain Markdown instructions rather than provider-specific code, so Clean Branches is not tied to the model it was written for. Install it once in TypingMind and use it with GPT-5, Claude, Gemini, Grok, DeepSeek, Mistral, Llama, or a local model you run yourself — all on your own API keys.

  • Loaded only when it is needed

    The system prompt carries just the name and description. The instructions are fetched on the first matching request, so an idle skill costs nothing.

  • Switch models mid-chat

    Because the skill is instructions rather than code, changing model does not break it — the next model reads the same SKILL.md.

Skill instructions

This is the SKILL.md content the model loads. Read it before installing — a skill is instructions your model will follow.

Clean Git Branches

Safely remove merged and stale git branches with confirmation.

Process

If $ARGUMENTS is provided, treat it as a glob pattern to filter branch candidates (e.g., feature/*) and pass it to the candidate script in Step 1.

1. Fetch latest state

bash
git fetch --all --prune

If fetch fails (no remotes configured), note remote data is unavailable and continue with local analysis only.

2. Identify candidates

Run the candidate detection script, passing the optional pattern filter:

bash
bash ${CLAUDE_PLUGIN_ROOT}/skills/clean-branches/scripts/find-candidates.sh "$PATTERN"

The script outputs two labeled sections (=== MERGED === and === STALE ===), one branch per line. Branches carry two optional annotations:

  • [worktree:/path/to/wt] — branch is checked out in a worktree
  • [squash-merged] — branch was merged via squash or rebase PR; git does not recognize it as merged locally (requires force-delete in Step 5)

Parse each section into its own list, preserving both annotations.

After parsing, apply these worktree rules before building the candidate lists. Process the MERGED list first, then the STALE list — a branch that appears in both (merged AND older than 30 days) is governed by the MERGED rule only; skip it when processing STALE.

  • Stale branch + active worktree → move immediately to the blocked list, regardless of worktree state. A stale branch with a live worktree may still have in-progress work — never offer it for cleanup. Skip branches already classified as merged.
  • Merged branch + active worktree → check whether the worktree is clean:
    bash
    git -C /path/to/wt status --porcelain
    If the command returns any output (uncommitted changes), move to the blocked list. If clean, keep in the merged candidate list with the worktree annotation.

3. Present results

Display branches in four groups:

  • Merged (safe to delete) — branches fully merged into base; those with a clean worktree show "(+ worktree at /path)"
  • Stale (no recent commits, no active worktree) — only branches without a worktree appear here
  • Protected (never touch) — main, master, develop, release/*
  • Blocked — branches skipped because they have an active worktree with uncommitted work, or are stale with any active worktree; list each with its worktree path so the user knows what to resolve manually

Do NOT say "will be removed" for worktrees — removal is gated on confirmation in Step 4. If both the merged and stale candidate lists are empty, report "No branches to clean" and stop.

4. Confirm before deletion

Use AskUserQuestion. For merged branches that carry a worktree annotation, the confirmation option must name both the branch and its worktree path — the user is authorizing removal of both in one selection.

Structure:

  • Header: "Branch cleanup"
  • For merged branches: one option per branch. If the branch has a worktree: label = "branch-name + worktree", description = "Removes branch and worktree at /path". If the branch is squash/rebase-merged: append "(squash/rebase PR — force delete)" to the description so the user knows -D will be used. If no worktree and not squash-merged: label = branch name, description = "Removes local branch". Include a "Keep all merged branches" fallback. If there are multiple candidates with no worktrees, a "Delete all N" batch option is acceptable.
  • For stale branches: use multiSelect:true. Each option: label = branch name, description = age. (No stale branch with a worktree will appear here — they were moved to blocked in Step 2.)
  • Always include a "Skip — keep all" option

The user selecting a branch-with-worktree option is explicit authorization to remove both. Never remove a worktree that was not explicitly included in a confirmed selection.

5. Execute deletion

Delete only what the user confirmed. For each confirmed branch:

  1. If the branch has a [worktree:/path] annotation, remove the worktree first:

    bash
    git worktree remove /path/to/wt

    If the command fails (the worktree acquired changes in the window between Step 2 and now), report the error and skip that branch — do not force-remove.

  2. Then delete the branch:

    • Regular merged (no [squash-merged] annotation): git branch -d <branch-name>
    • Squash/rebase-merged ([squash-merged] annotation): git branch -D <branch-name>

    -D is required for squash/rebase-merged branches because git does not recognise their commits as merged into base — using -d will fail. The [squash-merged] annotation on a confirmed selection is explicit user authorisation to force-delete.

  3. After local deletions are complete, offer remote cleanup:

    Use AskUserQuestion with multiSelect:true listing every branch that was successfully deleted locally and has a known remote (git ls-remote --heads origin <branch-name> to verify). Let the user select which remotes to also delete. If none have a remote, skip this step.

    For each selected remote:

    bash
    git push origin --delete <branch-name>

Output

Summary of actions taken:

  • Branches deleted (local)
  • Branches deleted (remote, if requested)
  • Branches kept
  • Any errors encountered

Bundled files

The model reads these on demand while the skill is loaded. They are exposed as readable files and are never executed.

Frequently asked questions

What does the Clean Branches AI skill do?

This skill should be used when the user says "clean up branches", "delete merged branches", or "prune stale branches". Use whenever the user mentions branch cleanup, pruning, or stale branch deletion — even if they don't say "clean-branches" explicitly.

Why use Clean Branches on TypingMind?

Because you install it once and use it with any model. Clean Branches is plain Markdown rather than provider-specific code, so the same skill runs on GPT-5, Claude, Gemini, Grok, or a local model — and you can switch model mid-chat without it breaking. TypingMind runs on your own API keys, so you pay providers directly instead of a per-seat subscription, and your skills and chats stay in your own storage.

How do I install Clean Branches in TypingMind?

Open Plugins → Skills → Install from GitHub in TypingMind and paste https://github.com/gupsammy/Claudest/tree/main/plugins/claude-coding/skills/clean-branches. TypingMind reads its SKILL.md and bundles its files and installs it as a skill you can enable per chat.

Which AI models can use Clean Branches?

Any model you connect in TypingMind. AI skills are plain Markdown instructions rather than provider-specific code, so GPT, Claude, Gemini, Grok, and local models can all load this skill when a request matches it.

How many AI models can I use with Clean Branches?

As many as you like. As long as a model supports skills, you can use Clean Branches with it — GPT, Claude, Gemini, Grok, DeepSeek, Mistral, Llama and more — all on TypingMind with your own API keys.

Is the Clean Branches AI skill free?

It is published on GitHub by gupsammy. Check the repository for licensing terms. You only pay your own AI provider for the tokens you use.

What are AI skills?

An AI skill is a reusable instruction bundle that teaches an AI model how to do one specific task. It follows the open Agent Skills format: a SKILL.md file with a name and description, plus any scripts, templates or reference files the model may need. The model reads the instructions only when your request matches the skill, so an installed skill costs nothing until it is used.

How are AI skills different from plugins or MCP servers?

A plugin or MCP server gives a model new tools to call — code that runs somewhere and returns a result. An AI skill gives the model knowledge and process instead: how to approach a task, which steps to follow, what good output looks like. Skills are plain Markdown, so they need no server, no API key and no runtime, and they work with any model.

View all

Set up your own AI workspace now

Get notified about new features and future giveaways by subscribing to our newsletter 👇