Agent skill

Cleanup Branches

by hmislk in hmislk/hmis

Delete all merged local branches and fast-forward development to origin.

GPL-3.0Auto-check: notesDevelopment

Install Cleanup Branches

skills CLI
$ npx skills add hmislk/hmis --skill cleanup-branches -a claude-code

Project install by default; add -g for ~/.claude/skills/.

GitHub CLI
$ gh skill install hmislk/hmis cleanup-branches --agent claude-code

Project scope by default; add --scope user for a personal install. Needs GitHub CLI 2.90.0 or later (public preview).

Manual copy
$ git clone --depth 1 https://github.com/hmislk/hmis.git skills-src && mkdir -p .claude/skills && cp -r skills-src/.claude/skills/cleanup-branches .claude/skills/cleanup-branches && rm -rf skills-src

Use ~/.claude/skills/ instead of .claude/skills for a personal install. The folder must contain SKILL.md.

Claude Code skills documentation · loads skills from .claude/skills/

Facts

Skill name
cleanup-branches
GitHub stars
236
Token cost
~2.5k tokens
SKILL.md length
1,157 words
Files
1
Skills in repo
33
Repo updated
First seen
Licence
GPL-3.0

At a glance

Delete all merged local branches and fast-forward development to origin.

  • Works in 8 steps: Stash Local persistence.xml Changes → Fetch Latest from Origin → Collect All Local Branches Except… → …
  • Development work in your project
  • SKILL.md covers Step 1 — Stash Local…, Step 2 — Fetch Latest from…, Step 3 — Collect All Local… and Step 4 — Switch to development, plus 5 more sections
  • Calls git and gh

What it does

Cleanup Branches is an agent skill from hmislk/hmis. Delete all merged local branches and fast-forward development to origin. Handles both feature branches (merged to development) and hotfix branches (ending in -hotfix, merged to any production branch). Stashes and restores persistence.xml local JNDI settings automatically. Use after PRs are merged to clean up local git state in one command.

Its SKILL.md is about 2.5k tokens, which your agent loads only when the skill is triggered. It is a single SKILL.md file with no bundled scripts.

It sits in Development. It works with Git. The repository describes itself as: This is an Open Source Java EE based Hospital Information Management System. The licence is GPL-3.0.

When your agent uses it

  • Development work in your project

Example prompts

  • “/cleanup-branches”

Requirements

  • Pre-approved tools (allowed-tools): Bash

Workflow steps

8 steps, taken from the step headings in SKILL.md.

  1. Stash Local persistence.xml Changes
  2. Fetch Latest from Origin
  3. Collect All Local Branches Except development
  4. Switch to development
  5. Delete Marked Branches
  6. Fast-Forward development to origin/development
  7. Restore persistence.xml
  8. Report

What it can do on your machine

Read from SKILL.md and the folder at commit d261e32. It shows what the files ask for, not the result of running them.

  • Tool permissions

    Pre-approves these tools, so the agent can use them without asking each time:

    • Bash

    From allowed-tools in the SKILL.md frontmatter.

  • Runs code

    Shell commands in SKILL.md call:

    • git
    • gh

    From the folder's file list and the shell code blocks in SKILL.md.

  • Network

    No URLs in SKILL.md. Its commands use git and gh, which can reach the network depending on how they are called.

    From URLs in SKILL.md, links to its own repository left out.

  • Credentials

    Names no API keys, tokens, secrets or passwords.

    From names ending in _API_KEY, _TOKEN, _SECRET, _KEY or _PASSWORD in SKILL.md.

Context cost

Cleanup Branches loads about 2.5k tokens when it runs. Until then it costs about 90 tokens; SKILL.md has 1,157 words of instructions outside code blocks.

Always · name and description, kept in context so the agent knows when to use it
~90
When it runs · the whole SKILL.md, loaded when a task matches
~2.5k

Estimates: characters ÷ 4, the usual rule of thumb; real counts depend on the model's tokenizer. Scripts and assets cost tokens only if the agent reads them.

Safety

Auto-check: notes

The automated check noted patterns worth knowing about, such as sudo or a known installer.

  • NotePre-approves every shell command (allowed-tools: Bash)SKILL.md
    allowed-tools: Bash

