Agent skill

Git Worktree Prune

by michaleiatrak-star in michaleiatrak-star/Lex-Machina

Safely prune stale git worktrees and local branches left over from past sessions, deleting only those with no unique work so no commit is ever lost.

GPL-3.0Auto-check passedDevelopment

Install Git Worktree Prune

skills CLI
$ npx skills add michaleiatrak-star/Lex-Machina --skill git-worktree-prune -a claude-code

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

GitHub CLI
$ gh skill install michaleiatrak-star/Lex-Machina git-worktree-prune --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/michaleiatrak-star/Lex-Machina.git skills-src && mkdir -p .claude/skills && cp -r skills-src/.claude/skills/git-worktree-prune .claude/skills/git-worktree-prune && 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
git-worktree-prune
GitHub stars
262
Token cost
~712 tokens
SKILL.md length
336 words
Files
2 (incl. scripts)
Skills in repo
35
Repo updated
First seen
Licence
GPL-3.0

At a glance

Safely prune stale git worktrees and local branches left over from past sessions, deleting only those with no unique work so no commit is ever lost.

  • A repo has accumulated worktrees and branches over many sessions and needs cleanup
  • SKILL.md covers Safety invariant, Usage, Review the DELETE list before… and Notes
  • Runs Python scripts from its folder; calls python and git
  • Include prune worktrees

What it does

Git Worktree Prune is an agent skill from michaleiatrak-star/Lex-Machina. Safely prune stale git worktrees and local branches left over from past sessions, deleting only those with no unique work so no commit is ever lost. Use when a repo has accumulated worktrees and branches over many sessions and needs cleanup. Triggers include "prune worktrees", "delete stale branches", "clean up git worktrees/branches", "remove old worktrees", "which branches are safe to delete".

Its SKILL.md is about 710 tokens, which your agent loads only when the skill is triggered. The skill folder holds 2 other files, including scripts (for example `scripts/prune_git.py`).

It sits in Development, covering Git worktrees. It works with Git. The repository describes itself as: Analityka polskiego prawa, przygotowanie pism procesowych, weryfikacja przepisów prawa polskiego i orzecznictwa z oficjalnych źródeł z zakazem cytowania z pamięci, przygotowanie… The licence is GPL-3.0.

When your agent uses it

  • A repo has accumulated worktrees and branches over many sessions and needs cleanup
  • Include prune worktrees
  • Delete stale branches
  • Clean up git worktrees/branches

Example prompts

  • “prune worktrees”
  • “delete stale branches”
  • “clean up git worktrees/branches”
  • “/git-worktree-prune”

Requirements

  • Python 3

What it can do on your machine

Read from SKILL.md and the folder at commit bccda93. 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/ (Python), which the agent can run.

    Shell commands in SKILL.md call:

    • python
    • git

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

  • Network

    No URLs in SKILL.md. Its commands use git, 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 Prune loads about 712 tokens when it runs. Until then it costs about 104 tokens; SKILL.md has 336 words of instructions outside code blocks.

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

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

The full file from michaleiatrak-star/Lex-Machina at commit bccda93, republished under its GPL-3.0 licence (© michaleiatrak-star). 336 words, ~712 tokens.

