agents/skills/clean-worktrees/SKILL.md
Audit and clean agent-created Git worktrees (Codex, Claude Code, OpenCode, Pi, or plain `git worktree add`) and leftover worktree directories safely. Use when disk usage appears inflated by `~/.codex/worktrees`, per-repo `.claude/worktrees`, `.worktrees`, other agent worktree roots, Git worktree metadata, detached worktrees, stale branch worktrees, or when the user asks to map worktrees to pull requests before deletion.
npx skillsauth add carterdea/dots clean-worktreesInstall this skill globally with one command. Works with Claude Code, Cursor, and Windsurf.
3 of 9 scanners reported clean
Some scanners were skipped, did not run, or reported a non-clean status. Review each row below.
Use this skill when any agent's worktree root is large, when git worktree list has accumulated cruft, or when the user asks which worktrees are safe to remove. Works for every harness that creates worktrees.
Different agents use different conventions. Scan all that apply:
~/.codex/worktrees (global, one dir per worktree)<repo>/.claude/worktrees/* or <repo>/.worktrees/*<repo>/.opencode/worktrees/* or shared ~/.config/opencode/worktrees, depending on setup<repo>/.pi/worktrees/* or ~/.pi/agent/worktreesgit worktree add <path> <branch>The default script mode scans every registered worktree for the target repo except the primary checkout, so all of the above are covered automatically. Use --root (repeatable) to narrow scope.
Measure disk first:
df -h / /System/Volumes/Data
du -sh ~/.codex/worktrees 2>/dev/null
find . -maxdepth 3 -type d \( -name worktrees -o -name ".worktrees" \) -exec du -sh {} \; 2>/dev/null
Audit before cleanup. Locate clean_worktrees.py under whichever agent skill dir is installed (any of these symlink to the same file):
~/.claude/skills/clean-worktrees/scripts/clean_worktrees.py~/.agents/skills/clean-worktrees/scripts/clean_worktrees.py (Codex)~/.config/opencode/skills/clean-worktrees/scripts/clean_worktrees.py~/.pi/agent/skills/clean-worktrees/scripts/clean_worktrees.pyAudit-only (all worktrees for a repo):
python3 ~/.claude/skills/clean-worktrees/scripts/clean_worktrees.py \
--repo ~/path/to/repo \
--audit-dir ~/.worktree-cleanup-audit \
--min-age-hours 24
Narrow to a specific root (repeatable):
python3 ~/.claude/skills/clean-worktrees/scripts/clean_worktrees.py \
--repo ~/path/to/repo \
--root ~/.codex/worktrees \
--root ~/path/to/repo/.claude/worktrees \
--root ~/path/to/repo/.worktrees \
--audit-dir ~/.worktree-cleanup-audit
Interpret risk:
Apply cleanup only after the audit result is clear:
python3 ~/.claude/skills/clean-worktrees/scripts/clean_worktrees.py \
--repo ~/path/to/repo \
--audit-dir ~/.worktree-cleanup-audit \
--apply \
--include-dirty \
--min-age-hours 24
Prune repository metadata after removals (script already runs this on --apply, but safe to repeat):
git -C ~/path/to/repo worktree prune
Verify:
git -C ~/path/to/repo worktree list --porcelain
du -sh ~/.codex/worktrees 2>/dev/null
df -h / /System/Volumes/Data
For named branch worktrees, map branches to PRs before deletion:
gh -C <repo> pr list --head <branch> --json number,title,url,state,headRefName,baseRefName
Detached worktrees do not map cleanly to PRs by branch. Treat them as not PR-backed unless the worktree has a named branch or a remote branch can be inferred from local metadata.
rm or rm -rf.~/.worktree-cleanup-audit.git status --porcelaingit diff --binary24 hours, to avoid deleting active sessions.worktree remove --force for registered worktrees.--root) to ~/.Trash/worktrees/<timestamp>/ instead of deleting them directly. Override via --trash-dir.development
Ship a Trello ticket end to end on any web app (Vercel, Fly.io, or other host — no Shopify): pull the latest main, read the card including Figma links, implement the change in a worktree, run the project's own tests/lint/typecheck, run de-slop and code-simplifier and fold the worthwhile cleanups in, QA desktop and mobile on a local Portless preview URL, capture screenshots, open or update the GitHub PR, link the PR and Trello to each other, attach screenshots to both, comment on the card, and move it to review. Use this whenever the user points you at a Trello card or ticket for a code task and wants it delivered as a reviewable PR — phrases like 'do this Trello ticket', 'ship this card', 'pick up this ticket and open a PR', 'update the PR for this card', or names a card/list/board with a feature or bug to implement. This is the default Trello-to-PR workflow for non-Shopify projects; for Shopify theme work use shopify-trello-delivery instead.
tools
Install or upgrade a quality baseline for Shopify theme repos. Use this whenever the user asks to add Shopify theme linting, Biome, Theme Check, Playwright accessibility checks, Vitest, Vite build tooling, lefthook hooks, GitHub Actions CI, Shopify Lighthouse CI, Claude Code PR review workflows, or a context-efficient run_silent.sh setup across Shopify sites.
development
Run an extremely strict maintainability review for abstraction quality, giant files, and spaghetti-condition growth. Use for a thermo-nuclear code quality review, thermonuclear review, deep code quality audit, or especially harsh maintainability review.
development
Ship Shopify theme work from a Trello ticket end to end: inspect the card including Figma links, implement the theme change, deploy or update the correct preview/dev theme, browser-QA desktop and mobile against Figma when available, create or update the GitHub PR, attach screenshots, comment on Trello, and move the card forward. Use this whenever the user mentions a Shopify theme task with a Trello card, Figma design/artboard, preview theme, Customizer, dev theme, PR handoff, Ready for Review/Testing, or asks to update an existing Shopify PR from a ticket.