Safe C: Drive Cleanup
Clean the Windows system disk (C:) safely: scan first (read-only), then move selected junk to the
Recycle Bin (recoverable) — never permanent delete. This skill is required because the agent's
sandbox blocks writes to protected Windows paths, and a specific command-form workaround is needed.
When to use
- User asks to clean / free space on C: ("清理C盘", "c盘清理", "腾空间").
- User wants to remove temp files, updater caches, old backups, Windows search index, etc.
Step 1 — Read-only scan (NEVER delete during scan)
Generate a markdown report of largest directories and files. Use a Python os.walk that:
- Buckets sizes by top-level and second-level folder.
- Collects individual files >= 100 MB (sorted desc, cap ~120).
- Skips junction/symlink targets: skip when os.path.realpath(dirpath) != dirpath.
- Sets a time cap (e.g. 600 s) to avoid runaway scans.
- Writes a report; prints nothing destructive.
The scan must be read-only. Do NOT delete or move anything in this step.
Step 2 — Confirm scope with the user (safety)
C:\ is a system No-Go Zone. Before any removal:
- Present the report and a safe-candidate list (Temp, updater caches, Windows.edb, old backups, logs).
- Flag what must NOT be touched: pagefile.sys (virtual memory), C:\Windows\WinSxS, System32,
and user data (WeChat files, WPS cloud, Documents).
- Require explicit user confirmation of which items to clean. Use AskUserQuestion (multiSelect).
Step 3 — THE SANDBOX WORKAROUND (critical)
The Bash tool sandboxes writes to protected paths. To actually move files:
- Call Bash with dangerouslyDisableSandbox: true.
- Path quoting is the trap: git-bash strips backslashes from double-quoted C:\Users\...,
and forward slashes /c/Users/... get mangled into c:\c\....
- ALWAYS wrap Windows paths in SINGLE quotes with literal backslashes, e.g.:
'C:\Users\Administrator\.workbuddy\binaries\python\versions\3.13.12\python.exe' 'C:\path\to\script.py'
- PowerShell Add-Type is blocked by policy — do NOT use PowerShell .NET for this. Use Python +
SHFileOperation instead.
Step 4 — Move to Recycle Bin (recoverable, never permanent)
Use scripts/recycle_paths.py which calls SHFileOperationW with FOF_ALLOWUNDO
(sends to Recycle Bin). Run it via the Step 3 command form, passing target paths as args.
- Moving to Recycle Bin keeps the file on disk (in C:\$Recycle.Bin) — recoverable.
- After moving, verify with os.path.exists(path); it should return False.
- Process in small batches; if a path fails (locked file), skip and report — do NOT force.
Step 5 — Special cases
Windows.edb(search index, ~hundreds of MB): locked by the Windows Search service.
Stop it first (net stop WSearch), recycle the file, thennet start WSearchto rebuild.
Check status withsc query WSearch(STATE 4 = RUNNING). The service recreates a fresh
(small) index after restart.Templocked items: enumerate children and recycle each individually; skip any that
fail (code 32 = in use by a running process). These clear on reboot / when the app closes.pagefile.sys: never touch. To shrink, use System > Advanced > Performance > Virtual Memory.
Step 6 — Verify & report
- Re-check each target with
os.path.exists(expect False). - Confirm
WSearchis RUNNING after touchingWindows.edb. - Tell the user: space is only truly reclaimed after they EMPTY the Recycle Bin. Offer to empty
it only with a second explicit confirmation (emptying is permanent).
Safety rules (non-negotiable)
- Read-only scan first; explicit per-item confirmation before removal.
- Recycle Bin only — never
rm/ permanent delete on personal/system paths. - Never touch
pagefile.sys,WinSxS,System32, or user data without explicit instruction.