Cleanup Git logo

Cleanup Git

Community
alexei-led
cleanup-git

Remove merged local branches and stale git worktrees. Use when the user says "cleanup branches", "prune worktrees", "tidy git", "remove merged branches", "delete merged branches", "gone branches", or wants to clean local git state. NOT for creating commits, creating worktrees, or configuring git hooks.

Overview

Publisheralexei-led
Repositorycc-thingz
Skill namecleanup-git
Stars
38
Forks
5
Bundled files
1
LicenseMIT
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 alexei-led on GitHub. Read the source before you install it.

Installation

Install the Cleanup Git 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/alexei-led/cc-thingz/tree/master/src/skills/cleanup-git
  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/alexei-led/cc-thingz.git /tmp/cc-thingz
mkdir -p .claude/skills
cp -r /tmp/cc-thingz/src/skills/cleanup-git .claude/skills/cleanup-git
Restart Claude Code after copying so it picks up the new skill.

Use it in TypingMind

Enable Cleanup Git 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 Cleanup Git 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 Cleanup Git 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.

Cleanup Git

Use the target repo's own scripts/cleanup-git.sh if it ships one, otherwise this skill's script. Inspect a repo-provided script before relying on its safety policy. Use direct deletion only for a specifically approved exception described below; never pipe a branch list into force-delete.

bash
scripts/cleanup-git.sh                  # preview (default)
scripts/cleanup-git.sh --apply          # execute the requested safe cleanup
scripts/cleanup-git.sh --apply --force --branch <name>  # approved ahead-commit loss
scripts/cleanup-git.sh --base <ref>     # override base detection

The script fetches and prunes remotes. It prefers the fetched remote default branch, then remote main, master, trunk, develop, or dev, then local fallbacks. --base overrides this choice.

What the script decides

A branch or its worktree is a candidate when one of these holds:

  • PR merged: GitHub confirms the PR in the target repository and base, and its merge commit is reachable from the base. This catches squash, conflict-resolved squash, and rebase merges; ahead commits count only past the PR head.
  • merged: the branch is an ancestor of the base.
  • squash merged: the complete branch patch is equivalent to a commit in the base. This works offline without gh; conflict resolution can prevent equivalence.
  • upstream gone: only a candidate signal, not merge proof. Unique commits still keep the branch.

It prunes worktree registrations whose directory is gone (git worktree prune) before listing, so a stale entry does not keep its branch forever. It removes a detached worktree when its HEAD is merged or squash-merged into the base and the tree is clean; an unmerged, dirty, locked, or current detached worktree stays.

It skips the current worktree, current branch, base, and main/master/trunk/develop/dev. It keeps locked worktrees and worktrees with tracked, untracked, or ignored files, or unknown status. It keeps candidates with ahead commits or unknown ahead counts unless --force --branch <name> is passed for one approved target. No proof prints skip ... (active); do not treat that as proof of unmerged work.

Workflow

  1. Run the preview and show the safe removals and kept objects.
  2. An explicit cleanup request authorizes --apply for verified safe candidates. Run it without another confirmation; kept objects do not block safe removals. For a preview-only request, do not apply.
  3. Report what was removed and what remains. Do not ask about every kept object unless the user wants it removed. For a risky exception, show the exact branch/path, full tip OID, unique commits, and uncommitted files (including ignored files), then ask once for permission to discard them. A reply such as “I allow it” authorizes only that described scope; execute it yourself rather than telling the user to run it.

Stop if the directory is not a git repo. If no base is found, ask for --base <ref>. A fetch failure makes the preview use stale refs (say so) and makes --apply refuse.

Approved exceptions

After explicit user consent, recheck the tip and file list. If either changed, ask again. For one worktree, use the using-git-worktrees cleanup script with --force <branch>. For a branch-only exception, or a hook-blocked direct cleanup, use the command-local marker:

bash
git -c cc-thingz.cleanupApproved=<full-tip-oid> worktree remove --force <exact-path>
git -c cc-thingz.cleanupApproved=<full-tip-oid> branch -D <exact-branch>

Use separate commands, worktree first. The marker must match the current tip. It does not authorize protected/current/locked worktrees, other branches, reset --hard, clean, or force-push. Never save it with git config, invent user consent, or use bulk --force when only one exception was approved. The marker pins only the commit, not file contents; the agent must recheck files immediately before executing. This is a consent attestation by the agent, not cryptographic proof that the user approved; the hook is a mistake guard, not a security sandbox.

Output

text
GIT CLEANUP
Status: PREVIEW | APPLIED | BLOCKED
Base: <ref>
Remove: <branch/worktree> — <reason>
Keep: <branch/worktree> — <reason and decision needed>
Verification: <command> — pass/fail/not run

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 Cleanup Git AI skill do?

Remove merged local branches and stale git worktrees. Use when the user says "cleanup branches", "prune worktrees", "tidy git", "remove merged branches", "delete merged branches", "gone branches", or wants to clean local git state. NOT for creating commits, creating worktrees, or configuring git hooks.

Why use Cleanup Git on TypingMind?

Because you install it once and use it with any model. Cleanup Git 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 Cleanup Git in TypingMind?

Open Plugins → Skills → Install from GitHub in TypingMind and paste https://github.com/alexei-led/cc-thingz/tree/master/src/skills/cleanup-git. 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 Cleanup Git?

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 Cleanup Git?

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

Is the Cleanup Git AI skill free?

Yes. It is published on GitHub by alexei-led under the MIT license. 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 👇