clean-worktrees

Delete non-main agent worktrees and orphaned worktree-agent- branches.

Updated Apr 17, 2026
One-click install
npx skills add https://github.com/smallorbit/smallorbit-plugins --skill clean-worktrees
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: clean-worktrees
Source: https://github.com/smallorbit/smallorbit-plugins/tree/main/plugins/swarmkit/skills/clean-worktrees
Command: npx skills add https://github.com/smallorbit/smallorbit-plugins --skill clean-worktrees

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill requires git, jq, and includes scripts (resource) components.

What problem does it solve?

Remove clutter from Git worktrees by deleting all agent worktrees (non-main) and their orphaned local branches that start with worktree-agent-.

Core Features & Use Cases

  • Enumerates current worktrees and identifies those to remove and to prune, based on naming conventions.
  • Deletes non-main worktrees and orphaned branches safely, with safety checks to avoid touching the main repo or active worktrees.
  • Supports post-run cleanup in swarmkit workflows and regular maintenance of local repos.

Quick Start

Run clean-worktrees to automatically remove all non-main agent worktrees and their orphaned branches

Frequently Asked Questions about clean-worktrees

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
What is the best way to prune orphaned git branches left behind by swarm agents?

To automate git worktree cleanup, the script targets non-main agent worktrees and their associated orphaned branches. It enumerates current worktrees, validates their state, and performs safe deletions to remove clutter from local git repositories.

How can I safely delete non-main worktrees without affecting my active repository?

Cleaning up swarm agent worktrees requires git and jq installed. The script uses jq to enumerate worktrees and validate state, ensuring safe deletions of branches and directories without touching the main repository or active worktrees.

Why does my local repository accumulate orphaned branches starting with worktree-agent-?

Automating git worktree pruning for routine maintenance involves running a cleanup script to remove non-main worktrees and orphaned branches. This supports regular maintenance of local repos and post-run cleanup in swarmkit workflows by safely pruning directories and branches.

Do I need jq to prune orphaned branches from my local git repository?

You should avoid automated worktree cleanup if you have active non-main worktrees that need to be preserved. The cleanup process targets non-main agent worktrees and orphaned branches for safe deletion, so running it during active swarmkit workflows might disrupt ongoing tasks.