Agent skill

Git Worktree Cleanup

by lobehub in lobehub/lobehub

Audits stale Git worktrees and branches with a bundled script, classifies each one, and deletes only after you approve the exact candidates.

Custom licenceAuto-check passedDevelopment

Install Git Worktree Cleanup

skills CLI
$ npx skills add lobehub/lobehub --skill cleanup-git-worktrees -a claude-code

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

GitHub CLI
$ gh skill install lobehub/lobehub cleanup-git-worktrees --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/lobehub/lobehub.git skills-src && mkdir -p .claude/skills && cp -r skills-src/.agents/skills/cleanup-git-worktrees .claude/skills/cleanup-git-worktrees && 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-git-worktrees
GitHub stars
83k
Token cost
~2.8k tokens
SKILL.md length
1,410 words
Files
3 (incl. scripts)
Skills in repo
50
Repo updated
First seen
Licence
Custom licence

At a glance

Audits stale Git worktrees and branches with a bundled script, classifies each one, and deletes only after you approve the exact candidates.

  • Works in 5 steps: Run the audit from any worktree in the… → Interpret classifications → Present one compact table split into… → …
  • Auditing a repository with many leftover worktrees and local branches
  • SKILL.md covers Workflow, Proving a merge, Repo-approved deletion policy and Broken registrations, plus 2 more sections
  • Runs Shell scripts from its folder; calls git, bash and gh

What it does

The skill treats cleanup as a destructive action. It audits first, groups candidates by the reason they can be deleted, and asks for one explicit approval before removing anything, unless your request already names the exact targets. A bundled cleanup.sh script does the classification so the results are deterministic, and removal of managed worktrees goes through the repository's own lifecycle.

The audit command can fetch and prune the remote, look up each branch's pull request with the gh CLI (which confirms a merge, at roughly a second per branch), and flag clean branches idle past a day threshold, with 15 days as the approved default. Classifications include protected branches such as main and canary, the current worktree, dirty worktrees that are kept, and candidates whose tip is merged into the base or whose pull request is merged or closed.

When your agent uses it

  • Auditing a repository with many leftover worktrees and local branches
  • Finding branches whose pull request was merged or closed so they can go
  • Checking which worktrees hold uncommitted work before removing anything

Example prompts

  • “Audit my stale worktrees and show me what is safe to delete.”
  • “Clean up the branches that were merged into canary, using PR status from GitHub.”
  • “List which worktrees are dirty so I do not lose anything before cleanup.”

Requirements

  • Bash and Git
  • An authenticated gh CLI for pull request lookups

Workflow steps

5 steps, taken from the first numbered list in SKILL.md.

  1. Run the audit from any worktree in the repository
  2. Interpret classifications
  3. Present one compact table split into three groups: deletable now (all candidate-*), needs a manual check (review-*), and protected. Keep…
  4. After approval, use the repository's worktree lifecycle workflow when it manages services or other resources alongside a checkout; the…
  5. Run the audit again and report

What it can do on your machine

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

  • Tool permissions

    Pre-approves nothing: there is no allowed-tools line, so your agent's usual permission prompts apply.

    From allowed-tools in the SKILL.md frontmatter.

  • Runs code

    Ships 1 file in scripts/ (Shell), which the agent can run.

    Shell commands in SKILL.md call:

    • git
    • bash
    • 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

Git Worktree Cleanup loads about 2.8k tokens when it runs. Until then it costs about 31 tokens; SKILL.md has 1,410 words of instructions outside code blocks.

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

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 passed

The automated check found no risky patterns in SKILL.md.

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); the scripts in this folder are not scanned.

SKILL.md

Its licence (Custom licence) doesn't allow us to republish the file, so here is its outline and opening line. It has 1,410 words (~2,788 tokens).

“Use the bundled script to make classification deterministic. Treat cleanup as a destructive action: audit first, show the exact candidates grouped by why they are deletable, and obtain one explicit approval before applying deletion unless the user's current request already…”

— opening of SKILL.md by lobehub, Custom licence
name
cleanup-git-worktrees

Read the full SKILL.md on GitHub

Files

SKILL.md and 2 other files (scripts) in .agents/skills/cleanup-git-worktrees of lobehub/lobehub.

  • SKILL.md
  • agents/openai.yaml
  • scripts/cleanup.sh

Open the folder on GitHubat commit 1863542

Compare with similar skills

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

