--- name: tidy description: Use when worktrees pile up beside the checkout or the person asks to clean them up. Gives every linked worktree a verdict, safe or keep, and removes the safe ones. --- # Tidy Say which worktrees are finished and remove those, wherever they live and whoever made them. A worktree marked keep is never touched. Most agent worktrees go without this skill. Once per session, at its start, the board runs the same script with `--remove-safe --unasked --only=` on the agent worktrees no one may be using (not locked, no agent or git write in the last ten minutes, no ticket on it that is not `done` or `dropped`) and that changed since they were last kept, toasts how many went and names each kept one once with its reason. A landing's move to `done` removes what it landed the same way. Unasked, a commit counts as held only by another local branch, and only a `worktree-agent-*` branch is deleted. This skill is for the rest, and for a kept one the person wants looked at now: worktrees a person made, branches and folders an older version left. ## Steps 1. **Look.** From the main checkout run: ```bash node "${CLAUDE_PLUGIN_ROOT}/scripts/worktrees.mjs" ``` It prints one row per linked worktree: path, branch, uncommitted or untracked files, commits on no remote and not merged into the main checkout's branch, locked, last commit date, and the verdict. `safe` means nothing is uncommitted, nothing is only there, no rebase, merge or bisect is in progress, and it is not locked. Only there includes ignored files: one the main checkout lacks or holds with other content (a `.env`, a local database), or an ignored folder the main checkout does not have. Installed or built folders the main checkout has too still read safe. A worktree that holds a submodule is always `keep`, because git does not remove one. Anything else is `keep` with the reason. 2. **Show it.** Paste the table, then one line: how many can go, how many stay and why, in plain words (`12 can go. 5 stay: 3 have uncommitted files, 2 hold a commit that is on no remote.`). When the script prints a line starting `Safe, and named by a person`, show that line as it is before anything is removed: those folders or branches carry a name someone chose, not an agent's. Agent-named safe ones stay a count. 3. **Remove.** When the person asked for the cleanup, go on at once. Otherwise ask once whether to remove the safe ones and wait for the yes. Then run: ```bash node "${CLAUDE_PLUGIN_ROOT}/scripts/worktrees.mjs" --remove-safe --named ``` `--named` takes the person-named ones you showed in step 2 too; without it they stay. It re-reads every worktree, judges each safe one again right before it touches it and keeps it with the reason when it changed, removes it with a plain `git worktree remove` (never forced), and deletes a branch only when another branch or a remote holds its commits and `git branch -d` accepts it. Before a folder goes, every junction or symbolic link inside it, at any depth, that leads out of it is taken away as a link, so the removal cannot delete files through it. A worktree kept by its verdict or by that second look keeps its links. The same run also lists local `worktree-agent-*` branches that have no worktree, safe when merged or empty and keep with the commit count otherwise. Hundreds of safe ones print as one count line with the keeps named, so show that line as it is and never list them one by one. To find worktree folders an older version left under the home directory that git no longer knows, pass the folder to look under (the older version's worktree folder, one folder per project inside it) as an argument to both commands. A folder is safe only when every file in it matches something the repository already holds; `--remove-safe` removes just those. 4. **Report** what it removed, which branches it kept and why, and what stays. ## Rules - Never remove, force, unlock or clean a worktree marked keep, and never delete a branch `git branch -d` refuses. Its reason goes in the report; what to do with it is the person's call. - Not while agents run. A worktree an agent just got has nothing in it yet and reads as safe. When the board shows running agents, wait until they return. - `--json` prints the same report as JSON.