LLM "Light Thinking" in Practice: Building a Disk Cleanup Tool

    This article walks through building a disk analysis and cleanup tool with LLM-generated code, focusing on why models that produce concise, runnable output are well suited for scripting tasks. It breaks the requirements into four layers, provides a simplified Python skeleton, and explains the cost of excessive reasoning along with engineering safeguards such as retries, caching, and fallbacks.

    1. Background: When a Disk Alert Meets Code Generation

    On personal dev machines, test boxes, or small servers, disk space gradually filling up is a common failure. Failed log rotation, piled-up build caches, uncleared temporary files, and accidentally downloaded large files can all shrink available space quickly. Once the root partition is full, services may fail to write, databases may crash, and containers may refuse to start.

    The traditional approach is manual, layer-by-layer investigation: check overall usage first, then locate the culprit directory by directory, and finally delete files by hand. This process depends on experience and is prone to accidental deletion. A better approach is to turn the investigation into a repeatable tool: scan first, sort next, clean last, and keep a confirmation step.

    As LLM code generation has matured, the cost of building such tools has dropped significantly. But in practice, developers often hit a shared pain point: some models perform lengthy internal reasoning before generating code, producing large amounts of analysis unrelated to the task. This slows down responses and increases context consumption. So for scripting tasks, a model trait of “restrained thinking, direct runnable code” is especially friendly.

    2. Breaking Down the Requirements: What a Disk Analysis and Cleanup Tool Needs

    Before letting the model start, clarifying the requirements is key to a higher first-pass success rate. It helps to split the task into four layers:

    1. Information collection layer: Get overall disk usage and capacity per mount point.
    2. Scan and locate layer: Recursively tally directory usage and output the Top N largest directories and files.
    3. Cleanup execution layer: Support rule-based cleanup of caches, logs, and temporary files, plus empty-directory cleanup.
    4. Safety control layer: Scan only by default, require explicit confirmation to delete, and support exclusion lists and dry-run.

    When writing the requirement as a one-line prompt, include these constraints too, for example: “Write a cross-platform script that first prints disk usage, then lists the largest directories, requires a second confirmation before cleanup, and supports an exclusion list.” The more explicit the constraints, the less likely the model is to drift.

    3. Core Implementation Approach and Sample Code

    Below is a simplified implementation skeleton to illustrate the structure, not a complete production-ready project.

    1. import os
    2. import shutil
    3. from pathlib import Path
    4. def disk_usage(path="/"):
    5. total, used, free = shutil.disk_usage(path)
    6. return total, used, free
    7. def top_dirs(root, n=10):
    8. result = []
    9. for entry in os.scandir(root):
    10. if entry.is_dir(follow_symlinks=False):
    11. size = dir_size(entry.path)
    12. result.append((size, entry.path))
    13. return sorted(result, reverse=True)[:n]
    14. def dir_size(path):
    15. total = 0
    16. for dirpath, _, files in os.walk(path):
    17. for f in files:
    18. fp = os.path.join(dirpath, f)
    19. try:
    20. total += os.path.getsize(fp)
    21. except OSError:
    22. pass
    23. return total
    24. def safe_clean(targets, exclude=None, dry_run=True):
    25. exclude = exclude or []
    26. for t in targets:
    27. if any(e in t for e in exclude):
    28. continue
    29. if dry_run:
    30. print(f"[dry-run] would remove {t}")
    31. else:
    32. shutil.rmtree(t, ignore_errors=True)

    This code has three key design points: first, scanning and deletion are separated, read-only before write; second, dry-run is the default to avoid collateral damage; third, exceptions are swallowed without interrupting, so scanning can continue even with insufficient permissions. A real project should also add logging, concurrent scanning, symlink avoidance, and result persistence.

    4. The Cost of Redundant Reasoning and the Value of “Light Thinking”

    Lengthy reasoning is not entirely worthless, but in script-generation scenarios its marginal benefit is low. The costs, however, are clear: longer time to first token, higher context usage, and a greater chance of queuing and stream interruptions under rate limits. For developers, waiting ten minutes for code that could have been produced in thirty seconds is a negative experience.

    So choosing a model with “restrained thinking, direct code output” is essentially paying for iteration speed. Prompt engineering can help too: explicitly requiring “output only code and necessary notes,” “do not restate the requirements,” and “do not explain basic concepts” often further compresses useless output.

    5. API Stability and Engineering Safeguards

    Even with a suitable model, external APIs can still suffer from reduced throughput or dropped connections. Engineering should add three layers of safeguards:

    • Retry and backoff: Use exponential backoff for timeouts and rate limits to avoid avalanche-style retries.
    • Local caching: Cache common prompts and generated results to reduce repeated calls.
    • Fallback plan: When the API is unavailable, fall back to templated scripts or a local rule engine.

    If data privacy and response latency requirements are high, it is worth evaluating the feasibility of deploying a small-parameter model locally, but hardware cost and quality loss must be weighed, and there is no one-size-fits-all answer.

    6. Summary

    A disk cleanup tool is a typical “small requirement, strong constraints, safety-critical” scenario, well suited to testing a model’s code generation quality. Developers should focus on three points: whether the requirement constraints are clearly written, whether the generated code is safe by default, and whether external dependencies have fallbacks. Get these three right, and you get stable, controllable, and maintainable output regardless of which AI coding tool you use.