Git Worktree Cleanup compared with similar skills
SkillStarsUsed inTokensAuto-checkLicenceRepo updated
Git Worktree Cleanup this skilllobehub/lobehub83k—~2.8kAutomated safety check: PassCustom licence
Finishing a Development Branchobra/superpowers296k5 repos~1.9kAutomated safety check: PassMIT
Ccmanager Configkbwo/ccmanager1.3k—~1.5kAutomated safety check: PassMIT
Git Worktree Managermicrosoft/WindowsAppSDK4.7k—~2kAutomated safety check: PassMIT
Git Worktree IsolationjnMetaCode/superpowers-zh8.3k1 repos~982Automated safety check: PassMIT
Git Committisfeng/Easydict15k—~535Automated safety check: PassGPL-3.0

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.

    296k GitHub starsUsed in 5 repos~1.9k tokens
    DevelopmentAuto-check passed
  • Ccmanager Config

    kbwo/ccmanager

    Set up, review, or repair a CCManager config — .ccmanager.json at a git repository root, or the global ~/.config/ccmanager/config.json.

    1.3k GitHub stars~1.5k tokensUpdated 10 days ago
    DevelopmentAuto-check passed
  • Git Worktree Manager

    microsoft/WindowsAppSDK

    Official

    Creates and manages Git worktrees with PowerShell scripts so separate issues and Copilot sessions each get an isolated branch, build and test environment.

    4.7k GitHub stars~2k tokensUpdated today
    DevelopmentAuto-check passed
  • Git Worktree Isolation

    jnMetaCode/superpowers-zh

    Sets up an isolated workspace before feature work or plan execution, preferring native worktree tools and falling back to git worktree, with instructions in Chinese.

    8.3k GitHub starsUsed in 1 repo~982 tokens
    DevelopmentAuto-check passed
  • Git Commit

    tisfeng/Easydict

    起草、创建或汇报 Angular-style 本地 Git 提交。用于明确的提交交付;分支集成使用 worktree-rebase-merge,不 push。

    15k GitHub stars~535 tokensUpdated yesterday
    DevelopmentAuto-check passed
  • Clean Complete Branches

    jtenniswood/espcontrol

    Clean up completed Git branches and worktrees for this repository both locally and on GitHub.

    1.1k GitHub stars~820 tokensUpdated today
    DevelopmentAuto-check passed

More from lobehub/lobehub

All 50 skills in this repo
  • Builds single-file interactive HTML prototypes rendered with the real LobeHub UI components and written as production-style React, so they can later be split into files.

    83k GitHub stars~1.6k tokensUpdated today
    Auto-check passed
  • Verifies a delivery end to end by driving the real product on a CLI, web, desktop or iOS Simulator surface, capturing evidence and publishing a round with the lh CLI.

    83k GitHub stars~9.7k tokensUpdated today
    Auto-check passed
  • Maintains LobeHub's model-backed alint rule set: writing rules, removing false positives against real code, deciding warn versus error and tracking token cost.

    83k GitHub stars~1.9k tokensUpdated today
    Auto-check passed
  • Guides building LobeHub builtin agent tools, from the manifest and execution runtime to executors, chat UI renders and registry wiring.

    83k GitHub stars~2.4k tokensUpdated today
    Auto-check passed
  • Explains how LobeHub client code fetches data through services, SWR store hooks and cache keys, and when to avoid useEffect fetching or duplicated state.

    83k GitHub stars~1.7k tokensUpdated today
    Auto-check passed
  • Guides work on LobeHub's own product search: the shared search repository, provider choice, Elasticsearch mappings, change syncing and reindexing.

    83k GitHub stars~4.1k tokensUpdated today
    Auto-check passed

Works with

Categories

Questions about Git Worktree Cleanup

What does Git Worktree Cleanup do?

Audits stale Git worktrees and branches with a bundled script, classifies each one, and deletes only after you approve the exact candidates. The skill treats cleanup as a destructive action. It audits first, groups candidates by the reason they can be deleted, and asks for one explicit approval before removing anything, unless your request already names the exact targets.

When should I use Git Worktree Cleanup?

Git Worktree Cleanup fits situations like: auditing a repository with many leftover worktrees and local branches; finding branches whose pull request was merged or closed so they can go; checking which worktrees hold uncommitted work before removing anything.

How do I install Git Worktree Cleanup in Claude Code?

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

How do I install Git Worktree Cleanup in Codex?

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

Can I use Git Worktree Cleanup 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 lobehub/lobehub --skill cleanup-git-worktrees -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-git-worktrees, .gemini/skills/cleanup-git-worktrees, .github/skills/cleanup-git-worktrees and .opencode/skills/cleanup-git-worktrees in your project.

What does Git Worktree Cleanup need to run?

Going by SKILL.md and its folder, Git Worktree Cleanup needs a shell for the scripts in its folder and the command-line tools its instructions call (git, bash and gh). Our summary lists: Bash and Git; An authenticated gh CLI for pull request lookups.

Does Git Worktree Cleanup 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 Git Worktree Cleanup safe to install?

Our automated static check of SKILL.md found no risky patterns, such as piping downloads into a shell, reading credential files or hidden Unicode. It is not a guarantee. The check reads SKILL.md only: the scripts in the folder are not scanned, so read them before running anything.

What licence does Git Worktree Cleanup use?

Git Worktree Cleanup has a licence file (the repository's licence) that doesn't match a standard licence. Read it on GitHub before reusing the skill.

How many tokens does Git Worktree Cleanup use?

About 2.8k tokens (SKILL.md is roughly 11k 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 Git Worktree Cleanup?

Skills that share tags, products or a category with Git Worktree Cleanup: Finishing a Development Branch (obra/superpowers, 296k stars), Ccmanager Config (kbwo/ccmanager, 1.3k stars), Git Worktree Manager (microsoft/WindowsAppSDK, 4.7k stars) and Git Worktree Isolation (jnMetaCode/superpowers-zh, 8.3k stars). The comparison table on this page puts their stars, adoption, token cost, safety result and licence side by side.

Who maintains Git Worktree Cleanup?

lobehub (a GitHub organization) maintains it in lobehub/lobehub, which has 83,023 GitHub stars. The repository holds 50 skills in this directory. The repository was last updated on October 7, 2026.

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