Improving Coding Efficiency with LLMs: A Practical Guide to Disk Usage Cleanup
This article walks through a real-world scenario where a development machine runs out of disk space and shows how a code-generation model can quickly produce a reusable analysis and cleanup tool. It covers how to write precise prompts with explicit constraints, which risks to review in generated code (path safety, performance, error handling, and observability), how model reasoning behavior affects the coding experience, and the trade-offs between cloud inference and local deployment. A final checklist helps turn a one-off script into a reliable team utility.
1. Background: Emergency Response When the Disk Fills Up
A full disk on a development machine is a frequent and frustrating problem in day-to-day engineering. It is rarely caused by a single oversized file. More often, it is the combined result of accumulated logs, bloated cache directories, leftover build artifacts, container image layers, and temporary files that are never reclaimed. Tracing this layer by layer manually is slow, whereas a model with code generation capability can produce a reusable analysis tool in a very short time.
The core requirement of this practice can be summarized in one sentence: given a path, measure the space used by each subdirectory, sort the results, and perform cleanup only after explicit confirmation. The requirement looks simple, but making it genuinely usable requires several engineering details.
2. The Key to the Requirement: Writing Implicit Constraints into the Prompt
A one-sentence prompt works only when the requirement itself is well defined. It should cover at least the following:
- The target path and scan scope, including whether hidden directories are included;
- The output format: a terminal table, JSON, or an exportable report;
- Sorting rules and thresholds, for example showing only directories above a certain size;
- The boundaries of the cleanup action: deleting only caches and temporary files, or allowing user-specified pattern matching;
- Safety mechanisms, which must include a second confirmation and a dry-run mode.
An example prompt structure:
Implement a command-line tool that:1. Recursively measures the size of each first-level subdirectory under a given directory and prints the top N in descending order;2. Supports --dry-run, which only prints the paths that would be deleted and an estimate of the space to be freed;3. Requires interactive confirmation before deletion and supports excluding whitelisted directories;4. Skips and logs paths that cannot be accessed due to permissions, without interrupting the overall process;5. Also writes output to a local log file for later review.
Putting constraints up front significantly reduces rework and lowers the chance that generated code “looks runnable but is actually dangerous.”
3. What to Review in Generated Code
Model-generated implementations are usually well structured, but four categories of risk must be checked before use.
The first is path safety. The deletion logic must normalize paths and reject empty values, the root directory, abnormal wildcard expansion, and symlink escapes to avoid accidental deletion.
The second is concurrency and performance. Scanning large directories should support incremental statistics and progress feedback, so that long periods without output are not mistaken for a hang.
The third is permissions and exceptions. In production environments, some directories are commonly unreadable; the tool should record a failure list rather than crash entirely.
The fourth is observability. The tool should output a before-and-after comparison of space usage, forming a verifiable feedback loop.
A simplified safe-deletion check:
def is_safe_target(path: str, whitelist: list[str]) -> bool:real = os.path.realpath(path)if real in ("/", os.path.expanduser("~")):return Falsereturn not any(real.startswith(w) for w in whitelist)
4. Real-World Experience from Differences in Reasoning Behavior
Differences among models on coding tasks show up mainly in three areas: length of the reasoning chain, time to first token, and stability over long contexts. An overly long reasoning process increases waiting time and consumes more quota, while interrupted responses and declining throughput directly break the coding flow. When choosing a coding assistant, therefore, “effective output per unit of time” is a better measure than leaderboard scores alone. Focus on streaming output stability, context window utilization, and tool call success rate.
5. Trade-offs Between Cloud Calls and Local Deployment
The advantages of cloud inference are elasticity and no operations overhead, making it suitable for burst workloads. The drawbacks are network jitter, rate fluctuations, and concerns about data leaving the environment. Local deployment offers data control, stable latency, and offline operation, at the cost of hardware investment and the resource footprint of large models. A middle ground is layered usage: handle sensitive code and operations scripts locally, and delegate generic boilerplate code to cloud services. At the same time, use monitoring, alerting, and logging services to observe call failure rates and latency percentiles so problems do not accumulate.
If Baidu AI Cloud capabilities are used, a typical setup combines a container platform to host inference services, object storage to archive models and artifacts, and logging plus monitoring and alerting to build an observability loop. Refer to the official documentation for specific specifications and pricing.
6. Implementation Checklist
- First validate the scan results in dry-run mode to confirm they match expectations;
- Establish a whitelist to protect configuration directories and version control workspaces;
- Before adding cleanup to a scheduled task, run it manually for one cycle;
- Retain operation logs so space anomalies can be located quickly;
- For recurring issues, introduce log rotation and periodic reclamation of build artifacts to reduce emergency demand at the source.
Turning a one-off script into a standard team tool is the real long-term payoff of this kind of practice.