Download SKILL.mdSave it as .claude/skills/git-worktree-prune/SKILL.md (or your agent's skills folder). This skill also uses 1 other file; get the full folder from GitHub.
name
git-worktree-prune
description
Safely prune stale git worktrees and local branches left over from past sessions, deleting only those with no unique work so no commit is ever lost. Use when a repo has accumulated worktrees and branches over many sessions and needs cleanup. Triggers include "prune worktrees", "delete stale branches", "clean up git worktrees/branches", "remove old worktrees", "which branches are safe to delete".

Git Worktree & Branch Prune

Remove stale worktrees and local branches from old sessions without ever losing a commit.

Safety invariant

  • A branch is deleted only when every commit on it is reachable from some other surviving ref (another local branch, a remote-tracking branch origin/*, or a tag). Branches with unique commits are kept.
  • A worktree is removed only when it is clean (no uncommitted or untracked changes). The branch it held is preserved.
  • The primary worktree, the current branch, and main/master are always kept.

Usage

Always dry-run first (the default — it changes nothing), review the plan, then apply:

bash
python scripts/prune_git.py --repo <path>            # dry-run: prints KEEP/REMOVE/DELETE plan
python scripts/prune_git.py --repo <path> --apply    # execute after reviewing the dry-run

Flags:

  • --fetch — run git fetch --all --prune first so branches already merged/pushed to a remote are recognized as deletable. Without it the tool is more conservative (stale remotes only ever cause it to keep more, never lose work).
  • --protect BRANCH — always keep this branch (repeatable). Use for branches with no unique commits that you still want to keep (see below).
  • --repo PATH — a path inside the target repo (default: cwd).

Review the DELETE list before --apply

The "no unique commits" rule is about commits, not intent. A branch can be flagged DELETE while still being meaningful — most commonly a feature branch that a descendant now subsumes (e.g., you branched research/x off feat/y, so feat/y's commits now also live on research/x). No commit is lost if it's deleted, but the branch name and its PR track are. Keep such a branch with --protect <name>.

Every removal is printed with its reason; a branch shown as KEEP -- N unique commit(s) holds work found nowhere else and is never touched.

Notes

  • Never deletes remote-tracking refs, tags, or the reflog — only local branches and worktree checkouts.
  • Removing a worktree that holds a branch (even a protected one like main) frees the branch without deleting it; you can then check it out in the primary worktree.
  • Worktrees whose directory is already gone are cleaned via git worktree prune.
  • On Windows, run under Git Bash / a UTF-8 console (PYTHONIOENCODING=utf-8) if paths contain non-ASCII characters.

© michaleiatrak-star, 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

SKILL.md and 1 other file (scripts) in .claude/skills/git-worktree-prune of michaleiatrak-star/Lex-Machina.

  • SKILL.md
  • scripts/prune_git.py

Open the folder on GitHubat commit bccda93

Compare with similar skills

Git Worktree Prune 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 Prune compared with similar skills
SkillStarsUsed inTokensAuto-checkLicenceRepo updated
Git Worktree Prune this skillmichaleiatrak-star/Lex-Machina262—~712Automated safety check: PassGPL-3.0
Build Px4 macOSPX4/PX4-Autopilot13k—~1.1kAutomated safety check: PassBSD-3-Clause
Git Worktree IsolationjnMetaCode/superpowers-zh8.3k1 repos~982Automated safety check: PassMIT
WorktreeAgentsMesh/AgentsMesh2.4k—~553Automated safety check: NotesCustom licence
Cursor Composer Task DelegateChachamaru127/claude-code-harness3.2k—~4.4kAutomated safety check: NotesMIT
Git Worktree Setupk8zdev/k8z155—~930Automated safety check: PassNone

Similar skills

  • Build Px4 macOS

    PX4/PX4-Autopilot

    Build PX4 board firmware on macOS in the px4-dev Docker container, including git worktrees, and stage commit-labeled artifacts without flashing hardware.

    13k GitHub stars~1.1k tokensUpdated yesterday
    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
  • Worktree

    AgentsMesh/AgentsMesh

    Creates or reuses an isolated AgentsMesh Git worktree from a verified base branch, preserves existing changes, and optionally starts the worktree-scoped development environment.

    2.4k GitHub stars~553 tokensUpdated 16 days ago
    DevelopmentAuto-check: notes
  • Cursor Composer Task Delegate

    Chachamaru127/claude-code-harness

    Hands one implementation task to Cursor Composer in an isolated git worktree, then reviews its diff and cherry-picks the result into the main branch.

    3.2k GitHub stars~4.4k tokensUpdated 5 days ago
    DevelopmentAuto-check: notes
  • Automate git worktree creation and copy private files (not tracked in git) to new workdirs.

    155 GitHub stars~930 tokensUpdated 3 mo ago
    DevelopmentAuto-check passed
  • New Feature

    michaelshimeles/skills

    Start a new task in an isolated Git worktree branched from origin/main so multiple agents can work on the same repo in parallel without conflicts.

    1.3k GitHub starsUsed in 1 repo~699 tokens
    DevelopmentAuto-check passed

More from michaleiatrak-star/Lex-Machina

All 35 skills in this repo
  • Gemini Agent

    michaleiatrak-star/Lex-Machina

    Delegate tasks to Gemini CLI as an agent. An agent skill from michaleiatrak-star/Lex-Machina.

    262 GitHub stars~626 tokensUpdated today
    Auto-check passed
  • Audyt Systemu V4

    michaleiatrak-star/Lex-Machina

    Audyt jakości, spójności i bezpieczeństwa systemu prawnych skilli: zależności, wersje, mapy Dz.U., treść merytoryczna, propagacja zmian, deduplikacja i bramki jakości.

    262 GitHub stars~17k tokensUpdated today
    Auto-check passed
  • Dr 02 Prawo Cywilne Rodzinne Gospodarcze

    michaleiatrak-star/Lex-Machina

    Prawo cywilne, rodzinne i gospodarcze: KC, KPC, spadki, rodzina, spółki, upadłość, restrukturyzacja, windykacja i odpowiedzialność kontraktowa/deliktowa.

    262 GitHub stars~10k tokensUpdated today
    Auto-check passed
  • Dr 01 Ustroj Konstytucyjny I Zrodla Prawa

    michaleiatrak-star/Lex-Machina

    Prawo konstytucyjne i ustrojowe: Konstytucja, organy państwa, TK, źródła prawa, legislacja i skarga konstytucyjna; analiza z aktualną weryfikacją źródeł.

    262 GitHub stars~2.6k tokensUpdated today
    Auto-check passed
  • Prawo administracyjne i sądowoadministracyjne: KPA, PPSA, decyzje, bezczynność, WSA/NSA, egzekucja administracyjna, cudzoziemcy i postępowania urzędowe.

    262 GitHub stars~4.6k tokensUpdated today
    Auto-check passed
  • Dr 07 Zamowienia Publiczne Fundusze Ue

    michaleiatrak-star/Lex-Machina

    Zamówienia publiczne i fundusze UE: PZP, postępowania zakupowe, KIO, środki ochrony prawnej, finansowanie UE i powiązane zagadnienia realizacyjne.

    262 GitHub stars~2.8k tokensUpdated today
    Auto-check passed

Works with

Questions about Git Worktree Prune

What does Git Worktree Prune do?

Safely prune stale git worktrees and local branches left over from past sessions, deleting only those with no unique work so no commit is ever lost. Git Worktree Prune is an agent skill from michaleiatrak-star/Lex-Machina. Safely prune stale git worktrees and local branches left over from past sessions, deleting only those with no unique work so no commit is ever lost.

When should I use Git Worktree Prune?

Git Worktree Prune fits situations like: A repo has accumulated worktrees and branches over many sessions and needs cleanup; include prune worktrees; delete stale branches; clean up git worktrees/branches.

How do I install Git Worktree Prune in Claude Code?

Run `npx skills add michaleiatrak-star/Lex-Machina --skill git-worktree-prune -a claude-code`. Or copy the skill folder (.claude/skills/git-worktree-prune in michaleiatrak-star/Lex-Machina) into .claude/skills/git-worktree-prune in your project. Claude Code loads it when a task matches its description.

How do I install Git Worktree Prune in Codex?

Run `npx skills add michaleiatrak-star/Lex-Machina --skill git-worktree-prune -a codex`. Or copy the skill folder (.claude/skills/git-worktree-prune in michaleiatrak-star/Lex-Machina) into .agents/skills/git-worktree-prune in your project. Codex loads it when a task matches its description.

Can I use Git Worktree Prune 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 michaleiatrak-star/Lex-Machina --skill git-worktree-prune -a cursor` (or -a gemini-cli, github-copilot or opencode for the others). To copy it by hand, put the folder in .cursor/skills/git-worktree-prune, .gemini/skills/git-worktree-prune, .github/skills/git-worktree-prune and .opencode/skills/git-worktree-prune in your project.

What does Git Worktree Prune need to run?

Going by SKILL.md and its folder, Git Worktree Prune needs Python for the scripts in its folder and the command-line tools its instructions call (python and git). Our summary lists: Python 3.

Does Git Worktree Prune access the network?

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

Is Git Worktree Prune 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 Prune use?

Git Worktree Prune 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 Git Worktree Prune use?

About 712 tokens (SKILL.md is roughly 2.8k 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 Prune?

Skills that share tags, products or a category with Git Worktree Prune: Build Px4 macOS (PX4/PX4-Autopilot, 13k stars), Git Worktree Isolation (jnMetaCode/superpowers-zh, 8.3k stars), Worktree (AgentsMesh/AgentsMesh, 2.4k stars) and Cursor Composer Task Delegate (Chachamaru127/claude-code-harness, 3.2k stars). The comparison table on this page puts their stars, adoption, token cost, safety result and licence side by side.

Who maintains Git Worktree Prune?

michaleiatrak-star (a GitHub user) maintains it in michaleiatrak-star/Lex-Machina, which has 262 GitHub stars. The repository holds 35 skills in this directory. The repository was last updated on October 9, 2026.

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