How to Use an LLM to Generate a Disk Cleanup Tool from a Single Prompt
A practical guide to generating a disk space analysis and cleanup utility with a large language model. It covers prompt design, analysis and cleanup architecture, safety controls, engineering practices, and how to turn a one-off script into a reusable team tool.
How to Use an LLM to Generate a Disk Cleanup Tool from a Single Prompt
1. A Common Pain Point: The Disk Is Full Again
Almost every engineer who uses a development machine for a long time has encountered the same situation: a build suddenly fails, a container image cannot be pulled, or logging stops unexpectedly. After investigation, the root cause is often simple—the disk has run out of space.
A disk advertised as 1 TB may appear more than sufficient, but build caches, dependency packages, virtual machine images, container layers, historical logs, and temporary files can consume storage surprisingly quickly. By the time an alert is triggered, normal development work may already be affected.
There are usually two traditional ways to deal with the problem. One is to run a series of commands manually, inspect directories step by step, and delete files individually. The other is to maintain a cleanup script written years ago, which may no longer match the current directory structure or toolchain. Both approaches are time-consuming.
This is exactly the type of task that is well suited to a large language model: a one-off, low-complexity task with a clearly defined operational context.
Developers have increasingly shared a similar approach: provide a code-generation model with a single natural-language prompt and ask it to produce a complete utility for disk space analysis and safe cleanup. In practice, the results can be surprisingly effective.
This article uses that scenario to explore how to write a useful prompt, what capabilities the script should include, how to make cleanup safer, and how to turn the “generate a tool from one prompt” workflow into a repeatable engineering practice.
2. Why a Single Prompt Works: The Sweet Spot for LLM-Assisted Programming
Not every programming task should be handed over entirely to an LLM. Architecture design, complex state machines, and systems that require strong consistency still need substantial engineering involvement.
Disk cleanup scripts, however, fit particularly well within the sweet spot of LLM-assisted development for three reasons.
First, the requirements are clearly bounded. The input is a file system, and the output is a storage report plus a set of cleanup actions. There is little ambiguous business logic, so the model is less likely to go off track.
Second, the required knowledge is highly standardized. Directory traversal, size calculation, file-type aggregation, and sorting by modification time are common programming patterns represented extensively in training data. Generated implementations are therefore often reasonably mature.
Third, verification is inexpensive. You can usually determine whether the script works by running it once. If a problem occurs, pasting the error back into the model often leads to a working fix after one or two iterations.
There is also an important difference in user experience between models. Some coding models produce a long reasoning process before presenting an answer. For a simple utility, excessive reasoning can increase response time and make the interaction feel unnecessarily slow.
For lightweight tool generation, a model that quickly provides runnable code may offer a better experience. This suggests a practical rule for selecting AI coding tools: match the model to the complexity of the task. Use a lightweight model for simple scripts, and reserve deeper reasoning modes for complex refactoring or system design.
3. Writing a Better Prompt
The results from “Write me a disk cleanup program” can be dramatically different from those produced by a structured requirements description. In practice, a prompt should cover at least the following areas:
- Runtime environment: operating system, interpreter version, and whether third-party dependencies are allowed;
- Analysis dimensions: storage usage by directory level, aggregation by file type, the largest N files, and long-unused files;
- Cleanup policy: only clean explicitly safe categories, such as temporary directories, package manager caches, and expired logs; default to reporting without deleting; require confirmation before removal;
- Interaction model: provide a color-coded command-line report and support options such as
--dry-runand--yes; - Robustness requirements: handle permission errors, symbolic links, and mount-point boundaries.
A sample prompt could look like this:
Write a disk space analysis and cleanup script in Python 3 using only the standard library. Requirements:1. Scan a specified directory, calculate usage by subdirectory, and display the top 20 directories by size;2. Aggregate file sizes by extension, identify files larger than 500 MB, and find files that have not been accessed for 180 days;3. Include a safe cleanup list covering temporary directories, package manager caches, and rotated logs older than 30 days;4. Run in dry-run mode by default and only delete files when --clean is provided; ask for confirmation before each deletion;5. Skip the real files targeted by symbolic links, and report permission errors while continuing the scan.
The more specific the requirements are, the more likely the generated code will be usable on the first attempt, reducing the amount of rework required.
4. Core Script Design: Inspect First, Clean Second
A reliable disk management script should separate analysis from cleanup.
Analysis
The analysis phase provides most of the value. The script should recursively scan the target directory and calculate the actual storage consumed by each subtree. It is important to consider disk block usage rather than only logical file size, because sparse files can otherwise produce misleading results.
A useful report should include three types of views:
- Top-N directory view: helps identify which directory trees consume the most space;
- File-extension aggregation: reveals cache and build artifacts that are concentrated in a small number of file types;
- Time-based view: identifies files that have not been accessed for a long time and may be candidates for cleanup.
Presenting this information as tables and text-based bar charts allows developers to understand where the storage has gone at a glance.
Cleanup
The cleanup phase should follow a strict allowlist-driven policy. The script should contain an explicit list of categories that may be cleaned, such as:
- Operating system temporary directories;
- Download caches used by common package managers;
- Rotated log files older than the configured retention period;
- Unreachable objects in version control systems.
Any path outside the allowlist should be reported but never modified.
Before deletion, the script should display the files to be removed and the total amount of space that can be recovered. It should then wait for human confirmation. An even safer approach is to move files into an isolation directory instead of deleting them immediately. After a defined grace period, the isolation directory can be emptied permanently, reducing the risk of accidental deletion.
Several engineering details also deserve attention:
- Do not cross mount points by default, preventing external storage or network drives from being included unintentionally;
- Record permission failures as warnings and continue instead of terminating the scan;
- Write all operations to a log file for later auditing;
- Avoid following symbolic links to their target files during traversal.
5. From a One-Off Script to a Team Asset
Once the script has been tested and stabilized through several iterations, it can be developed into a reusable engineering asset.
- Store it under version control: Place the script in the team’s tooling repository together with usage instructions and a configurable cleanup allowlist. This makes the policy reviewable and traceable.
- Schedule regular inspections: Run the script weekly in dry-run mode through the operating system’s scheduling mechanism. Reports can be sent to a team messaging system or email, turning disk management from emergency response into proactive warning.
- Connect it to monitoring and alerts: Configure disk-usage thresholds in the monitoring system and attach the latest analysis report when an alert is triggered. This shortens the path from notification to diagnosis.
- Reuse it in cloud environments: On cloud servers or container platforms, the script can be included as an operational utility in a base image. Combined with log archiving to object storage, this can reduce disk pressure at its source.
6. Taking the Model Service Experience Seriously
The model’s capabilities are important, but the stability and throughput of the API service also affect the development experience.
Developers sometimes report that a model responds very quickly during a free promotional period but becomes noticeably slower or experiences connection interruptions after moving to regular service, especially during periods of high concurrency. In interactive coding workflows, reduced generation speed can interrupt concentration and productivity.
Several practical measures can help:
- For latency-sensitive interactive development, prepare a backup model or a local lightweight model as a fallback;
- For team usage, pay attention to concurrency quotas and rate-limiting policies;
- When necessary, deploy an open-source model locally to gain more control over throughput and privacy;
- Standardize prompt templates and preserve generated scripts as maintained assets, reducing dependence on any single model request.
The last point is particularly important. Once the tool has been generated, reviewed, and tested, service fluctuations should not prevent the team from continuing to use it.
Conclusion
Asking an LLM to generate a disk cleanup tool from a single prompt may seem like a small productivity trick, but it reflects a broader and useful way of working.
Repetitive, low-complexity, highly context-specific development tasks can be delegated to a model, while engineers retain responsibility for expressing requirements, validating results, and turning prototypes into maintainable assets.
Structured prompts, an allowlist-based cleanup policy, a clear separation between analysis and deletion, and proper engineering practices are what transform the initial efficiency gain into a sustainable capability.
