# Safety model (/docs/concepts/safety-model)

purgeit assumes every scan result is stale by the time you act on it, and that **a directory's name never proves it is regenerable**.

## At scan time [#at-scan-time]

<Steps>
<Step>
**Rules** decide what is a candidate: names that are unmistakable anywhere (`node_modules`, `.next`), names proved by a manifest beside them (`target` needs a `Cargo.toml` or `pom.xml`; `coverage`, `out` and `.cache` need a project manifest), directories proved from the inside (`venv` needs the `pyvenv.cfg` a virtualenv always contains), and caches that declare themselves with a tag file. A name that is also a common word for *authored* folders is never trusted on its own.
</Step>

<Step>
**Measure.** One traversal per candidate gives allocated size, file count and the newest modification inside. Symlinks are never followed.
</Step>

<Step>
**Protection** marks a candidate as protected when it contains its own `.git` (a checkout, not output), a `*-keypair.json` within three levels (for example Anchor's `target/deploy` keys, a program's on-chain identity), or any file git tracks. If git cannot answer, the candidate is *unverified* and also protected. A protected candidate is listed with its reason and can never be selected.

Purgeit also records **whether git ignores the directory** — evidence it isn't authored — and **whether it sits in a cloud-synced folder** (Dropbox, iCloud, OneDrive, Google Drive), where deleting thousands of files triggers slow syncs. Both are shown in the UI and in `purgeit explain`.
</Step>
</Steps>

## At deletion time [#at-deletion-time]

Everything is re-derived from the filesystem as it is now. A path is **refused, with a reason**, unless all of this holds:

1. It is not a filesystem root or your home directory.
2. It still exists and resolves strictly **inside a scanned root** — this defeats a symlink swapped in after the scan.
3. It is still a real directory (not a symlink) and **a rule still claims it**.
4. The protection checks above still pass.
5. Nothing inside changed within `--min-age` (7 days for `clean`).
6. If it came from a scan or plan, nothing inside changed **after** that scan.

The delete then targets the *verified real path*, so an ancestor swapped for a symlink between the check and the delete cannot redirect it. Anything that cannot be verified is refused. One refusal never stops the rest.

## Human in the loop [#human-in-the-loop]

- The UI preselects nothing, and needs an explicit review (`enter`) and `y`.
- `clean` asks for confirmation unless `--yes`, and without a terminal it refuses to delete at all rather than guess.
- `--dry-run` runs every check and deletes nothing.

## Records [#records]

Deletions and failures are appended to a history file (see `purgeit history`). The package itself is published with signed provenance, so you can verify what you install with `npm audit signatures`.

## What it will not do [#what-it-will-not-do]

- It never follows symlinks while scanning or measuring.
- It never enters version-control directories.
- It never deletes the directory you scanned, or anything outside it.
- It does not send data anywhere: there is no telemetry and no network access.