Skip to content

Writing Cleanup Rules

fzihak edited this page Nov 27, 2026 · 1 revision

Writing cleanup rules

Every cleanup in Deep Cleanup comes from a rule: a small TOML file that says where an app keeps rebuildable data and how to remove it safely. You don't write any Rust and you don't touch the engine.

FreeMyDisk ships 122 rules. If an app you use leaves junk behind, a rule for it is about 20 lines and makes a great first pull request.

Where rules live

src-tauri/crates/freemydisk-core/rules/filesystem/windows/<category>/<app>.toml

Categories: ai, application, browser, container, development, system.

A complete example

[rule]
id = "windows_application_spotify_cache"      # unique: windows_<category>_<app>_<what>
name = "Spotify Media & Storage Cache"
category = "application"
risk = "safe"                                 # safe · low · moderate · medium
verified_rebuildable = true                   # the app recreates this data by itself
verified_at = "2026-08-15"                    # the date you checked it
author = "Your Name"
description = "Cached streamed audio chunks and offline artwork stored by Spotify"
platform = "windows"
locking_processes = ["spotify.exe"]           # skipped while these are running

[applicability]
conditions = [{ type = "path_exists", path = "${local_app_data}/Spotify/Data" }]

[targets]
paths = [{ path = "${local_app_data}/Spotify/Data/*", matcher = "glob" }]
# min_age_hours = 24                          # optional: keep recently changed files

[disposal]
default_action = "permanent"                  # "trash" for anything a user might miss
protect_subpaths = ["*/Users/*"]              # never touch these, even if matched

Field reference

[rule]

Field Required Description
id ✔ Unique ID in the form windows_<category>_<app>_<what>
name ✔ Name shown in the app
category ✔ One of the six categories above
risk ✔ safe, low, moderate or medium. See risk levels.
verified_rebuildable ✔ true only if the app recreates the data by itself
verified_at ✔ Date you verified the rule, YYYY-MM-DD
author ✔ Your name
description ✔ One sentence about what is removed
platform ✔ windows
locking_processes Executables that hold the files open. While one is running, the rule shows "In use by …" and is skipped.
default_selected true to include the rule in Smart Select. Default false.

[applicability]

conditions is a list. The rule only runs when every condition is true. The supported type is path_exists.

[targets]

Field Description
paths List of { path, matcher }. matcher is glob (default) or exact. Globs support * and **.
min_age_hours Only clean items not changed for this many hours. For a folder, its newest file counts.

[disposal]

Field Description
default_action trash (default) or permanent. With Always Route to Recycle Bin on, everything goes to the Recycle Bin anyway.
protect_subpaths Glob patterns that are never removed, even when a target matches them.

Path variables

Variable Expands to
${local_app_data} %LOCALAPPDATA%
${app_data} %APPDATA%
${program_data} %ProgramData%
${user_profile}, ${home} %USERPROFILE%
${temp} The user's temp folder
${win_dir} %SystemRoot%

Use / in paths. FreeMyDisk converts them to \ on Windows.

What makes a good rule

  • ✅ It targets data the app rebuilds by itself: caches, logs, temp files, crash dumps.
  • ✅ It is as narrow as possible: App/Cache/* rather than App/*.
  • ✅ It lists the app's processes in locking_processes.
  • ✅ It uses risk = "safe" only when removing the data has no visible effect except a slower first start.
  • ❌ It never targets documents, saves, settings, sessions, passwords or downloads.

Test your rule

Put the rule in an empty folder, then:

cargo run -p freemydisk-cli -- scan --rules-path .\my-rules
cargo run -p freemydisk-cli -- clean --dry-run --category application
cargo test -p freemydisk-core --test rules_test

rules_test checks that every built-in rule is valid.

Submit it

  1. Fork the repository and add your file under the right category.
  2. Commit with a sign-off: git commit -s -m "feat(rules): add Spotify cache".
  3. Open a pull request and say how you verified that the app rebuilds the data.

Not ready to write it yourself? Request a rule instead, or vote in Which app should be rule #123?.

The full contribution guide is in CONTRIBUTING.md.

Clone this wiki locally