Skip to content
Agentmart
Submit a tool

git-clean-worktrees

Remove already-preserved linked worktrees and local branches from one repository, only through an explicit plan the user approves by digest.

Skill by lucaspimentel

IndexedMIT
Write a review

Install

Works with Claude Code, Claude apps, Codex, Cursor, Gemini CLI, GitHub Copilot, VS Code, OpenCode, Goose, Windsurf. Read the repository before you give any tool access to your data.

npx agentmarket install skill/lucaspimentel-git-clean-worktrees

Asks which of your tools to add it to (Claude Code, Codex, Cursor, VS Code, Windsurf, Gemini CLI, Claude Desktop) and shows the change first. See https://agentmart.dev/cli.

Get the weekly diff

The weekly diff: one email a week with new agent tools, notable updates and grade changes, plus security alerts for tools you follow. Double opt-in, one-click unsubscribe.

We use your email only for this newsletter. Privacy

About

Remove already-preserved linked worktrees and local branches from one repository, only through an explicit plan the user approves by digest.

No reviews yet. Installed it? Reviews come from verified installers only. How reviews work

Permissions

What this skill can do and what it asks for, from its SKILL.md. Checked Oct 25, 2026.

Tools
No tools found
Secrets
None asked for
Install scripts
None found
Runs as
Python package

Network hosts it talks to 1

  • codeload.github.com · found in install command

Files it touches

  • ~/.claude/skills/git-clean-worktrees

What's inside

Skill name
git-clean-worktrees
Description
Remove already-preserved linked worktrees and local branches from one repository, only through an explicit plan the user approves by digest.
License
MIT
Instructions
63 lines in SKILL.md · view on GitHub

Before installing

  • Ships executable scripts

Files (3)

  • SKILL.md
  • safety.md · references/
  • git_clean_worktrees.py · scripts/

SKILL.md (first lines)

# git-clean-worktrees

Inspect one repository, propose an exact cleanup plan, and remove only the worktrees and local branches the user approves. The helper proves preservation for every exact branch tip before anything is deleted, and it never forces, prunes, unlocks, or touches a remote.

## Before starting

1. **Pick a Python 3.11+ interpreter.** Try `python3`, then `python`, then `py -3` on Windows. Check `--version` and stop if it is older than 3.11.
2. **Resolve the helper path** as `scripts/git_clean_worktrees.py` relative to this skill's own directory. Use that absolute path for every phase; do not resolve it against the current working directory.
3. **Confirm access.** The helper needs filesystem access to the repository and its worktrees, plus network access for `git fetch` and, when needed, the `gh api` merged-PR lookup. In pi, if the sandbox cannot reach the repository or the network, run the commands with the `host_bash` tool instead of the sandboxed `bash` tool. Keep Git, `gh`, and Python in the same environment; the helper does not translate paths between WSL and native Windows.
4. **Keep artifacts outside removal targets.** Write the snapshot, plan, and result JSON somewhere outside every worktree that may be removed, for example the main checkout's `.git` directory or a temporary directory.
5. Run the helper with `--help` if you need the exact flags for the current version.

## Phase 1: inspect

```console
python3 <skill-dir>/scripts/git_clean_worktrees.py inspect [<repository-path>] --output <snapshot.json>
```

The optional repository path defaults to the current directory. It must be inside the main (non-bare) working tree; a linked worktree is rejected.

Inspection removes nothing, but it does fetch the remote's actual default branch into its origin remote-tracking ref, so it writes Git objects, as documented in `references/safety.md`.

The snapshot lists every registered worktree and every local branch with an eligibility decision and an explicit reason. Read it, then decide which targets to propose.

- Worktree ids are the registered absolute paths.
- Branch ids are the short branch names (`topic/x`, not `refs/heads/topic/x`).
- `--allow-ignored` is valid only together with removing that same worktree, and only when the snapshot shows the worktree needs the ignored-file override.

## Phase 2: plan

```console
python3 <skill-dir>/scripts/git_clean_worktrees.py plan --snapshot <snapshot.json> \
  [--remove-worktree <id> ...] [--delete-branch <id> ...] [--allow-ignored <id> ...] \
  --output <plan.json>
```

Worktree removal and branch deletion are separate selections. Removing a worktree never authorizes deleting its branch; select `--delete-branch` explicitly.

Show the user the complete plan and its digest, then wait for explicit approval before continuing. If the user changes any target or ignored-file override, rebuild the plan: the digest changes and the old approval no longer applies.

## Phase 3: apply

```console
python3 <skill-dir>/scripts/git_clean_worktrees.py apply --plan <plan.json> --approved-digest <sha256>
```

Apply revalidates the repository, refreshes the default branch again, rechecks every lock, file protection, fingerprint, and preservation proof, and skips any target that changed or became unsafe. It continues with the other independent approved actions.

Exit codes: `0` every approved action succeeded, `2` some target was skipped or failed, `1` the run aborted before any action.

## Report

Summarize the result for the user: removed worktrees, deleted branches with their recorded SHAs, and every skipped or failed target with the helper's reason. Note that deleting a ref removes its reflog, so a recorded SHA is only recoverable while its objects remain.

## Non-negotiables

- Never select or apply a target that is not in the approved plan, and never widen the approved digest.
- Never use `--force`, `git worktree unlock`, `git worktree prune`, or hand-rolled deletion.
- Never switch GitHub accounts. If `gh` authentication cannot see the origin repository, leave those targets retained.
- Never delete a remote branch.

Detailed safety and concurrency contracts, limitations, and recovery notes live in [references/safety.md](references/safety.md).

From lucaspimentel/agent-skills, MIT.

More from lucaspimentel/agent-skills

Signals

Stars
0
Forks
0
Open issues
0
Last commit (this folder)
Oct 23, 2026 (5 days ago)

From GitHub (fetched Oct 24, 2026).

Details

License
MIT
First seen
Oct 24, 2026
Last checked
Oct 24, 2026

More from lucaspimentel

Cite this page

git-clean-worktrees skill. Agent Mart. https://agentmart.dev/skills/lucaspimentel-git-clean-worktrees (last updated 2026-10-24)