Automated static check — not a guarantee. Review scripts before installing. It scans the text of SKILL.md for risky patterns (piping downloads into a shell, reading credential files, hidden Unicode, destructive commands); files beside SKILL.md are not scanned.

SKILL.md

The full file from hmislk/hmis at commit d261e32, republished under its GPL-3.0 licence (© hmislk). 1,157 words, ~2,525 tokens.

Download SKILL.mdSave it as .claude/skills/cleanup-branches/SKILL.md (or your agent's skills folder).
name
cleanup-branches
description
Delete all merged local branches and fast-forward development to origin. Handles both feature branches (merged to development) and hotfix branches (ending in -hotfix, merged to any production branch). Stashes and restores persistence.xml local JNDI settings automatically. Use after PRs are merged to clean up local git state in one command.
allowed-tools
Bash

Cleanup Merged Local Branches

Delete every local branch whose PR has already been merged — plus any branch with no PR of its own whose changes are all already represented on origin/development (e.g. a gh pr checkout <N> review checkout) — then bring development up to date. Leave persistence.xml with local JNDI names restored (unstaged) at the end.

Step 1 — Stash Local persistence.xml Changes

Only stash persistence.xml — not all uncommitted work. This prevents unrelated WIP from being moved onto development when the stash is popped.

bash
git stash push -- src/main/resources/META-INF/persistence.xml

If this reports "No local changes to save", that is fine — continue. Note whether a stash was created so you know whether to pop it in Step 7.

Step 2 — Fetch Latest from Origin

bash
git fetch origin --prune

--prune removes remote-tracking refs for branches deleted on GitHub.

Step 3 — Collect All Local Branches Except development

List every local branch except development:

bash
git branch --format='%(refname:short)' | grep -v '^development$'

For each branch, determine whether it is safe to delete.

Protected branches — never delete, never classify

Before the feature/hotfix split, skip any branch that is master or ends with -prod (the local mirrors of admin-managed / production branches — see Notes for the full list). They diverge from development by design, so a naïve patch-equivalence check could still misfire on them; the explicit skip is the guarantee. List them in the report under their own "Protected — not touched" heading (they are expected, not a problem to flag).

Feature branches (do NOT end with -hotfix)

The comparison base is origin/development. Look for a merged PR from this head:

bash
gh pr list --head <branch> --base development --state merged --repo hmislk/hmis --json number,title,mergedAt --jq '.[0]'
# if that is empty, retry without --base — the PR's base may have been changed:
gh pr list --head <branch> --state merged --repo hmislk/hmis --json number,title,baseRefName,mergedAt --jq '.[0]'

Record the PR number/title if found. If the second query returns a PR with a baseRefName other than development, the comparison base is origin/<that baseRefName>, not origin/development. Whether or not a PR is found, continue to Vet the branch tip — a merged PR does not by itself prove the local branch is safe to force-delete (it may carry post-merge commits, or have been reused).

Hotfix branches (end with -hotfix)

Hotfix PRs target a production branch. Look for a merged PR:

bash
gh pr list --head <branch> --state merged --repo hmislk/hmis --json number,title,baseRefName,mergedAt --jq '.[0]'
  • No merged PR → skip (warn the user). A hotfix branch is never vetted by patch-equivalence against development; its commits legitimately are not there.
  • Merged PR found → record the PR number/title and its baseRefName, then Vet the branch tip with the comparison base origin/<baseRefName>.
Vet the branch tip (both branch kinds)

Carry two facts forward for each branch: its PR reference — either #<n> → <base-branch> (from the gh pr list step) or none (a no-PR review checkout) — and its comparison base <base>: origin/development for a feature branch or a no-PR checkout, origin/<baseRefName> for a feature PR whose base was changed, origin/<prod> for a merged hotfix.

bash
git merge-base --is-ancestor <branch> <base> && echo CONTAINED || echo AHEAD
  • CONTAINED — the branch tip is already reachable from <base>; it holds nothing unmerged and no post-merge commits. Mark for deletion.

  • AHEAD — the tip is not reachable from <base>. Normal for a squash- or rebase-merged PR, but also how a branch with genuine post-merge commits (or a reused branch) looks. Decide with a final-tree guard: are <branch>'s versions of the files it touched already identical to <base>?

    bash
    mb=$(git merge-base <base> <branch>)
    git diff --quiet <base> <branch> -- $(git diff --name-only "$mb" <branch>)

    This compares final content, not per-commit patches, so it is correct where git cherry is not: a clean multi-commit squash-merge (no per-commit equivalent) passes; a branch whose change was applied to <base> and later reverted there fails; a merge commit that carried unique content in fails.

    • exit 0 — every file the branch touched already matches <base>; deleting the branch loses nothing (a clean squash/rebase merge, or a fully-absorbed no-PR checkout such as pr-23617). Mark for deletion.
    • exit 1 — some file the branch touched differs from <base>: genuine post-merge work, a reused branch, conflict-resolution content, or a squash/rebase that did not land identical content. Skip and warn, quoting the branch's real <base> and its PR reference (or noting it has none): "ahead of <base> — if PR #<n> was squash/rebase-merged, git branch -D <branch> manually; otherwise inspect for unmerged work first".

    Empty touched-file list gotcha: if git diff --name-only "$mb" <branch> is empty, the command above degrades to a full-tree git diff --quiet <base> <branch> (no pathspec) and will almost always exit 1 — not because <branch> differs from <base>, but because <base> has since changed unrelated files <branch> never touched. Don't trust that exit code in this case. Instead compare tree hashes directly:

    bash
    [ "$(git rev-parse <branch>^{tree})" = "$(git rev-parse "$mb"^{tree})" ] && echo IDENTICAL || echo DIVERGED
    • IDENTICAL — <branch>'s tree is byte-identical to the merge-base (its "ahead" commits are no-ops, e.g. an empty merge), and the merge-base is by definition an ancestor of <base>. The branch holds zero unique content. Mark for deletion.
    • DIVERGED — genuinely different content despite the empty per-commit diff (rare). Skip and warn.
Show full SKILL.md (413 more words)Show less

Step 4 — Switch to development

bash
git checkout development

Step 5 — Delete Marked Branches

Step 3's Vet the branch tip fully decided every marked branch — each is either CONTAINED in its comparison base, or AHEAD but proven fully absorbed (the final-tree guard found every file it touched already identical to <base>). Branches with post-merge or unmerged work were skipped there. Step 5 only deletes; it does not re-decide safety.

bash
git branch -d <branch> || git branch -D <branch>

git branch -d refuses when the tip is not reachable from local development — normal here, because a squash/rebase merge leaves the tip off development and local development is not fast-forwarded until Step 6. The || git branch -D completes the delete; Step 3 already established the branch is safe to drop. git branch -D prints the deleted SHA (Deleted branch X (was 906d5ebbb4)) and the reflog keeps it ~30 days, so a mistaken delete is still recoverable.

Do not re-check with git log origin/<branch>..<branch>: Step 2's git fetch --prune has already removed the origin/<branch> upstream, so that command errors with unknown revision or path not in the working tree instead of returning empty.

Step 6 — Fast-Forward development to origin/development

Use --ff-only so git stops with an error if the local development has diverged (e.g. local commits not yet pushed), rather than silently discarding them:

bash
git merge --ff-only origin/development

If this fails with "Not possible to fast-forward", the local development has commits that are not on origin/development. Report this to the user and stop — do not force-reset. The user must resolve the divergence manually.

Step 7 — Restore persistence.xml

If a stash was created in Step 1 (only persistence.xml was stashed):

bash
git stash pop

If the stash pop reveals conflicts (unlikely but possible), report them to the user and stop — do not resolve conflicts automatically.

If no stash was created, leave persistence.xml as-is.

Step 8 — Report

Print a summary:

text
✓ Deleted branches:
  - <branch>  (PR #NNN merged → <base-branch>)
  - <branch>  (no PR; all changes already represented on <base-branch>)
  ...

⚠ Skipped branches:
  - <branch>  (PR #NNN merged → <base-branch>, but tip is ahead of it —
    squash/rebase merge? `git branch -D` manually; else inspect for unmerged work)
  - <branch>  (no PR; tip has commit(s) not on <base-branch>)
  - <branch>  (hotfix, no merged PR found)
  ...

• Protected — not touched:
  - master, <name>-prod

✓ development is now at <short-sha> (<commit subject>)
✓ persistence.xml restored to local JNDI settings (unstaged)

Each vetted deleted / skipped line carries the branch's real PR reference (or "no PR") and its real comparison base — never assume a PR exists or that the base is development. The unvetted "hotfix, no merged PR found" line is the one exception: it is skipped before any base is chosen, so it carries neither. Omit any section with no entries. If nothing was stashed, replace the last line with: ✓ persistence.xml unchanged (no local changes were present)

Notes

  • Never delete development, master, or any *-prod branch.
  • The known production branches are: coop-prod, ruhunu-prod, southernlanka-prod, rmh-prod, digasiri-prod, mp-prod, roseth-prod, horizon-prod, asiripharmacy-prod, engagewellness-prod
  • After this skill completes the developer is on development, up to date, with only unmerged feature branches remaining locally.

© hmislk, GPL-3.0. Rendered from Markdown: HTML in the file is shown as text, images as links, and headings moved down two levels. Raw file

Files

Just SKILL.md in .claude/skills/cleanup-branches of hmislk/hmis.

Open the folder on GitHubat commit d261e32

Compare with similar skills

Cleanup Branches next to the 5 skills that share the most tags, products or categories with it. Stars are the repository's; “used in” counts other GitHub owners with a copy.

Cleanup Branches compared with similar skills
SkillStarsUsed inTokensAuto-checkLicenceRepo updated
Cleanup Branches this skillhmislk/hmis236—~2.5kAutomated safety check: NotesGPL-3.0
Finishing a Development Branchobra/superpowers297k5 repos~1.9kAutomated safety check: PassMIT
Code Review ChecklistshareAI-lab/learn-claude-code78k5 repos~1.1kAutomated safety check: PassMIT
Code Design Rationale Investigatorcursor/plugins10k9 repos~2.6kAutomated safety check: PassNone
Contributor-First PR MergeHKUDS/OpenHarness16k1 repos~847Automated safety check: PassMIT
Finishing A Development Branchfarm-fe/farm5.6k34 repos~1.8kAutomated safety check: PassMIT

Similar skills

  • Walks the last step of a branch: confirm tests pass, detect the git environment, ask how to integrate, carry out your choice and clean up the worktree.

    297k GitHub starsUsed in 5 repos~1.9k tokens
    DevelopmentAuto-check passed
  • Code Review Checklist

    shareAI-lab/learn-claude-code

    Reviews code against a five-part checklist covering security, correctness, performance, maintainability and testing, and reports findings in a fixed format.

    78k GitHub starsUsed in 5 repos~1.1k tokens
    DevelopmentAuto-check passed
  • Official

    Digs into why code is shaped the way it is by checking git history, pull requests and connected tools in parallel, then reporting a cited read on the tradeoffs.

    10k GitHub starsUsed in 9 repos~2.6k tokens
    DevelopmentAuto-check passed
  • Merges external GitHub pull requests while keeping the original author credited, and fixes conflicts after the merge instead of rewriting the contribution.

    16k GitHub starsUsed in 1 repo~847 tokens
    DevelopmentAuto-check passed
  • A skill your agent uses when implementation is complete, all tests pass, and you need to decide how to integrate the work - guides completion of development work by presenting structured options for…

    5.6k GitHub starsUsed in 34 repos~1.8k tokens
    DevelopmentAuto-check passed
  • Moves a package from another TryGhost repository into Ghost as an internal workspace package while keeping its Git history, with checkpoints for the steps that need an administrator.

    56k GitHub stars~3.8k tokensUpdated today
    DevelopmentAuto-check passed

More from hmislk/hmis

All 33 skills in this repo
  • API Usage

    hmislk/hmis

    Reference for calling existing HMIS REST APIs. An agent skill from hmislk/hmis.

    236 GitHub stars~1.1k tokensUpdated today
    Auto-check passed
  • Application configuration options reference for the HMIS project.

    236 GitHub stars~474 tokensUpdated today
    Auto-check passed
  • Caveman

    hmislk/hmis

    Ultra-compressed communication mode. An agent skill from hmislk/hmis.

    236 GitHub starsUsed in 20 repos~946 tokens
    Auto-check passed
  • Database Guide

    hmislk/hmis

    MySQL database development guide for the HMIS project. An agent skill from hmislk/hmis.

    236 GitHub stars~664 tokensUpdated today
    Auto-check passed
  • Demo Video

    hmislk/hmis

    A skill your agent uses when asked to make a demo, training, how-to or tutorial video with sound or voice-over showing an HMIS function or configuration (e.g.

    236 GitHub stars~3.9k tokensUpdated today
    Auto-check passed
  • Deploy QA

    hmislk/hmis

    Sync development into QA/testing environment branches (QA1-QA4, local RH staging) via PR + merge on GitHub.

    236 GitHub stars~2.1k tokensUpdated today
    Auto-check: notes

Works with

Categories

Questions about Cleanup Branches

What does Cleanup Branches do?

Delete all merged local branches and fast-forward development to origin. Cleanup Branches is an agent skill from hmislk/hmis. Delete all merged local branches and fast-forward development to origin.

When should I use Cleanup Branches?

Cleanup Branches fits situations like: development work in your project.

How do I install Cleanup Branches in Claude Code?

Run `npx skills add hmislk/hmis --skill cleanup-branches -a claude-code`. Or copy the skill folder (.claude/skills/cleanup-branches in hmislk/hmis) into .claude/skills/cleanup-branches in your project. Claude Code loads it when a task matches its description.

How do I install Cleanup Branches in Codex?

Run `npx skills add hmislk/hmis --skill cleanup-branches -a codex`. Or copy the skill folder (.claude/skills/cleanup-branches in hmislk/hmis) into .agents/skills/cleanup-branches in your project. Codex loads it when a task matches its description.

Can I use Cleanup Branches in Cursor, Gemini CLI or GitHub Copilot?

Cursor, Gemini CLI, GitHub Copilot and OpenCode also load SKILL.md folders. With the skills CLI, run `npx skills add hmislk/hmis --skill cleanup-branches -a cursor` (or -a gemini-cli, github-copilot or opencode for the others). To copy it by hand, put the folder in .cursor/skills/cleanup-branches, .gemini/skills/cleanup-branches, .github/skills/cleanup-branches and .opencode/skills/cleanup-branches in your project.

What does Cleanup Branches need to run?

Going by SKILL.md and its folder, Cleanup Branches needs the command-line tools its instructions call (git and gh). Its frontmatter pre-approves these tools: Bash.

Does Cleanup Branches access the network?

SKILL.md contains no URLs. Its commands use git and gh, which can reach the network depending on how they are called. This is read from the text; nothing was executed.

Is Cleanup Branches safe to install?

Our automated static check of SKILL.md found notes only (pre-approves every shell command (allowed-tools: bash)), nothing it rates as a warning. It is not a guarantee. Review the folder before installing.

What licence does Cleanup Branches use?

Cleanup Branches is published under the GPL-3.0 licence (the repository's licence). It allows redistribution, so the full SKILL.md is shown on this page.

How many tokens does Cleanup Branches use?

About 2.5k tokens (SKILL.md is roughly 10k characters). Agents keep only the skill's name and description in context until a task matches; then they load SKILL.md in full.

What are the alternatives to Cleanup Branches?

Skills that share tags, products or a category with Cleanup Branches: Finishing a Development Branch (obra/superpowers, 297k stars), Code Review Checklist (shareAI-lab/learn-claude-code, 78k stars), Code Design Rationale Investigator (cursor/plugins, 10k stars) and Contributor-First PR Merge (HKUDS/OpenHarness, 16k stars). The comparison table on this page puts their stars, adoption, token cost, safety result and licence side by side.

Who maintains Cleanup Branches?

hmislk (a GitHub organization) maintains it in hmislk/hmis, which has 236 GitHub stars. The repository holds 33 skills in this directory. The repository was last updated on October 9, 2026.

Source: hmislk/hmis on GitHub. Facts on this page come from the repository at the commit we read; the author's words are quoted as theirs.