---
description: "Sweep leftover /tmp scratch (picker state, review diffs, channel payloads, analysis drafts), worktree residue (orphan .worktrees dirs, gitlink index entries) and offloaded tool payloads under .multi-agent/refs/ from past runs. With --abandoned, also reaps runs that stopped and were never picked back up, stashing any uncommitted work. Dry-run first; confirms before deleting. Invoked only when the user types it."
disable-model-invocation: true
description-tr: "Geçmiş çalışmalardan kalan /tmp scratch'ini (picker durumu, review diff'leri, kanal payload'ları, analiz taslakları), worktree kalıntılarını (sahipsiz .worktrees klasörleri, gitlink index kayıtları) ve .multi-agent/refs/ altındaki offload edilmiş araç çıktılarını süpürür. --abandoned ile durup bir daha dönülmemiş koşuları da toplar, commit edilmemiş işi stash'ler. Önce dry-run; silmeden önce onay alır. Yalnızca kullanıcı yazdığında çalışır."
argument-hint: "[--older-than=<minutes>] [--abandoned [--days=N]] [--yes]  -  dry-run unless confirmed"
parameters: [{"name":"--older-than","kind":"text"},{"name":"--abandoned","kind":"flag"},{"name":"--days","kind":"text"},{"name":"--yes","kind":"flag"}]
gui: button
destructive: true
confirm: required
---

# multi-agent garbage-collect  -  Sweep /tmp Scratch

> **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.

Sweeps run scratch under `/tmp` (known prefixes only), worktree residue,
offloaded payloads and, with `--abandoned`, stopped runs. Backed by
`$HOME/.claude/scripts/gc-tmp.sh` and its siblings. Safe by default: it previews
and deletes nothing until you confirm.

What each phase covers, the abandoned-run line kinds and the scope of each
phase: `$HOME/.claude/multi-agent-refs/garbage-collect/phases.md`. Read it when
explaining a phase's output.

## Steps

1. **Preview (dry-run)**  -  run the sweeper with no `--yes`, forwarding an
   `--older-than=<minutes>` argument if the user supplied one:

   ```bash
   bash $HOME/.claude/scripts/gc-tmp.sh ${ARGUMENTS}
   ```

   It prints each matching item and the space it would free.

2. **Nothing to do**  -  if the output says `nothing to do`, stop and report
   that there is no scratch to clean.

3. **Confirm**  -  surface a native `AskUserQuestion` picker (no typed keyword),
   in `outputLanguage`:
   - `question`: "Delete the listed /tmp scratch items now?" (include the count
     and freed-size estimate from step 1)
   - `header`: "Sweep" (English, <=12 chars)
   - `options`: `{ label: "Delete scratch", description: "Remove the listed /tmp items" }`,
     `{ label: "Cancel", description: "Keep everything, change nothing" }`
   - Anything other than **Delete scratch** -> cancel and change nothing.

4. **Delete**  -  on confirm, re-run with `--yes` (and the same
   `--older-than` if given):

   ```bash
   bash $HOME/.claude/scripts/gc-tmp.sh --yes ${ARGUMENTS}
   ```

5. **Report**  -  echo the `══ garbage-collect: removed N item(s), freed ~X ══`
   summary line.

6. **Worktree residue sweep (second phase)**  -  when the current directory is
   a git repo, also preview worktree leftovers:

   ```bash
   bash $HOME/.claude/scripts/gc-worktrees.sh ${ARGUMENTS}
   ```

   Registered, healthy worktrees are NEVER touched  -  those belong to
   `/multi-agent:resume` / `/multi-agent:kill`.

   - Output says `nothing to do` -> skip silently, no question.
   - Otherwise surface a second `AskUserQuestion` (in `outputLanguage`):
     `question`: "Apply the listed worktree cleanups?" (include the dry-run
     lines), `header`: "Worktrees", options `{ label: "Apply cleanups" }` /
     `{ label: "Cancel", description: "Keep everything, change nothing" }`.
   - On confirm, re-run with `--yes` and echo its summary line. If a gitlink
     was unstaged, remind the user the removal still needs a commit.

7. **Offloaded payload sweep (third phase)**  -  when the current directory is a
   git repo, also preview the offloaded tool payloads:

   ```bash
   bash $HOME/.claude/scripts/gc-refs.sh ${ARGUMENTS}
   ```

   Only node-id-shaped files under `.multi-agent/refs/` are touched, and files
   inside the grace window are spared.

   - Output says `nothing to do` -> skip silently, no question.
   - Otherwise surface a third `AskUserQuestion` (in `outputLanguage`):
     `question`: "Delete the listed offloaded payloads?" (include the count and
     freed size), `header`: "Payloads", options `{ label: "Delete payloads" }` /
     `{ label: "Cancel", description: "Keep everything, change nothing" }`.
   - On confirm, re-run with `--yes` and echo its summary line.

   Pass `--all` to sweep every checkout under `$HOME` rather than only the
   current repo.

8. **Abandoned runs (fourth phase, only with `--abandoned`)**  -  the other three
   phases sweep leftovers from runs that ENDED. This one reaps runs that simply
   stopped:

   ```bash
   bash $HOME/.claude/scripts/gc-abandoned.sh ${ARGUMENTS}
   ```

   The line kinds (`would remove`, `would stash`, `would mark abandoned`, the
   unattended-run keep lines, `refused`, `unattributed`) are not
   interchangeable; their table is in `phases.md`. An `unattributed` worktree
   is **never removed, whatever the flags**: report the list and its size; the
   user decides. An unattended run's worktree is **kept**, never inspected
   with git; a `refused` run is left as it is, and the line says why.

   Three rules hold with or without `--yes`: a run waiting on you (open PR,
   Phase 4/5, `awaiting_input`) is never touched; a path outside
   `<repo>/.worktrees/` is never removed; and uncommitted work is stashed rather
   than lost (an unattended run's worktree is kept whole instead).

   - Output says `nothing to do` -> skip silently, no question.
   - Otherwise surface a fourth `AskUserQuestion` (in `outputLanguage`):
     `question`: "Reap the listed abandoned runs?" (include the counts, the
     freed-size estimate, and the unattributed total as a separate sentence -
     those are not being reaped), `header`: "Abandoned",
     options `{ label: "Reap runs" }` / `{ label: "Cancel", description: "Keep everything, change nothing" }`.
   - On confirm, re-run with `--yes` and echo its summary line. If anything was
     stashed, name the branch so the user can recover it.

## Notes

- An in-flight analysis keeps its drafts in `/tmp/analysis-<slug>-<timestamp>/`
  and `/multi-agent:resume` re-uses them. If a run is paused at
  `awaiting_output_decision`, pass `--older-than=<minutes>` so fresh drafts are
  spared, or finish the run first.
- Per-task logs (`/multi-agent:prune-logs`) and the per-repo memory stores
  (`/multi-agent:uninstall --all-data`) are never swept here; see `phases.md`,
  "Scope of each phase".
