The Problem with Manual Disk Cleanup
Windows 11 constantly accumulates temporary files. Windows Update caches, downloaded program files, error reports, and internet cache can easily consume tens of gigabytes of storage on your primary C: drive. While you can open the Storage Settings or the legacy Disk Cleanup graphical interface to clear these files, doing so requires multiple clicks and waiting for the system to calculate the space.
If you are a system administrator managing a fleet of computers, or if you simply want to write a batch script that automatically cleans your PC every Friday night without prompting you, you need a command-line solution.
The cleanmgr (Disk Space Cleanup Manager) command is the native Windows utility designed specifically for this task. By using specific flags, you can configure cleanmgr to run completely silently in the background, automatically deleting only the files you specify.
Step 1: Configuring a Cleanup Profile (sageset)
Before you can run a silent cleanup, you must first configure a “profile” telling Windows exactly which categories of temporary files it is allowed to delete. You do this using the /sageset flag.
- Press the Windows Key, type
cmd, right-click on Command Prompt, and select Run as administrator. - Type the following command and press Enter:
cleanmgr /sageset:1
The number 1 represents the ID of the profile you are creating. You can use any number from 1 to 65535.
Once you press Enter, a special version of the Disk Cleanup graphical interface will open. You will notice that it contains significantly more checkboxes than the standard version. Go through the list and check everything you want this automated profile to delete (e.g., Temporary Internet Files, Recycle Bin, Windows Update Cleanup).
When you are finished, click OK. Windows will save these specific checkbox selections to the registry under profile ID 1. No files are actually deleted during this step.
Step 2: Executing the Silent Cleanup (sagerun)
Now that your profile is saved, you can trigger the automated cleanup at any time using the /sagerun flag.
Open the Command Prompt or a batch script and run:
cleanmgr /sagerun:1
This command instructs Windows to read the registry settings for profile ID 1 and immediately execute the cleanup. The tool runs completely silently in the background. You will not see a progress bar, and it will not ask for any user confirmation before emptying the Recycle Bin or deleting the update caches.
Step 3: Creating Multiple Profiles
Because the sageset profiles are saved permanently, you can create multiple automated cleanup routines for different scenarios.
For example, you could configure /sageset:1 to only delete basic temporary internet files, allowing you to safely run cleanmgr /sagerun:1 every single night via the Windows Task Scheduler.
Then, you could configure a much more aggressive profile using /sageset:2 that includes emptying the Recycle Bin, deleting Windows Defender logs, and wiping the massive Windows Update cache. You could then run cleanmgr /sagerun:2 manually once a month to reclaim maximum storage space.
Alternative: The “Low Disk Space” Flag
If you don’t want to bother creating custom registry profiles, cleanmgr includes a built-in automated mode designed specifically for emergencies.
cleanmgr /lowdisk /c
When you run this command (specifying the C: drive), Windows will automatically check every single box in the cleanup list and begin deleting everything it legally can to free up space, without requiring a pre-configured sageset profile.