Skill

/hanzo-web:clean-worktrees

Borra con seguridad los worktrees de tareas ya mergeadas en develop, junto con sus ramas locales.

Fuente: plugins/hanzo-web/skills/clean-worktrees/SKILL.md · hanzo-web v0.2.0

  • Claude Code /hanzo-web:clean-worktrees
  • Cursor /clean-worktrees

Cuándo usarlo

Cuando se acumulan worktrees de tareas terminadas o el repositorio ocupa demasiado.

Qué hace

  • Hace primero una simulación y te enseña qué worktrees borraría, cuáles conserva y por qué.
  • Solo borra un worktree si su merge está en develop y no tiene cambios sin commitear.
  • De los que conserva te explica el motivo, y pregunta antes de hacer nada a mano.
  • Te dice cuánto espacio ha liberado y qué worktrees quedan.

Qué te entrega

Qué se ha borrado, qué se ha conservado y por qué, y el espacio liberado.

Pídelo así

/hanzo-web:clean-worktrees

O con tus palabras: «limpia worktrees», «borra los worktrees mergeados».

A tener en cuenta

También puede instalar una limpieza diaria automática en macOS (launchd), si la activaste en init y das tu permiso.

Definición en el plugin

Las instrucciones que sigue la skill, tal como están en el plugin (en inglés).

Qué hace

Remove worktrees of a Hanzo project whose MR is merged into develop (and their local branches), safely; also install or check the optional daily launchd cleanup.

Cuándo usarlo

Use when the user says "limpia worktrees", "borra los worktrees mergeados" or asks why the repo/disk is so big.

Paths: ${CLAUDE_PLUGIN_ROOT} is this plugin's folder (Claude Code expands it). If you see it literally (e.g. in Cursor), use the "Plugin scripts" path from the session context, or the plugin folder two levels above this skill (../../ from the folder of this SKILL.md).

Script: ${CLAUDE_PLUGIN_ROOT}/scripts/clean-merged-worktrees.sh --repo <main checkout> [--dry-run]. It reads git.develop, git.production and project.slug from <main>/.claude/hanzo-project.json and logs to ~/Library/Logs/hanzo-<slug>-worktree-cleanup.log.

  1. Preview with --dry-run. Show the result in a short table: worktree → remove / keep (reason).
  2. Run it without --dry-run. It removes a worktree only if origin/<develop> has its Merge branch '<branch>' into '<develop>' commit (plus <production> for release/*), every touched file matches the merge, and only .DS_Store files are uncommitted.
  3. For each kept worktree, explain why (uncommitted changes, commits not in develop, no merge commit — e.g. squashed or renamed MR) and ask before doing anything by hand (git -C <wt> status --short, git cherry origin/<develop> <branch>, then git worktree remove + git branch -D). Never discard uncommitted work without an explicit yes.
  4. git worktree prune, then report freed space (du -sh <config.worktrees.dir> before/after) and remaining worktrees.

Daily automatic cleanup (macOS, optional)

Install only if config.worktrees.dailyCleanup.enabled and the user agrees:

  1. Copy the script to a stable path (the plugin cache path changes on every update): mkdir -p ~/.claude/hanzo-web && cp "${CLAUDE_PLUGIN_ROOT}/scripts/clean-merged-worktrees.sh" ~/.claude/hanzo-web/ && chmod +x ~/.claude/hanzo-web/clean-merged-worktrees.sh.
  2. Fill ${CLAUDE_PLUGIN_ROOT}/templates/worktree-cleanup.plist ({{SLUG}}, {{SCRIPT}} = the stable copy, {{REPO}}, {{HOME}}, {{HOUR}}) into ~/Library/LaunchAgents/com.hanzo.<slug>.worktree-cleanup.plist.
  3. launchctl bootstrap gui/$(id -u) <plist>; test with launchctl kickstart gui/$(id -u)/com.hanzo.<slug>.worktree-cleanup and read both logs.
  4. If the repo is under ~/Documents, ~/Desktop or ~/Downloads, macOS blocks launchd from reading it (Operation not permitted in the launchd log). The user must grant Full Disk Access to /bin/bash themselves (System Settings › Privacy & Security); explain that this applies to every bash script and let them decide.
  5. Behaviour: asleep at the hour → runs on wake; powered off → skipped that day. Uninstall: launchctl bootout gui/$(id -u)/com.hanzo.<slug>.worktree-cleanup, then remove the plist, logs and the stable script copy.

After a plugin update, re-copy the script (step 1) so the daily job uses the new version.