# Contributing (/docs/community/contributing) ```bash bun install # dependencies and git hooks bun run check # format, oxlint, typecheck, knip, tests + coverage, build, package checks ``` Node.js 22+ and [Bun](https://bun.sh) are needed. `bun run check` is the same gate CI and releases run, and takes seconds. ## Conventions [#conventions] - Tests use real temporary directories (`test/tree.ts`). Never scan or delete a shared directory (`/tmp`, `$HOME`). Anything that deletes needs old fixtures: `backdate(root)` or `minAge: 0`. - Assert paths with `rel()`, never literal `/`, and don't hard-code sizes: allocated sizes depend on the filesystem. - Only `src/tui/` may import `react` or `ink` (oxlint enforces it); `bun run doctor` must stay clean. - Deletion goes through `clean()` → `inspect()` only. Never weaken a guard to make a test pass. ## Add an ecosystem [#add-an-ecosystem] 1. Create `src/rules/catalog/.ts` exporting `readonly RuleDefinition[]`. 2. Spread it into `RULE_CATALOG` in `catalog/index.ts`. 3. If it is a new category, add it to `RuleCategory`, `CATEGORY_LABELS` and `CATEGORY_ORDER` in `catalog/types.ts`. 4. Run `bun run generate` — the [rules reference](/docs/reference/rules) is generated from the catalog. Use `safe` only for names that are unambiguous everywhere. Anything generic (`build`, `out`, `bin`) must be `gated` on a manifest. ## Generated files [#generated-files] `purgeit.schema.json` and `docs/src/generated/*` are generated from the code: run `bun run generate` after changing `src/config/schema.ts`, the CLI's options, or the rule catalog (tests fail if they are stale). ## The docs site [#the-docs-site] The site lives in `docs/` — a [Fumadocs](https://fumadocs.dev) app on Next.js with its own dependencies. ```bash cd docs npm ci npm run dev ``` ## Releasing [#releasing] Bump `version`, commit, push `main`, then `git tag vX.Y.Z && git push origin vX.Y.Z`. The tag runs the full `check` gate and publishes to npm with trusted publishing and provenance — no tokens involved. # FAQ & troubleshooting (/docs/community/faq) A project is the nearest git repository (worktrees fold into their main repository) or a manifest folder outside git. It is dormant when git's log shows no commit, checkout or pull for 30 days (`dormantAfter` changes that). See [Projects and dormancy](/docs/concepts/how-it-works#projects-and-dormancy). Artifacts under 10 MB are folded away so the list shows what matters; the header says how many and how much. Press `m` to show them, or pass `--min-size` to set your own floor. Those names are also used for authored folders, so they only match with proof: `target` beside a `Cargo.toml` or `pom.xml`, `out`/`coverage`/`.cache` beside a project manifest, `venv` containing a `pyvenv.cfg`. `purgeit explain ` says exactly what is missing. No. The UI needs an explicit selection plus `y`; `clean` asks unless you pass `--yes`; without a terminal it refuses to delete unless you pass `--yes`. `clean` and the UI print the reason: modified within `--min-age`, changed after the scan, protected (nested repo, deploy keypair, git-tracked files), or no longer claimed by a rule. See the [list of reasons](/docs/guides/clean-safely#when-something-is-skipped). purgeit reports space that deleting would actually free. Files hardlinked to something outside the artifact (pnpm's content store) aren't counted. See [How sizes are counted](/docs/concepts/how-it-works#how-sizes-are-counted). `build` is only matched beside a manifest (`package.json`, `Cargo.toml`, …). Run `purgeit rules` to see the proof each gated rule needs, or [add your own rule](/docs/guides/custom-rules). Permission errors and directories that vanish mid-scan are skipped and counted, never hidden. You are in a pipe, a CI job or a script. Use [`scan` and `clean`](/docs/reference/cli). No — artifacts are regenerable, which is why the rules are strict. `purgeit history` lists what was removed. No. There is no telemetry and no network access. Both are supported. Space is measured from allocated blocks on every platform; `git` is needed only for the tracked-files check. ## It deleted something it shouldn't have [#it-deleted-something-it-shouldnt-have] Please [open an issue](https://github.com/nandan-varma/purgeit/issues) with `purgeit history --format json` and the rule that matched. Safety bugs are treated as top priority. # How it works (/docs/concepts/how-it-works) ## The pipeline [#the-pipeline] ```text roots ─▶ walk ─▶ rules claim directories ─▶ measure ─▶ filters ─▶ protection ─▶ entry │ clean: re-verify every path ◀───────────┘ ``` **Walk.** Directories are read concurrently. A directory a rule claims is never entered (so nested `node_modules` inside `node_modules` are never reached), VCS directories are never entered, and symlinks are never followed. **Rules.** `safe` names match at once. `gated` names are checked against the listing of the directory that holds them — usually free, because the walker already has it. `tagged` caches are recognised by their marker file. **Measure.** One traversal per candidate collects size, file count and the newest modification time. The same traversal later answers "is this empty?" and "was anything touched recently?". **Filter and protect** (`--min-size`, `--min-age`, emptiness, nested repos, deploy keys, tracked files). Results stream out as they are ready, so the UI fills in while the scan is still running. ## Projects and dormancy [#projects-and-dormancy] As the walker descends it knows each directory's listing, so recognising what an artifact belongs to is free: - a directory with a `.git` **directory** is a repository; a monorepo is one project, however many packages it holds; - a `.git` **file** marks a worktree (or submodule). A worktree's file points at the repository it came from, and the worktree is **folded into that project**; - outside git, a directory with a manifest (`package.json`, `Cargo.toml`, …) is a project folder. A project's **activity** is the modification time of git's `HEAD` log: it moves when you commit, check out, pull or rebase, but not on `git status`, and costs one `stat`. A project untouched for `dormantAfter` (30 days by default) is *dormant*. Outside git, the newest change inside its artifacts stands in. That is what lets the UI and `scan` lead with **big and abandoned** instead of simply big. ## Why it is fast [#why-it-is-fast] - A single traversal does the work `du`, `find` and a tree walk used to do separately. - Gated rules are proven from directory listings already in memory. - File-system calls are not throttled in JavaScript: libuv's thread pool is the real limit, and a JS limiter measured about 35% slower. - Commands are loaded lazily, so `purgeit --version` costs Node's startup plus ~30 ms. - Deleting uses Node's `fs.rm`, which measured on par with `rm -rf`. On a real 13 GB, ~50-artifact development folder a full scan takes about two seconds — comparable to `find | du`, while also producing activity and protection data. ## How sizes are counted [#how-sizes-are-counted] Size is **allocated disk blocks** (what `du` reports), not apparent file size. A file hardlinked to something *outside* the artifact — pnpm's content store is the common case — is only counted if every one of its links lives inside the artifact, because only then does deleting the artifact actually free it. So the numbers purgeit shows are what you will get back. # 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] **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. **Measure.** One traversal per candidate gives allocated size, file count and the newest modification inside. Symlinks are never followed. **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`. ## 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. # Using purgeit with AI agents (/docs/guides/ai-agents) purgeit is designed to be driven by an agent: every command has structured output, deletions are re-verified, and guidance ships with the CLI. ## Get the guide [#get-the-guide] ```bash purgeit skill ``` Prints a guide **versioned with the installed CLI**, so it always matches the commands that exist. The package also ships a `SKILL.md` stub for agent-skill installers. This site is agent-friendly too: - Append `.md` to any docs URL, or send `Accept: text/markdown`, to get the page as Markdown. - [`/llms.txt`](/llms.txt) lists every page; [`/llms-full.txt`](/llms-full.txt) is the whole site in one file. ## The workflow an agent should follow [#the-workflow-an-agent-should-follow] **Look first.** `purgeit scan --format json` lists candidates and deletes nothing. The report has a `projects[]` rollup (dormant projects first) as well as every entry. Narrow with `--stale`, `--min-size`, `--min-age`, `--only`. **Show the user** the projects and the total — not hundreds of paths. Entries with a non-null `protection` are never deleted; `purgeit explain --format json` tells you why anything is matched, skipped or protected. **Delete only what was approved.** Trim the report to the approved entries and run `purgeit clean --plan plan.json --yes`. Use `--dry-run` to preview. Don't lower `--min-age` below its default (`7d`) unless the user asks. It is the guard against deleting something a person is working on. ## Why this is safe to hand to an agent [#why-this-is-safe-to-hand-to-an-agent] - Every path is **re-verified at deletion time** against the rules, git, deploy keys and recent activity, so a stale or edited plan cannot delete the wrong thing. See the [safety model](/docs/concepts/safety-model). - Nothing is deleted without `--yes` (or an interactive confirmation), and without a terminal `clean` refuses to guess. - Output is stable JSON with documented [exit codes](/docs/guides/automation#exit-codes) and [formats](/docs/reference/output-formats). With `--format json`, even **errors** are JSON on stdout (`{"error":{"code","message"}}`), so a parser never has to scrape stderr. - Everything deleted is recorded: `purgeit history --format json`. ## Other useful commands [#other-useful-commands] | Command | Use | | --- | --- | | `purgeit rules --format json` | What is matched, and the proof gated rules need | | `purgeit history --format json` | What has been deleted | | `purgeit scan --format ndjson` | Stream results as they are measured | | `purgeit explain --format json` | Why a directory is matched, skipped or protected, and what `clean` would do | # Automation (/docs/guides/automation) Unattended runs should be conservative and leave a trail. ```bash # everything in projects you have not worked on for 30+ days, over 100 MB purgeit clean ~/dev --stale --min-size 100MB --yes ``` `clean` already skips recent activity (default 7 days), re-verifies every path, logs to `purgeit history`, and reports problems through its exit code, so a scheduler can notice. ## Exit codes [#exit-codes] | Code | Meaning | | --- | --- | | `0` | success | | `1` | some paths were skipped or failed, or you declined the confirmation | | `2` | bad arguments, config or plan | | `70` | internal error | | `130` | interrupted (`SIGINT`/`SIGTERM`) | Without a terminal and without `--yes`, `clean` refuses to delete rather than guessing. ## Schedulers [#schedulers] ```text 0 3 * * 0 /usr/local/bin/purgeit clean ~/dev --min-age 30d --yes >> ~/purgeit.log 2>&1 ``` ```xml Labeldev.purgeit ProgramArguments /usr/local/bin/purgeitclean /Users/you/dev--min-age30d--yes StartCalendarIntervalWeekday0Hour3 ``` ```ini # ~/.config/systemd/user/purgeit.service [Service] Type=oneshot ExecStart=/usr/bin/env purgeit clean %h/dev --min-age 30d --yes # ~/.config/systemd/user/purgeit.timer [Timer] OnCalendar=weekly Persistent=true [Install] WantedBy=timers.target ``` ```yaml # free space on a runner before a big build - run: npx purgeit clean ~/ --min-age 0 --only node_modules,target --yes ``` ## Reviewed automation [#reviewed-automation] When a person must approve what an unattended job deletes, split the job in two (see [Clean safely](/docs/guides/clean-safely#3-review-then-apply-a-plan)): the first writes a plan with `scan --format json`; the second runs `clean --plan` after approval. ## Machine-readable output [#machine-readable-output] `scan --format json|ndjson` and `clean --format json` are documented in [Output formats](/docs/reference/output-formats). # Clean safely (/docs/guides/clean-safely) Deleting is the one thing purgeit does that you cannot undo, so it gives you several ways to look before you leap. ## 1. Preview with a dry run [#1-preview-with-a-dry-run] ```bash purgeit clean ~/dev --dry-run ``` Runs *every* check — rules, protection, recent activity — and reports what would be deleted and what would be skipped, deleting nothing. Skipped paths come with the reason. ## 2. Narrow it down [#2-narrow-it-down] | You want | Use | | --- | --- | | Only the big wins | `--min-size 100MB` | | Only projects you have abandoned | `--stale` (not worked on for 30 days — change it with `dormantAfter`) | | Only artifacts untouched for a while | `--min-age 30d` | | Only certain tools' output | `--only node_modules,target` or a [group](/docs/reference/configuration) | | Only proven-safe names | `--safe-only` (skips rules that need a manifest as proof) | | Keep some folders out | `--exclude 'legacy/**'` | ## Ask why [#ask-why] When something is matched, skipped or protected and you wonder why: ```bash purgeit explain ~/dev/app/node_modules ``` ```text ~/dev/app/node_modules rule ✓ node_modules — npm / yarn / pnpm dependencies (safe wherever it appears) project ✓ app (repo, ~/dev/app) · last git activity 5mo ago size ✓ 979.6 MB in 41,230 files · last changed 5mo ago protection ✓ nothing marks it as authored git ✓ ignored by git — evidence it is not authored synced ✓ not in a cloud-synced folder verdict ✓ clean would delete it ``` It runs the **same checks `clean` runs**, so the verdict can never disagree with what would happen. ## 3. Review, then apply a plan [#3-review-then-apply-a-plan] For anything a human should approve, split *finding* from *deleting*: ```bash purgeit scan ~/dev --format json > plan.json # delete the entries you want to keep purgeit clean --plan plan.json ``` A plan only *proposes*. At deletion time every entry is re-checked against the rules, protection and "changed since the scan", so a stale or hand-edited plan cannot delete something that is no longer an artifact. ## The 7-day guard [#the-7-day-guard] `clean` skips anything with a change inside the last **7 days** (`--min-age`, or `minAge` in config; `0` disables). The interactive UI doesn't apply it by default, because you are choosing each row yourself, but passing `--min-age` there enforces it too. ## When something is skipped [#when-something-is-skipped] | Reason | Meaning | | --- | --- | | `recently-active` | something inside changed within `--min-age` | | `changed-since-scan` | it changed after the scan (or after the plan was written) | | `protected` | nested `.git`, a `*-keypair.json`, or git-tracked files | | `no-longer-matches` | no rule claims it any more (renamed, replaced, or its proof file is gone) | | `outside-roots` | it resolves outside the folders you scanned (a symlink was involved) | | `missing` | it was already gone | | `unverifiable` | something couldn't be read, so it wasn't safe to proceed | Details and the full list of checks: [Safety model](/docs/concepts/safety-model). ## Audit trail [#audit-trail] Every deletion and failure is appended to a history file. `purgeit history` shows it, newest first. Dry runs write nothing. # Custom rules (/docs/guides/custom-rules) Rules are **data**, not code: a config can always be validated, printed with [`purgeit rules`](/docs/reference/cli#rules), and shared. Put them in `purgeit.config.ts` (or `.json`, `.mjs`, …, or the `purgeit` key of `package.json`). purgeit uses the **nearest config, searching from the current directory upward**, then a user-level `config.*` in `~/.config/purgeit/`; the nearest one wins outright. `purgeit init` writes a starter. See the full [configuration reference](/docs/reference/configuration). ```ts title="purgeit.config.ts" import { defineConfig } from 'purgeit'; export default defineConfig({ /* … */ }); ``` ## Recipes [#recipes] ### A cache that is always safe to delete [#a-cache-that-is-always-safe-to-delete] ```ts safe: ['.my-tool-cache'], ``` ### A generic name, but only next to proof [#a-generic-name-but-only-next-to-proof] Use a *gated* rule when the name alone is too generic. `out` is only generated output when a `project.toml` sits beside it: ```ts gated: [{ name: 'out', when: { file: 'project.toml' } }], ``` `when` accepts one condition or a list of which any one suffices: ```ts { file: 'package.json' } // a sibling file { glob: '*.csproj' } // a sibling matching a glob { grep: { file: 'Makefile', pattern: '^build:' } } // a sibling whose contents match { inside: 'pyvenv.cfg' } // a file inside the directory itself ``` `inside` is how a bare name like `venv` is proved: the built-in rule only matches a `venv` that contains a `pyvenv.cfg`. ### Any directory carrying a tag file [#any-directory-carrying-a-tag-file] ```ts markers: [{ name: 'MYTOOL.TAG', file: '.mytool-cache', signature: 'mytool-cache-v1' }], ``` ### Keep things out [#keep-things-out] ```ts ignore: ['vault', 'secrets'], // never entered, anywhere exclude: ['legacy/**'], // skipped, relative to each scanned root ``` ### Switch off a built-in rule [#switch-off-a-built-in-rule] ```ts disable: ['coverage'], // unknown names are an error, so typos are caught ``` ### Named groups for `--only` [#named-groups-for---only] ```ts groups: { web: ['node_modules', '.next', 'dist'] }, // purgeit clean --only web ``` ### Defaults for flags [#defaults-for-flags] ```ts minAge: '14d', minSize: '50MB', depth: 6, dormantAfter: '14d', // when a project counts as dormant (default 30d) ``` Flags always override config. ## JSON config with editor completion [#json-config-with-editor-completion] ```json { "$schema": "./node_modules/purgeit/schema.json", "safe": [".my-tool-cache"] } ``` ## Things worth knowing [#things-worth-knowing] - A rule with the same name as a built-in **replaces** it. - A name can't be both `safe` and `gated` in one config — that is rejected. - Version-control directories are never entered, whatever the config says. - Matching a name is never enough on its own: [protection checks](/docs/concepts/safety-model) still apply to every match. # Getting started (/docs/guides/getting-started) purgeit runs on macOS, Linux and Windows. Via npm it needs **Node.js 22 or newer**; the [standalone binaries](https://github.com/nandan-varma/purgeit/releases) need nothing. Releases are published to npm with [signed provenance](https://docs.npmjs.com/generating-provenance-statements), so you can verify what you run with `npm audit signatures`. ### Run it [#run-it] No install needed: `npx purgeit ~/dev` `bunx purgeit ~/dev` `pnpm dlx purgeit ~/dev` `npm install -g purgeit`, then `purgeit ~/dev` No Node needed: download `purgeit-` for macOS, Linux or Windows from [GitHub Releases](https://github.com/nandan-varma/purgeit/releases) (each release lists `SHA256SUMS`), make it executable, and run it. With no directory it scans the current one. Add `--discover` to also scan the places this machine keeps projects (`~/dev`, `~/Projects`, `~/Code`, AI agent worktrees, and any home folder that holds projects). ### Look around [#look-around] The [interactive UI](/docs/guides/interactive-ui) fills in as artifacts are measured. Press `space` on what you want gone, `enter` to review, `y` to delete. ### Or stay in the shell [#or-stay-in-the-shell] List without changing anything, then clean with a preview first: $ purgeit scan ~/dev --min-size 100MB $ purgeit clean ~/dev --min-size 100MB --dry-run # runs every check, deletes nothing $ purgeit clean ~/dev --min-size 100MB # asks first ## What you are looking at [#what-you-are-looking-at] `purgeit` lists **projects**, not individual folders: $ purgeit scan ~/dev PROJECT SIZE ITEMS ACTIVE ECOSYSTEMS old-api 1.3 GB 2 4mo JS/TS mail 6.9 GB 1 5m Rust pushstack (+1 worktree) 2 GB 5 2m JS/TS 8 artifacts · 10.2 GB reclaimable — scanned 1 root in 2.1s 1.3 GB of that is in 1 dormant project — `purgeit clean --stale` targets exactly those. | Column | Meaning | | --- | --- | | **SIZE** | Disk space deleting would free | | **ITEMS** | Artifacts in the project (`node_modules`, `target`, `.next`, …) | | **ACTIVE** | When the project was last worked on — from git's log; *dormant* after 30 days | | **ECOSYSTEMS** | Which tools' output it holds | Use `--by artifact` for one line per folder, and `purgeit explain ` to see exactly why a folder was matched or skipped. The biggest safe win is output from projects you haven't touched in months. `purgeit clean --stale` targets exactly those, and in the UI `R` selects them. `clean` leaves anything modified in the last **7 days** alone, never deletes without confirmation (or `--yes`), and refuses anything it cannot verify. See [Clean safely](/docs/guides/clean-safely) and the [safety model](/docs/concepts/safety-model). ## Make it yours [#make-it-yours] ```bash purgeit init # a starter purgeit.config.ts source <(purgeit completion zsh) # shell completions (bash, zsh, fish) ``` ## Next steps [#next-steps] # Interactive UI (/docs/guides/interactive-ui) `purgeit [dirs…]` opens a full-screen UI in an interactive terminal. It uses the terminal's alternate screen, so your scrollback is untouched when you leave. Rows appear as they are measured, and the header shows progress and running totals. ## Projects first [#projects-first] A project is the unit you think in, so that is what you see: **one row per project**, with every artifact (`node_modules`, `.next`, `target`, …) folded inside it. purgeit ~/dev scanned in 2.1s 14.8 GB reclaimable in 8 projects · 3.1 GB dormant (3) · 2 selected (3.1 GB) projects · sort: dormant first · +62 small artifacts hidden (34 MB) — m to show PROJECT SIZE ITEMS ACTIVE ECOSYSTEMS ▸ [x] › mocha 1.8 GB 3 5mo JS/TS · Apple [x] › old-api 1.3 GB 2 4mo JS/TS [ ] › mail 6.9 GB 1 5m Rust [~] ⌄ pushstack +1 worktree 2 GB 5 2m JS/TS [x] node_modules 948 MB 22h [ ] .next 412 MB 2m - **One project, however many checkouts.** A project is the nearest git repository (a monorepo is one project), or a manifest folder outside git. Git **worktrees fold into the repository they were created from** (`+1 worktree`), so agent and experiment worktrees stop multiplying the list. - **Dormant first.** *ACTIVE* is when the project was last worked on — from git's own log, so a rebuild or `git status` doesn't count — and anything untouched for 30 days is *dormant*. Dormant projects sort to the top and are the real wins: a large `node_modules` in a project you abandoned months ago. - **Small things stay out of the way.** Artifacts under 10 MB are hidden, with a footer saying how many and how much. Press `m` to show them. - A single project directory is listed flat — there is nothing to group. ## Select quickly [#select-quickly] | Key | Does | | --- | --- | | `R` | select every artifact in **dormant** projects — the one-key cleanup | | `space` | select a row; on a project, all of its artifacts (`[~]` means partly selected) | | `a` · `n` · `i` | select all shown · none · invert | | `→` `l` / `←` `h` | expand / collapse a project (`←` on an artifact jumps to its project) | | `e` · `E` | expand all · collapse all | ## Everything else [#everything-else] | Key | Action | | --- | --- | | `↑` `↓` / `k` `j` | move | | `PgUp` `PgDn` · `g` `G` | page · top · bottom | | `/` | filter by project, path or rule, live. `esc` clears | | `s` · `r` | cycle sort (dormant first, size, oldest, name) · reverse | | `v` | projects ⇄ flat artifact list | | `m` | show / hide small artifacts | | `?` | help | | `enter` | review the selection | | `y` | delete (in the review) | | `esc` | cancel the review | | `b` | back to the list after deleting | | `q` | quit | The two lines under the list explain the row under the cursor: for a project, when it was last worked on and how many artifacts it holds; for an artifact, which rule matched and what proved it, plus whether git ignores it (`git-ignored ✓`, or a warning when it doesn't), and a note when it sits in a cloud-synced folder. ## Deleting is two deliberate steps [#deleting-is-two-deliberate-steps] `enter` opens a review grouped **by project** with counts and sizes — not forty paths. It warns when a selected project was worked on in the last week, and when artifacts sit in Dropbox, iCloud or similar. Only `y` deletes. Each path is re-verified first; anything refused is listed afterwards with the reason, and what was deleted is recorded in [`purgeit history`](/docs/reference/cli#history). A protected artifact — one that contains its own `.git`, a deploy keypair, or git-tracked files — is shown with its reason but can never be selected, not even by `R` or `a`. The UI requires an interactive terminal. In scripts and pipes use [`scan` and `clean`](/docs/reference/cli) instead; running `purgeit` without a terminal exits with code `2` and says so. Set `dormantAfter` in your [config](/docs/reference/configuration), for example `dormantAfter: '14d'`. # purgeit documentation (/docs) purgeit scans your project folders for `node_modules`, `target`, `dist`, `Pods` and 60 more kinds of rebuildable output, shows you what each would free, and deletes only what you choose — after re-verifying every path at the moment of deletion. Install, scan, and reclaim your first gigabytes in a minute. Exactly what is checked before anything is deleted. Every command and option, generated from the CLI itself. A versioned guide, structured output and Markdown for every page. ## Find your way [#find-your-way] | I want to… | Go to | | --- | --- | | Try it right now | [Getting started](/docs/guides/getting-started) | | Browse and pick what to delete | [Interactive UI](/docs/guides/interactive-ui) | | Delete with a safety net | [Clean safely](/docs/guides/clean-safely) | | Run it on a schedule or in CI | [Automation](/docs/guides/automation) | | Teach it about my own build output | [Custom rules](/docs/guides/custom-rules) | | Parse its output in a script | [Output formats](/docs/reference/output-formats) | | Embed it in my own tool | [Library API](/docs/reference/library-api) | | Understand why a path was skipped | [Clean safely → skipped](/docs/guides/clean-safely#when-something-is-skipped) | Every page here is also available as Markdown: append `.md` to a URL, or send `Accept: text/markdown`. The whole site is at [`/llms-full.txt`](/llms-full.txt), and `purgeit skill` prints a guide versioned with your installed CLI. # CLI reference (/docs/reference/cli) purgeit [dirs…] browse and select in the interactive UI (default) purgeit scan [dirs…] list projects and artifacts, delete nothing purgeit clean [dirs…] delete artifacts purgeit explain why a directory is matched, skipped or protected purgeit rules list the rules in effect purgeit history show what has been deleted purgeit init write a starter config purgeit completion shell completions (bash, zsh, fish) purgeit skill print the guide for AI agents Flags beat the [config file](/docs/reference/configuration). Sizes use binary units (`1KB` = 1024 bytes); durations accept `ms`, `s`, `m`, `h`, `d`, `w`, `y` (and `0`). Output formats are described in [Output formats](/docs/reference/output-formats). ## browse [#browse] The default command: running `purgeit` with directories (or none) opens this. See the [interactive UI guide](/docs/guides/interactive-ui). ## scan [#scan] ## clean [#clean] `--min-age` defaults to `7d` for `clean` and doubles as a guard: anything with a change inside that window is skipped at deletion time, whatever the scan said. See [Clean safely](/docs/guides/clean-safely). ## explain [#explain] Runs the same checks `clean` runs against one directory and reports what it finds — the fastest way to understand a surprising result. ## rules [#rules] ## history [#history] ## init [#init] ## completion [#completion] ```bash source <(purgeit completion bash) # ~/.bashrc source <(purgeit completion zsh) # ~/.zshrc purgeit completion fish > ~/.config/fish/completions/purgeit.fish ``` ## skill [#skill] ## Exit codes [#exit-codes] | Code | Meaning | | --- | --- | | `0` | success | | `1` | some paths were skipped or failed, or you declined the confirmation | | `2` | bad arguments, config or plan | | `70` | internal error | | `130` | interrupted | ## Environment [#environment] purgeit honours `NO_COLOR`. History lives in `~/Library/Logs/purgeit/history.jsonl` on macOS, `$XDG_STATE_HOME/purgeit/` (default `~/.local/state/purgeit/`) on Linux and `%LOCALAPPDATA%\purgeit\Log\` on Windows. # Configuration reference (/docs/reference/configuration) purgeit uses **the nearest config, searching from the working directory upward**: the first of `purgeit.config.ts`, `.mts`, `.js`, `.mjs`, `.cjs`, `.json`, or the `purgeit` key of a `package.json`. If none is found it uses a user-level `config.*` in `~/.config/purgeit/` (the platform's config directory), then the defaults. The nearest config wins outright — configs are not merged. `--config ` names one explicitly, `--no-config` ignores all of them, and `purgeit init` writes a starter. TypeScript configs load directly. Unknown keys and bad values are rejected with the file and the problem named. For recipes see [Custom rules](/docs/guides/custom-rules). ## Rule shapes [#rule-shapes] ```ts gated: [{ name: 'out', when: { file: 'project.toml' }, description?: string }] markers: [{ name: 'MYTOOL.TAG', file: '.mytool-cache', signature: 'mytool-cache-v1' }] ``` `when` is one condition, or a list of which any one suffices: | Condition | Holds when… | | --- | --- | | `{ file: 'package.json' }` | that file sits beside the directory | | `{ glob: '*.xcodeproj' }` | any sibling matches | | `{ grep: { file, pattern } }` | that sibling's contents match the regex — only the first megabyte is read; unreadable ⇒ no proof | | `{ inside: 'pyvenv.cfg' }` | that file exists inside the directory itself | Names are plain file names, never paths. `file` and `glob` are answered from the directory listing the scanner already has, so they cost nothing. ## Schema [#schema] The JSON Schema ships with the package as `purgeit/schema.json` and is used for editor completion: ```json { "$schema": "https://purgeit.nandan.fyi/schema.json" } ``` The same file ships in the package as `purgeit/schema.json` (`./node_modules/purgeit/schema.json`) # Library API (/docs/reference/library-api) Everything the CLI does is a plain async-iterator API with no UI dependency. ESM only, Node 22+, fully typed. ```ts import { clean, createRuleSet, loadConfig, scan, scanAll } from 'purgeit'; const { config } = await loadConfig({ cwd: process.cwd() }); const rules = createRuleSet(config); const roots = ['/Users/me/dev']; // stream while the scan runs… for await (const event of scan(roots, { rules, minAge: 7 * 86_400_000 })) { if (event.type === 'entry') console.log(event.entry.rule.name, event.entry.bytes, event.entry.path); } // …or collect const { entries, summary } = await scanAll(roots, { rules }); // delete, re-verifying every path const targets = entries .filter((entry) => !entry.protection) .map((entry) => ({ path: entry.path, bytes: entry.bytes, unchangedSince: entry.lastActive })); for await (const event of clean(targets, { rules, roots, idleFor: 7 * 86_400_000 })) { if (event.type === 'refused') console.log('skipped', event.path, event.refusal.message); } ``` ## `scan(roots, options)` [#scanroots-options] An async generator of events: `found` (a rule claimed a path), then `entry` (measured) or `dropped` (`empty`, `too-small`, `too-recent`, `unreadable`), and finally `done` with a summary. Stopping the iteration, or aborting `signal`, stops the work. | Option | Meaning | | --- | --- | | `rules` | **required** — a `RuleSet` from `createRuleSet()` | | `signal` | an `AbortSignal` | | `depth` | never descend deeper than this | | `exclude` | globs relative to each root | | `minBytes`, `minAge` | drop smaller / more recently active (ms) artifacts | | `includeEmpty` | keep artifacts with no files | | `home` | the home directory whose `Library`, `.Trash` and `Applications` are never entered | An `Entry` has `path`, `root`, `project`, `rule`, `evidence`, `bytes`, `files`, `lastActive` and `protection`. `scanAll` runs a scan to completion and sorts entries (deletable largest first, protected last). ## `clean(targets, options)` [#cleantargets-options] An async generator of `start`, `deleted`, `refused` (with a typed `Refusal`), `failed`, `warning` and `done`. A refusal is a decision, not an error; one refused or failed path never stops the rest. | Option | Meaning | | --- | --- | | `rules`, `roots` | **required** — every target must resolve strictly inside a root and still be claimed by a rule | | `idleFor` | refuse anything modified within this many ms (default off) | | `dryRun` | run every check, delete nothing | | `concurrency` | deletions in flight (default 4) | | `historyFile` | append outcomes here; nothing is written without it | | `signal` | stop starting new deletions | A `Target` is `{ path, bytes?, unchangedSince? }` — `unchangedSince` refuses the path if anything inside changed after that time. ## Rules and config [#rules-and-config] `RULE_CATALOG`, `createRuleSet(config)`, `restrictRuleSet`, `onlySafeRules`, `loadConfig`, `ConfigSchema`, `defineConfig`. Lower level: `measure`, `findProtection`, `discoverRoots`, `readHistory`, `appendHistory`, `defaultHistoryFile`. User-fixable failures throw `PurgeitError`. # Output formats (/docs/reference/output-formats) All paths are absolute. Sizes are bytes of allocated disk space. Timestamps are epoch milliseconds unless noted. ## `scan --format json` [#scan---format-json] One report. It doubles as a [plan](/docs/guides/clean-safely#3-review-then-apply-a-plan) for `clean --plan`. ```json { "version": 1, "roots": ["/Users/me/dev"], "entries": [ { "path": "/Users/me/dev/app/node_modules", "rule": "node_modules", "kind": "safe", "categories": ["javascript-typescript"], "evidence": null, "bytes": 979600000, "files": 41230, "lastActive": 1763500000000, "protection": null, "project": "app", "projectRoot": "/Users/me/dev/app", "projectKind": "repo", "projectGroup": "/Users/me/dev/app", "projectTouchedAt": 1760000000000, "gitIgnored": true, "synced": null } ], "projects": [ { "name": "app", "group": "/Users/me/dev/app", "artifacts": 3, "bytes": 1200000000, "protected": 0, "worktrees": 1, "ecosystems": ["javascript-typescript"], "touchedAt": 1760000000000, "lastActive": 1763500000000, "dormant": true } ], "summary": { "found": 12, "entries": 10, "protected": 1, "dropped": { "empty": 1, "too-small": 0, "too-recent": 0, "unreadable": 0 }, "unreadable": 0, "bytes": 13100000000, "durationMs": 2100 } } ``` | Field | Meaning | | --- | --- | | `kind` | `safe`, `gated` or `marker` | | `evidence` | what proved a gated or tagged rule (e.g. `package.json`), else `null` | | `lastActive` | newest modification time of anything inside | | `protection` | `null` when deletable, otherwise `nested-repository`, `deploy-keypair`, `tracked-files` or `unverified` | | `project`, `projectRoot`, `projectKind` | what it belongs to: a repository, a worktree (`projectGroup` is its main repository) or a manifest folder | | `projectTouchedAt` | newest git activity in the project (epoch ms), `null` when git doesn't know | | `gitIgnored` | `true` is evidence it is not authored content; `null` outside a repository | | `synced` | the cloud-sync provider whose folder it sits in, else `null` | | `projects[]` | the same entries rolled up per project, dormant and largest first; `dormant` means untouched for `dormantAfter` (30d) | | `summary.dropped` | entries hidden by filters, by reason (`empty`, `too-small`, `too-recent`, `active-project`, `unreadable`) | | `summary.unreadable` | directories that could not be listed | Entries are sorted largest first, protected last. ## `scan --format ndjson` [#scan---format-ndjson] One JSON object per line, streamed as results are measured: ```text {"type":"entry","entry":{ …same shape as above… }} {"type":"done","summary":{ …same shape as above… }} ``` ## `clean --format json` [#clean---format-json] Requires `--yes` or `--dry-run`. ```json { "dryRun": false, "deleted": [{ "path": "…", "bytes": 979600000 }], "refused": [{ "path": "…", "code": "recently-active", "message": "modified within the last 7 days" }], "failed": [{ "path": "…", "message": "EBUSY: resource busy or locked" }], "summary": { "deleted": 1, "refused": 1, "failed": 0, "bytes": 979600000, "dryRun": false }, "interrupted": false, "left": 0 } ``` `refused[].code` is one of `dangerous`, `missing`, `outside-roots`, `no-longer-matches`, `protected`, `recently-active`, `changed-since-scan`, `unverifiable`. When there is nothing to clean the output is `{"deleted":[],"refused":[],"failed":[]}`. `interrupted` is `true` (exit code 130) when a Ctrl+C stopped the run early; `left` counts the targets it never reached. ## `history --format json` [#history---format-json] An array, newest first: ```json [{ "time": "2026-11-19T06:20:11.000Z", "action": "deleted", "path": "…", "bytes": 979600000 }] ``` `action` is `deleted` or `failed` (`message` explains a failure). The file itself is JSON Lines; a line cut short by a crash is skipped when read. ## Errors [#errors] With `--format json` or `ndjson`, a failure is also reported as JSON on stdout (the human text still goes to stderr): ```json { "error": { "code": "error", "message": "No such directory: /nope" } } ``` `code` is `usage` for bad arguments and `error` for everything else; the exit code is `2`. ## `explain --format json` [#explain---format-json] ```json { "path": "/Users/me/dev/app/node_modules", "matched": true, "rule": "node_modules", "evidence": null, "project": { "name": "app", "root": "…", "kind": "repo", "group": "…", "touchedAt": 1760000000000 }, "bytes": 979600000, "files": 41230, "lastActive": 1763500000000, "protection": null, "gitIgnored": true, "synced": null, "wouldDelete": true, "refusal": null } ``` When `clean` would skip the path, `wouldDelete` is `false` and `refusal` is `{ code, message }` (the codes listed above). ## `rules --format json` [#rules---format-json] The rules in effect: `name`, `kind`, `categories`, `description`, and `when` (gated) or `file`/`signature` (tagged). # Built-in rules (/docs/reference/rules) Every rule below is generated from the catalog the scanner itself compiles, so this page cannot drift from what the CLI matches. Run `purgeit rules` to see the rules in effect for *your* config. ## Kinds of rule [#kinds-of-rule] - **safe** — deletable wherever the name appears. Once matched, the scanner never enters it. - **gated** — the name alone is too generic (`build`, `vendor`, `bin`), so it only counts when a manifest beside it proves it is generated output; for example `Pods/` next to a `Podfile`. - **tagged** — any directory, whatever its name, carrying a [`CACHEDIR.TAG`](https://bford.info/cachedir/) with the standard signature (written by Cargo, Go, Zig, ccache, pytest, …). - **pruned** — version-control metadata: never entered, never deleted. A matching name is not enough to delete: [protection checks](/docs/concepts/safety-model) still apply to every match. Missing an ecosystem? [Add a rule in your config](/docs/guides/custom-rules), or [contribute it to the catalog](/docs/community/contributing).