---
description: "Free disk space with the disk cleaner: measure every category, pick what to delete, apply, report the space freed. Invoked only when the user types it."
disable-model-invocation: true
description-tr: "Disk temizleyiciyle yer açar: her kategoriyi ölçer, neyin silineceğini seçtirir, uygular, açılan alanı raporlar. Yalnızca kullanıcı yazdığında çalışır."
argument-hint: "[autopilot]  -  dry-run first; nothing is deleted before you choose"
parameters: [{"name":"autopilot","kind":"flag"}]
gui: button
destructive: true
confirm: required
allowed-tools: Bash, AskUserQuestion
---

# multi-agent clean-disk  -  Measure, Choose, Apply, Report

> **Pickers follow** `$HOME/.claude/multi-agent-refs/picker-contract.md`: never a one-option call, and branch on the option selected, not on its text.

Runs `$HOME/.claude/scripts/disk-cleaner.mjs`, the measure-first cleaner the
disk-cleaner skill uses. It deletes regenerable data from a fixed category
allowlist only, and checks every path again right before deleting it. It
never stops a process: leftover session processes appear in the report as
information. This command wraps it in one flow: measure, show where the space
comes from, choose, apply, report.

```bash
DC="$HOME/.claude/scripts/disk-cleaner.mjs"
```

**Unattended** means `MULTI_AGENT_UNATTENDED=1` is set or `autopilot` is in
`${ARGUMENTS}`. It asks nothing and keeps to the script's own safe set: no
Trash, no transcripts, no worktrees, no archives, no device support, no
simulator runtimes, and nothing held back only because it was touched
recently.

## Steps

1. **Measure (dry run)**. Nothing is deleted. Measure every category, the
   two opt-ins included so their sizes are known:

   ```bash
   node "$DC" --dry-run --json --top=5 --trash --transcripts > "${TMPDIR:-/tmp}/clean-disk-plan.json"
   ```

   Unattended, measure the safe set only:

   ```bash
   node "$DC" --dry-run --json --top=5 --unattended > "${TMPDIR:-/tmp}/clean-disk-plan.json"
   ```

2. **Show where the space comes from**, in `outputLanguage`, before any
   question. From the JSON, per category with items or kept items:
   - the id, the item count (`candidates`) and the size (`bytes`);
   - up to five of its largest items (`top`), each with its size and real
     path, then "and N more" from `more`;
   - why items were kept (`kept`, for example in use, recent, uncommitted
     changes, not merged), and `blocked` when its tool is running, which
     means it is measured but not applied.

   Mark `trash` and `transcripts` as opt-in, and every category `--list`
   does not tag `unattended-safe` as needing its own choice. Then three
   lines: the total reclaimable (`reclaimableBytes`), the free space now
   (`disk.before.freeBytes`) and the free space expected after
   (`disk.expectedFreeBytes`). When `orphans` is not empty, add one line:
   how many leftover session processes were found, information only, never
   stopped. When `held.aged` is above 0, one line: that many items
   (`held.agedBytes`) were kept only because they were touched recently and
   can be included; items in use and recently used session scratch (this
   session's or another open session's) stay held at any age. When `unreadable.count` is above 0, one line: that many folders
   could not be read (permission denied), so the numbers are incomplete;
   giving the terminal Full Disk Access lets the next run measure them. Give
   the report path.

3. **Nothing to do**. When `reclaimableBytes` is 0, report that and stop.

4. **Unattended: apply the safe set, then go to step 7.**

   ```bash
   node "$DC" --apply --unattended
   ```

5. **Choose (attended)**. One `AskUserQuestion` call, in `outputLanguage`.
   The safe categories are offered together; each risky one is its own
   question with its own warning, and is asked only when it measured above
   0 B.

   - **Categories**, `header` "Categories" (English, at most 12 chars):
     "Which categories should be deleted?" with the safe-set size. Options:
     `{ label: "All safe categories", description: "every category tagged unattended-safe, <size>" }`,
     `{ label: "Choose categories", description: "pick from the measured list" }`,
     `{ label: "None of these", description: "Delete nothing from this group" }`.
   - **Trash**, `header` "Trash": "Empty the Trash (<size>)? It holds files
     you deleted yourself; they cannot be recovered afterwards." Options
     "Keep the Trash" (first) and "Empty the Trash".
   - **Transcripts**, `header` "Transcripts": "Delete session transcripts
     older than 90 days (<size>)? `/resume` and past-session search read
     them; deleted sessions can no longer be resumed or searched. Memory
     folders, the current session and open files are never touched."
     Options "Keep transcripts" (first) and "Delete old transcripts".
   - **Recent**, `header` "Recent": "Include <held.aged> items touched
     recently (<held.agedBytes>)? A build may still be writing to them.
     Items in use and recently used session scratch, this session's or
     another open one's, stay held." Asked only when `held.aged` is above
     0. Options "Keep them" (first) and "Include them". The apply in step 6
     measures again, so it deletes what is old enough at that moment, not
     a frozen copy of this list.

   Nothing chosen in any question: stop and change nothing. **Choose
   categories** opens a second call: one `multiSelect` question per group
   of up to four measured categories with items, not counting `trash` and
   `transcripts`. A group never has a single option; a lone leftover joins
   the group before it. When only one category has items, ask "Delete
   <category>?" with "Delete" and "Keep" instead.

   Then build the skip list: every category id from `--list` that was not
   chosen, without `trash` and `transcripts` (their flags decide them).

   ```bash
   # All safe categories: skip what --list does not tag unattended-safe
   SKIP=$(node "$DC" --list | grep -v 'unattended-safe' | awk '{print $1}' \
     | grep -vx -e trash -e transcripts | paste -sd, -)
   ```

   For **Choose categories**, `SKIP` is the ids from `node "$DC" --list`
   minus the chosen ones, minus `trash` and `transcripts`. For **None of
   these** with a risky category chosen, `SKIP` is every id except `trash`
   and `transcripts`.

6. **Apply**. Add `--trash`, `--transcripts` and `--include-recent` only
   when their own question chose them:

   ```bash
   node "$DC" --apply --skip="$SKIP" [--trash] [--transcripts] [--include-recent]
   ```

7. **Report**. Relay the script's last lines in `outputLanguage`: removed
   and failed counts, `freed` with df before and after, every `held` and
   `failed` line, and the report path. Exit 1 means some deletions failed:
   name them. Never retry a refused or failed path with `rm`, `find -delete`
   or a loop of your own; the refusal is the answer.

## Notes

- What the script never touches (personal folders, credentials, memory
  folders, git working trees other than merged clean agent worktrees,
  symlinks, open files, processes) is listed in the disk-cleaner skill.
- Ages and dev roots (`--log-days`, `--transcript-days`, `--build-hours`,
  `--runtime-days`, `--root=<dir>`, `--depth=N`) are the script's options;
  `--exclude=<path>` keeps one item, and anything holding it, out of a run.
  `node "$DC" --help` lists them.
- Pipeline scratch and task logs go through `gc-tmp.sh` and `prune-logs.sh`;
  `/multi-agent:garbage-collect` and `/multi-agent:prune-logs` run those
  alone.
