Skip to content
Back to skills

Worktrees

ASecurity

Audits and optionally prunes git worktrees: current repo by default, cross-repo scan under ~/dev/ with --all. Use when the user says '/worktrees', 'audit worktrees', or 'prune worktrees'.

  • 17 stars
  • 0 votes
  • 0 copies
  • 2 views
  • Added August 31, 2026
ai-agentsgogit

Security analysis

A100/100

Scanned October 2, 2026

npx -y skills add domengabrovsek/claude --skill worktrees --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Worktrees?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for Worktrees
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/domengabrovsek-worktrees/badge)](https://www.skillsdirectory.com/skills/domengabrovsek-worktrees)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
SKILL.md
---
name: worktrees
description: "Audits and optionally prunes git worktrees: current repo by default, cross-repo scan under ~/dev/ with --all. Use when the user says '/worktrees', 'audit worktrees', or 'prune worktrees'."
---

Run worktree cleanup: $ARGUMENTS

## Modes

- **No flags**: single-repo dry-run against `$PWD`. Reports SAFE / KEEP verdicts and exits without changes.
- **`--apply`**: actually remove the SAFE worktrees and delete their local branches.
- **`--all`**: switch to cross-repo audit. Walks `~/dev/` (or `--root <path>`) up to 4 levels deep, finds every git repo, runs the same SAFE / KEEP report per repo. Combine with `--apply` for bulk removal.

## Implementation

Strip the `--all` flag from `$ARGUMENTS` and dispatch:

- If `--all` was passed: `~/.agents/scripts/worktree-prune.sh audit-all <remaining-args>`
- Otherwise: `~/.agents/scripts/worktree-prune.sh <args>`

## Safety rule

A worktree is "safe to remove" only if its branch is:

- **upstream-gone** (the remote branch was deleted, typically after PR merge), OR
- **merged into the repo's default branch** (`origin/HEAD` or `main`/`master`), OR
- **squash-merged**: the branch tip is not an ancestor, but merging it into the default branch produces the default branch unchanged. This catches squash merges that never deleted the remote branch.

Locked worktrees are unlocked iff they pass the safety rule. Default-branch checkouts are never removed. Worktrees with unmerged commits or open PRs are kept.

## Tips

- Run `git fetch --prune origin` first to refresh remote-tracking branches. The script does NOT fetch automatically (network cost across many repos in `--all` mode). The `merged-into-default` check works offline.
- The `SessionEnd` hook runs the equivalent of `/worktrees --apply` opportunistically on session close, so manual invocation is rare for actively-used repos. Reach for `/worktrees --all` mostly for periodic cross-repo hygiene.

Attribution

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

Comments

Loading comments…

Newsletter

Get the weekly list of safe new skills, and the ones we pulled.