# Trash

> Find the git worktrees that are safe to delete, see what each one would lose, and delete them in bulk with safety checks.

The Trash page lists every git worktree that Flow's `drop` tool manages, judges how safe each one is to delete, and deletes the ones you pick. It is the in-app version of `drop -dc`, for anyone whose agents leave a trail of worktrees behind. It never deletes work you haven't seen: unsaved changes, unpushed commits and worktrees still in use are flagged and need a confirmation.

## Open the Trash

- Press `⌃⌥⌘3`, or run **Go to Trash** from the command palette (`⇧⌘P`). Rebind it in Settings › Keyboard as `keyboard.go_to_trash`.
- Click **Trash** in the sidebar's Tools band (its first row by default). After the first scan its badge shows how many worktrees there are.
- From a terminal: `flow-cli page trash`.

## What it scans

The Trash looks at the repos `drop` knows: the favorite and recent repos in drop's global config (`~/.config/drop/config.json`) and every git repo one level under its `reposDir` (`~/src` by default). In each repo it lists only the worktrees drop manages, the ones under the repo's `worktreeDir` (`.worktrees` by default, so `your-repo/.worktrees/...`). The repo's main checkout is never listed. See [drop](https://flow.worldbreakstudios.com/docs/cli/drop.md) for how these are configured.

For each worktree it collects:

- uncommitted files;
- commits ahead of and behind the repo's base branch (its default remote branch, such as `origin/main`);
- how many commits are on neither the base nor any remote-tracking branch;
- the pull request for its branch, read through Flow's GitHub read CLI (`ghx` by default; see [ghx and gitx](https://flow.worldbreakstudios.com/docs/cli/ghx-and-gitx.md));
- its size on disk;
- its last activity: the newest of its last commit and any uncommitted file's modification time;
- Flow notes files under its `.flow/notes/` folder;
- whether an open Flow session has its directory inside the worktree.

A scan runs 30 seconds after launch (for the badge), when you open the page and the last scan is over a minute old, when you press `r` or the refresh button, every 10 minutes while the page is showing, and after every deletion. Sizes, pull requests and push state fill in after the rows appear.

## Verdicts

Every worktree gets one verdict. The first rule that matches wins:

| Order | Condition | Verdict |
|---|---|---|
| 1 | Open in a Flow session, or active within the in-use window (10 minutes by default) | In use |
| 2 | Has uncommitted files | Loses work |
| 3 | Has Flow notes files (they are git-ignored, so the worktree looks clean, but deleting it deletes them) | Loses work |
| 4 | A merged pull request covers it: the PR's head is its current commit, or every commit is pushed | Safe |
| 4 | A merged pull request that doesn't cover it, with commits beyond the base | Loses work |
| 5 | No base branch to compare against | Loses work |
| 6 | Nothing beyond the base, and git confirms it is merged into the base | Safe |
| 6 | Nothing beyond the base, but git could not confirm it | Loses work |
| 7 | Commits beyond the base, all of them on a remote | Pushed |
| 8 | Anything else (commits that exist nowhere else) | Loses work |

The list's sections use these titles:

| Section | Meaning |
|---|---|
| Safe to delete | Clean, and merged or nothing beyond the base. |
| Pushed | Clean; every commit is on the remote. |
| Would lose work | Uncommitted changes, or commits nowhere else. |
| In use | A Flow session is open in it, or it was touched within the in-use window. |

Anything Flow cannot prove is never called safe: a push state or pull request still loading, a missing base branch and a failed comparison all count as Loses work. A pull request alone proves nothing; a merged one covers a worktree only while the worktree is still at the commit it merged. Verdicts are recomputed all the time, so a worktree moves out of In use by itself once it goes quiet.

## What the page shows

- **The headline**: how much is safe to delete (for example "8.9 GB is safe to delete"), a line counting the worktrees that are safe, would lose work, or are in use, the key legend, and when the list was last updated.
- **The toolbar**: four selection presets, the filter, **Group**, **Sort** and the refresh button.
- **Sections**: each with its title, description, count, total size and a **Select all** / **Deselect** button.
- **Rows**: a checkbox; the worktree's name over its repo, branch and `↓behind ↑ahead` counts; the verdict over its reason (for example "Merged in #333" or "3 uncommitted files"); the size over a bar; the age; and the pull request chip over its title. Click the chip to open the pull request.
- **The inspector** for the focused row: the repo and the base it is compared with, the worktree's path, its verdict with an explanation, its facts (Branch, Commits, Changes, Notes when it has some, Disk, Last touched, Pull request), up to five of its uncommitted files and up to four of its commits beyond the base. Its buttons are **Open terminal** (a new session in the worktree), **Reveal in Finder**, select, and **Delete worktree**.
- **The dock**, while anything is selected: "N selected", their total size, how many would lose work, the **Delete branches too** switch, **Clear** and **Delete N**. After a deletion it shows what was deleted.

**Group** switches between sections by verdict and one section per repo. **Sort** switches between largest first and oldest activity first. The filter (**Filter worktrees**) matches the worktree's name, branch, repo, pull request title and `#number`.

## Delete worktrees

1. Select worktrees with their checkboxes, `space`, a section's **Select all**, or a preset.
2. Turn on **Delete branches too** in the dock if you also want each worktree's local branch deleted. It starts off every time Flow launches.
3. Press `⌫` or click **Delete N** in the dock. For a single worktree, you can use **Delete worktree** in the inspector instead.
4. If the selection needs a confirmation, a dialog opens. Otherwise the worktrees are deleted at once.

