Agent Skill

安全清理C盘 (Safe C: Drive Cleanup)

This skill should be used when the user asks to clean, free up space, or remove junk from the C: drive / Windows system disk (e.g. "清理C盘", "c盘清理", "腾空间", "大幅度清理"). It provides a read-only disk scan workflow and a SAFE Recycle-Bin (recoverable) deletion method that works even when the agent sandbox blocks direct writes to C:\Users\AppData, C:\ProgramData, C:\Windows. Use it to scan for large files/dirs and to move junk to the Recycle Bin without permanent deletion.

IT 运维与安全·好运连连ᰔᩚ·来自 skill_hub·skillhub.cn ↗
skillhub install @user_c1ee5550/safe-c-drive-cleanup
1 Stars·6.2万 综合热度·3,151 字文档·源站更新 2026-11-22

README 文档

3,151 字

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/recyclepaths.py which calls SHFileOperationW with FOFALLOWUNDO (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, then net start WSearch to rebuild. Check status with sc query WSearch (STATE 4 = RUNNING). The service recreates a fresh (small) index after restart.

  • Temp locked 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 WSearch is RUNNING after touching Windows.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.

同分类其他技能

查看全部 ›