Windows

Automate Disk Cleanup with cleanmgr /sageset and /sagerun (and Reuse It on Another PC)

Published June 10, 2026 · by The FixHub Team

Disk Cleanup has a hidden two-step mode that lets you choose what to clean once, then run it silently as often as you like — no dialog, no clicking. The two switches are easy to mix up by name (“sage set” vs “sage run”), so here’s exactly what each does.

  • cleanmgr /sageset:N — opens the Disk Cleanup Settings dialog and saves your ticked categories under the number N.
  • cleanmgr /sagerun:Nruns the cleanup using the categories you saved under that same N, with no prompts.

N can be any number from 0 to 65535 — it’s just a label so you can save more than one preset.

Step 1: Choose your options (/sageset)

Open an admin Command Prompt and run:

cleanmgr /sageset:1

The Disk Cleanup Settings window opens. Tick the categories (the “subsections”) you want cleaned every time — Temporary files, Recycle Bin, Windows Update Cleanup, Delivery Optimization Files, thumbnails, and so on — then click OK. Nothing is deleted yet; you’ve just saved the preset.

Behind the scenes, each ticked item writes a StateFlags0001 value into the registry under HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\VolumeCaches\. A checked box stores 2, an unchecked box stores 0. (The 0001 matches your :1.)

Step 2: Run it anytime (/sagerun)

cleanmgr /sagerun:1

This runs through every category you saved under preset 1, silently. Put this one line in a Task Scheduler task (run as Administrator, weekly) and the PC cleans itself up on schedule.

You can keep several presets — e.g. /sageset:1 for a light weekly clean and /sageset:2 for a heavy one — and call whichever you need.

Reuse the same selection on another machine

Because the choices live in the registry, you can export the preset and import it on other PCs so they all clean up identically:

On the configured PC (admin Command Prompt):

reg export "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\VolumeCaches" cleanup.reg

Copy cleanup.reg to the other machine, then (admin):

reg import cleanup.reg
cleanmgr /sagerun:1

The StateFlags0001 values carry your selections across. As long as both PCs run the same Windows version (so they have the same cleanup handlers), /sagerun:1 will now clean the same categories everywhere. Roll it out with Group Policy / a deployment tool and you’ve standardized cleanup across a fleet.

FAQ

/sagerun cleaned nothing. You either ran a different number than you set (the :N must match), or the preset was never saved — run /sageset:N first and tick at least one box. Also run from an admin prompt.

Where do the categories come from? From the cleanup handlers registered under VolumeCaches. If a PC is missing a handler the other one has (different Windows build/features), that category just won’t appear — the rest still apply.

Is /sagerun safe to schedule? Yes — it only removes the categories you chose (temp files, update leftovers, Recycle Bin if ticked). It doesn’t touch personal documents. To clear every user’s Recycle Bin in one move, see Empty the Recycle Bin for all users.

Sources: Microsoft Learn — Automating the Disk Cleanup tool (sageset / sagerun, StateFlags), Microsoft Learn — cleanmgr command