Purge
Removes build and dependency folders from projects you have not touched lately: node_modules, target, .venv and the like. They are often the largest things in a code folder, and a tool can always make them again.
dkit purge --dry-run # see what could be removed under this folder; changes nothing
dkit purge # review, untick what should stay, confirm
dkit purge ~/code ~/work # look in other folders
dkit purge folders add ~/code ~/work # save them, so a bare `dkit purge` looks there
Purge looks under the folders you name. With none named it looks in your saved folders, or under the folder you are in when you have saved none. It only works inside your home folder.
Saved folders
Save the folders you keep projects in once, and dkit purge on its own looks in all of them, wherever you run it:
dkit purge folders # show the saved folders
dkit purge folders add ~/code ~/work # look in these from now on
dkit purge folders remove ~/work # stop looking in this one
dkit purge --dry-run # preview across the saved folders
You can give several paths at once, and paths relative to the folder you are in. This works like dkit keep: the same three forms, and a text file you can also edit by hand.
- Naming a folder still wins.
dkit purge ~/otherlooks only in~/other; the saved folders are used only when no folder is named. - Purge says when it used them. The preview and the result say
Looked in your saved folders:and the list, at the top. With--json,looked_inissaved,namedorhere, androotslists the folders. - A saved folder gives purge nothing extra. It is only a place to start looking. What may be taken is decided exactly as when you type the folder: the same limits, the same proof for every kind, and your keep list still wins.
- Only a folder purge could search can be saved: one that exists, inside your home folder, and not kept in sync by a cloud service. A path through a symbolic link is saved as the folder it leads to.
- A saved folder that has gone is skipped, not fatal. The others are still searched and the missing one is reported as
Not searched. If none of them can be searched, purge stops and says so; it does not fall back to the folder you happen to be in. - Changing the list needs no confirmation: it removes nothing.
The list is purge-folders.txt in Deskit’s data folder, one full path per line; lines starting with # are ignored. If a line is not a full path, dkit purge without a folder stops with an error that names the line. Naming a folder still works.
A folder that is really called folders has to be written ./folders, since dkit purge folders shows the list.
What it looks for
A folder name alone is never enough. Each kind also needs proof that a tool made the folder, either a file next to it or something inside it:
| Kind | Folder | Proof | Cost of removing |
|---|---|---|---|
node-modules |
node_modules |
next to package.json |
re-downloads when needed |
rust-target |
target |
next to Cargo.toml, containing CACHEDIR.TAG |
slow to rebuild |
python-venv |
.venv |
containing pyvenv.cfg |
re-downloads when needed |
composer-vendor |
vendor |
next to composer.json, containing autoload.php and composer |
re-downloads when needed |
next-build |
.next |
next to package.json |
slow to rebuild |
turbo-cache |
.turbo |
next to package.json |
slow to rebuild |
pytest-cache |
.pytest_cache |
containing CACHEDIR.TAG |
rebuilds itself |
ruff-cache |
.ruff_cache |
containing CACHEDIR.TAG |
rebuilds itself |
So a folder called target full of your own files is left alone, and so is a Go project’s vendor folder.
dkit purge --kinds prints this list.
Only projects you have left alone
By default a folder is only selected when its project has had no activity for 30 days. Activity means the newest of:
- the files and folders at the top of the project
- git’s own records of commits, checkouts and staging
- the last build or install, which is the newest file inside the build folder itself
Folders of projects that were active more recently are still listed, under “Active in the last 30 days”, but are not selected. In the review they start unticked and you can tick them.
dkit purge --dry-run --min-age 90 # only projects idle for 90 days or more
dkit purge --dry-run --min-age 0 # everything found, however recent
Editing a file deep inside a project does not always count: only the top of the project and git’s records are looked at, to keep the scan fast. If you work in a project without building, installing or using git, it can look idle. Check the preview.
Undo
Purged folders are moved aside, not deleted:
dkit undo # put back everything the last purge is holding
dkit history 20261128-153045 # every folder of one purge, and what became of it
dkit undo 20261128-153045 ~/code/shop # put back only that project's folders
dkit release # delete what is being held, freeing the space now
- Folders that have to be installed or built again are held for 7 days, so their space is not free until then, or until you release them.
- The two small caches that rebuild themselves are freed at once.
- To free everything immediately, press
fin the confirmation or pass--releasewith--yes. To hold everything, presshor pass--hold.
See Undo, history and release for the details.
A folder on another disk than your home folder cannot be moved aside yet. It is reported and left where it is.
Folders a cloud service keeps in sync
Purge leaves a synced folder alone, whatever is in it. Two things make such a folder different from the rest of your disk:
- Moving something out of it is copied to your other devices as a deletion. Holding the folder here for undo does nothing about the copy on your laptop.
- Files in it may be placeholders whose content is not on this disk. Even measuring them can make the service download them.
So a synced folder is not entered, not measured and nothing in it is taken. The preview lists it under “Synced folders, left alone” with the service’s name; with --json it is in skipped with a synced_by field. Naming one as the folder to look in, or saving it, is refused with a message saying why. There is no option to override this.
What counts as synced:
| Folder | Service | How it is recognised |
|---|---|---|
~/Library/Mobile Documents |
iCloud Drive | macOS keeps iCloud Drive there |
~/Desktop, ~/Documents |
iCloud Drive | only while “Desktop & Documents Folders” is on: iCloud Drive’s own folder then has an entry of that name |
~/Library/CloudStorage/<Service>-<account> |
the service named | macOS puts every sync client built on its File Provider system there |
~/Dropbox, ~/Dropbox (…) |
Dropbox | the client’s default folder name |
~/OneDrive, ~/OneDrive - … |
OneDrive | the client’s default folder name |
wherever OneDrive, OneDriveConsumer or OneDriveCommercial point |
OneDrive | variables OneDrive sets on Windows; a Desktop or Documents it backs up is inside one of these |
~/Google Drive, ~/iCloudDrive, ~/Nextcloud, ~/ownCloud |
the service named | the client’s default folder name |
Symbolic links are resolved first, so a link in your code folder that leads into a synced folder is judged by where it leads. A folder that merely has a similar name, such as ~/Dropbox-notes, is an ordinary folder.
If a sync client was told to keep its folder somewhere else, under another name, purge cannot tell. Add that folder to your keep list.
What purge never does
These limits are built into the program:
- Only inside your home folder, and never a folder directly in it: a build folder has to be inside a project folder.
- Never inside a folder a cloud service keeps in sync. See above. Checked again at the moment each folder is moved, so a preview made before syncing was switched on takes nothing from it.
- Never inside hidden folders (names starting with a dot),
Library,ApplicationsorAppData. Editors and apps keep their ownnode_modulesthere. - Never inside another build folder. Packages inside
node_moduleshavenode_modulesof their own; those are part of the outer folder. - Symbolic links are never followed or removed.
- Your keep list is respected.
dkit keep add ~/code/importantprotects every build folder in that project. - Everything is checked twice: when planning, and again at the moment each folder is moved. If the
package.jsonnext to anode_moduleshas gone in between, the folder stays.
Known limits
- Not every tool is covered yet. Notably missing:
__pycache__,distandbuildfolders (too often they hold things that cannot be made again), Gradle, CocoaPods, Flutter. - Only
.venvis recognised as a Python environment, not other names. - A folder checked into git is not detected as such. A
vendorfolder you commit on purpose looks the same as any other; untick it or add it to the keep list. - The search goes 8 folder levels deep.
- Synced folders are recognised by where they are. A sync client set up to use a folder of another name, in another place, is not recognised, and neither are pCloud, MEGA, Box on Windows or Syncthing folders. Only the macOS cases have been seen on a real machine, and of those the iCloud “Desktop & Documents” case only with the setting off.
- The interactive review does not list the synced folders that were left alone; the
--dry-runreport does. - An assistant using
dkit mcpcan read your saved folders to know where to look, but cannot change them.
From docs/commands/purge.md at v0.1.0-alpha.2.