The presets select from all worktrees, not only those the filter shows:

| Preset | Selects |
|---|---|
| Safe | Every worktree whose verdict is Safe. |
| Merged | Worktrees whose current commit is in a merged pull request, and not in use. |
| Even with main | Clean worktrees with no commits beyond the base, and not in use (`m`). |
| Stale > 5d | Clean worktrees untouched for more than 5 days, and not in use (`s`). |

A worktree with Flow notes belongs to no preset. `a` selects every worktree the filter shows.

### The confirmation

By default the dialog opens only when a selected worktree would lose work or is in use. Set **Confirm deletes** to **Always** to be asked every time.

The dialog's title names what you are deleting ("Delete 6 worktrees?"), its text says how much it frees and whether anything is lost, it lists up to eight worktrees that hold work ("and N more" past that), and it says whether local branches go too. Its buttons:

- **Cancel**.
- **Delete the N safe**, when the selection mixes safe and risky worktrees. It deletes only the safe ones.
- **Delete anyway** (one worktree), **Delete all N** (several with risk), or **Delete N** (no risk).

`↩` runs the default button: the safe ones alone when that button is offered, otherwise everything. `Esc` cancels, and so do clicking back into the main window, leaving the page and the app locking.

The dialog is frozen when it opens, so a click deletes exactly what it lists. If a rescan under it drops a listed worktree or changes its verdict, uncommitted state or commit, the dialog closes with "Worktrees changed — review and try again" and nothing is deleted.

## Safety checks

- Just before deleting, Flow checks each worktree's commit and branch again. One that moved since the scan is refused with "Changed since the scan — refresh and try again".
- Flow forces the removal only for a worktree that the scan showed with uncommitted files. If a worktree that looked clean has gained changes since, git refuses and the toast shows git's reason; the work stays.
- Only local branches are ever deleted, and only when **Delete branches too** is on: never the base branch or the main checkout's branch. No remote is touched.
- The groups' current directories are checked again when you ask to delete, so a session you just opened counts as In use.
- One deletion runs at a time, and a rescan follows it.

## Keyboard

These keys work while the page is showing and the filter is not focused:

| Key | Action |
|---|---|
| `j` / `↓`, `k` / `↑` | Move the focus down or up. |
| `space` | Select or deselect the focused worktree. |
| `a` | Select every worktree the filter shows. |
| `m` | Toggle the Even with main preset. |
| `s` | Toggle the Stale preset. |
| `r` | Rescan. |
| `⌫` / `delete` | Delete the selection. |
| `Esc` | Clear the selection. |
| `/` | Focus the filter. |

In the filter, `↑` and `↓` still move the focus, and `↩` or `Esc` hands the keyboard back. `⌘` shortcuts keep their usual meaning.

## Settings

The first two are in Settings › Tools › Trash.

| Key | Type | Default | Effect |
|---|---|---|---|
| `trash.confirm` | string | `risky` | **Confirm deletes**: `risky` asks only when work would be lost or a worktree is in use; `always` asks every time. |
| `trash.live_minutes` | number | `10` | **In-use window**, 1 to 120 minutes: a worktree touched this recently counts as In use and is never offered as safe. |
| `trash.group` | string | `verdict` | `verdict` or `repo`; written when you click **Group**. |
| `trash.sort` | string | `largest` | `largest` or `oldest`; written when you click **Sort**. |
| `trash.devices` | string | `all` | With Puddles, which devices' worktrees show: `local`, `all` or a device id. |

## From the command line

`flow-cli` can read the last scan and delete worktrees without the dialog, which lets a coding agent clean up with you:

```sh
flow-cli read trash                                       # this Mac's worktrees from the last scan
flow-cli read trash --all                                 # plus every paired device's
flow-cli trash-delete ID --head HEAD --branch BRANCH      # repeat per worktree; add --dirty if it had changes
```

Each row of `read trash` has an `id`, `path`, `repo`, `branch`, `head`, `dirty_count`, `ahead`, `unpushed`, `pr`, `size_text`, `verdict` (`safe`, `pushed`, `loses_work` or `in_use`) and `reason`. Pass back what you read: a worktree that changed since is refused as a conflict. This route deletes only Safe or Pushed worktrees, always keeps branches, and is refused on a Mac whose **Confirm deletes** is **Always**. Anything that would lose work has to be deleted on the page. See [flow-cli](https://flow.worldbreakstudios.com/docs/cli/flow-cli.md) for the rest of the CLI.

## Other devices

With [Puddles](https://flow.worldbreakstudios.com/docs/features/puddle.md) on, a chip row under the headline (**This Mac**, **All devices**, and one chip per connected device) adds other Macs' worktrees to the list, each with its device badge, greyed "as of" while that device is offline. You can delete another device's worktree only while that device is connected and only when it is Safe or Pushed; the deletion runs on that Mac. Its rows have no detail, **Open terminal** or Finder button.

## Limits

- Only worktrees under a known repo's `worktreeDir` appear. Worktrees made elsewhere, and repos drop does not know, are not scanned.
- Without pull request data (the GitHub read CLI failing for a repo), a worktree with commits beyond its base is at best Pushed, never Safe.
- The Stale preset's threshold is fixed at 5 days.
