Building a Disk Space Cleanup Tool with LLMs: Practice and Lessons Learned
A practical guide to using large language models to generate a custom disk space analysis and cleanup tool, covering requirement breakdown, prompt design, code review checkpoints, inference efficiency considerations, and tips for turning one-off scripts into long-term engineering assets.
Starting from a Real Pain Point
Developers never seem to have enough disk space. Build caches, container images, VM disks, log files, node_modules, model weights—the list of space hogs keeps growing. One day you discover your 1TB drive is full. The usual approach is to search for scattered command-line tricks or look for an existing tool—but off-the-shelf tools tend to be rigid in functionality and rarely fit your specific needs.
This is where large language models offer a new path: describing your need in a single sentence and getting a customized analysis and cleanup program in return. This is not just an efficiency gain—it represents a shift in how everyday ops and maintenance tools get built.
Breaking Down the Requirements: What Should a Disk Analysis Tool Actually Do?
Before asking the model to write code, clarify your requirements—they directly determine prompt quality:
- Scanning capability: recursively traverse directories, measure the size of each subdirectory and file, and support sorting by size;
- Category detection: identify common “junk” categories—cache directories, temp files, logs, build artifacts, and duplicate large files;
- Risk assessment: distinguish between “safe to delete” and “handle with caution” files, avoiding accidental deletion of critical system paths;
- Interactive mode: analyze and display first, then delete only after user confirmation—never delete automatically;
- Extensibility: rules should be configurable so custom cleanup rules can be added later.
Prompt Design: Best Practices for One-Sentence Requests
A single-sentence prompt can work, but to get high-quality code, the prompt should be structured. A more robust template looks like this:
Please write a disk space analysis tool in Python:1. Recursively scan a given directory, output the size of each subdirectory in descending order;2. Identify common cleanable categories such as caches, logs, and temp files, and label them separately;3. Read-only mode is the default; deletion requires a second confirmation;4. Avoid traversing symlink loops; gracefully skip directories without permission;5. Output should be presented in table format.
Three key lessons:
- Constrain edge cases: symlink loops, permission-denied directories, and overly long paths are the most common crash points for this kind of tool. Writing them into the prompt upfront dramatically reduces rework;
- Make the safety policy explicit: explicitly requiring “read-only by default, confirmation before deletion” is far more reliable than patching it afterwards;
- Specify the output format: asking for tabular output and progress indicators upgrades a script from “usable” to “pleasant to use.”
A Sample Code Skeleton
The code the model generates typically includes a core structure like this (illustrative):
import osfrom pathlib import Pathdef scan_dir(root: Path, skip_symlinks=True):"""Recursively measure directory size, skipping symlinks to avoid loops"""total = 0for entry in os.scandir(root):try:if entry.is_symlink():continueif entry.is_dir(follow_symlinks=False):total += scan_dir(Path(entry.path))else:total += entry.stat().st_sizeexcept PermissionError:continue # gracefully skip directories without permissionreturn total
After generation, focus your review on three areas: whether permission error handling is complete, whether any paths are hardcoded, and whether the deletion logic truly includes a confirmation step. LLM-generated code is generally good, but safety-related logic must always be manually reviewed—that’s a non-negotiable principle.
Model Selection: The Hidden Costs of Reasoning Length and Throughput
Two often-overlooked experience factors matter in practice:
1. Chain-of-thought length. Some models produce very long internal reasoning before answering. For a moderately complex task like “write a disk cleanup script,” verbose thinking means waiting time multiplies. The ideal is adaptive reasoning depth: quick answers for simple tasks, deeper thinking only for complex ones.
2. API throughput. The same model can feel very different depending on how you access it. Developers often wire models into their workflow through command-line coding tools, where tokens generated per second directly shape the development pace—when output drops below a few dozen tokens per second, generating long code becomes painful. Connection stability matters too: an interrupted long session loses context.
This also explains why local deployment is attracting growing attention: open-source model weights paired with local inference frameworks avoid network flakiness and protect data privacy. Current mainstream open-source code models already achieve decent generation speeds on mid-to-large GPUs—more than enough for script-level development tasks like this.
Engineering Recommendations
If you want to turn such a “one-off script” into a long-term asset, consider:
- Externalize the rules: store cleanup rules in a YAML/JSON config so the code only handles execution;
- Add a dry-run mode: a
--dry-runflag that first prints the list of files to be deleted; - Keep an audit log: record the operation list for every cleanup to support later review;
- Schedule it: integrate with system cron jobs to run low-frequency automatic analysis and generate reports, with cleanup triggered manually.
Wrap-Up
LLMs have reduced the barrier to “writing a small tool to solve an immediate problem” to nearly zero. But using them well requires: structured prompts, manual safety review, attention to inference efficiency and throughput, and—when necessary—local deployment for full control of the stack. Tool development has evolved from “searching for snippets and stitching scripts together” to “one-sentence generation plus human oversight.” That is what AI-assisted programming truly changes about everyday operations work.
