Managing Local Disk Bloat from AI Coding Tools: A Practical Guide

    AI coding tools can quietly fill up your system drive with model caches, plugin directories, and inference logs. This article explains the three main sources of disk consumption, how to measure them with read-only commands, and how to clean up safely based on whether data can be rebuilt. It also covers moving large cache directories to another drive with symbolic links and setting up periodic disk usage checks.

    1. Why AI Coding Tools Consume So Much Local Disk

    When AI coding tools run locally, they often maintain several kinds of state at the same time: local caches for models and indexes, extension and plugin directories, and inference and context records generated around each conversation. These files share a common pattern: each one is small, there are a huge number of them, and they are written to very frequently. During everyday development, conversation turns, code index rebuilds, and dependency resolution keep triggering writes, so the free space on the system drive drops without you noticing.

    The problem is harder to detect because this kind of growth usually produces no obvious alert. By the time developers notice, they often can no longer create a new session, index building fails, or the system warns that space is running low. At that point, deleting directories blindly can easily break the tool’s runtime state, forcing a re-download or index rebuild and costing even more time.

    So the right approach is not to look for a one-click cleanup script. Instead, first build an understanding of how local data is distributed, then handle it in tiers based on whether it can be rebuilt.

    2. The Three Main Sources of Space Usage and How to Identify Them

    1. Local Model and Index Caches

    This data speeds up responses and code understanding, and it is usually the largest. Its defining trait is that it can be rebuilt, but rebuilding is expensive. Once deleted, it is generally downloaded or recomputed the next time it is used.

    2. Extension and Plugin Directories

    Plugins and their dependencies take up a considerable amount of space, and old version files are often left behind after version updates. This data is partially cleanable: you need to distinguish currently enabled items from historical leftovers.

    3. Inference and Log Data

    This includes session records, intermediate inference data, runtime logs, and crash dumps. Individual files are small but the total volume is large, and they often contain sensitive information such as local paths, so they are not suitable for direct external sharing or long-term accumulation.

    4. Run a Read-Only Checkup First

    Do not delete based on intuition. Quantify first. The following commands only collect read-only statistics and do not modify any files:

    1. # Show the size of each first-level subdirectory under the home directory (sorted by size)
    2. du -sh "$HOME"/.[!.]* 2>/dev/null | sort -h | tail -n 20
    3. # Find large files not accessed in 30 days to locate "zombie data"
    4. find "$HOME" -type f -size +200M -atime +30 2>/dev/null | head -n 50
    5. # Check free space and inode usage on the system drive
    6. df -h
    7. df -i

    A special reminder: any “one-click cleanup script” from the internet may contain rules with an overly broad deletion scope. Do not run it before the data structure is confirmed. Review the script itself before running it.

    3. Tiered Cleanup Strategy: Let Rebuildability Decide the Action

    Tier 1: Safe to Delete (Logs, Dumps, Temporary Files)

    Clean up logs and temporary artifacts first. The payoff is stable and the risk is lowest. It is recommended to keep the most recent few days and archive or delete the rest.

    1. # Example: delete log files older than 14 days (replace with the target log directory and confirm the path first)
    2. find /path/to/logs -type f -name "*.log" -mtime +14 -print -delete

    Tier 2: Rebuildable but at a Cost (Model and Index Caches)

    Do not delete everything. Evict by “last used time” instead, and keep the indexes for projects currently in use to avoid a long rebuild the next time they are opened.

    Tier 3: Do Not Delete Freely (Configuration, Session History, Credentials)

    Configuration and credential directories must be excluded from any bulk operation. Cleanup scripts should use a whitelist mechanism and only process explicitly declared paths.

    1. # Whitelist-style cleanup skeleton: only process explicitly listed directories
    2. TARGETS=(
    3. "/path/to/cache/models"
    4. "/path/to/logs"
    5. )
    6. for d in "${TARGETS[@]}"; do
    7. [ -d "$d" ] && du -sh "$d"
    8. done

    4. Moving Large Directories Off the System Drive

    If space is still tight after cleanup, a more fundamental solution is to migrate rather than delete. Using a symbolic link to point a cache directory to a data drive can free up system drive space without breaking the path the tool expects.

    1. # 1. Stop the related tool to avoid writes during migration
    2. # 2. Move the directory to the data drive
    3. mv "$HOME/.cache/example" /data/cache/example
    4. # 3. Create a symbolic link so the original path still works
    5. ln -s /data/cache/example "$HOME/.cache/example"
    6. # 4. Verify
    7. ls -ld "$HOME/.cache/example" && du -sh /data/cache/example

    In enterprise environments, shareable build and dependency caches can also be placed in an internal artifact repository or object storage and distributed by the team, reducing repeated downloads on each machine. This kind of setup is usually operated together with container platforms and logging services, making it easier to monitor capacity trends centrally.

    5. Setting Up a Long-Term Inspection Routine

    A one-time cleanup cannot solve a recurring problem. It is recommended to set up periodic inspections and threshold-based alerts:

    1. # Check system drive usage daily and print a hint when it exceeds the threshold (example threshold: 85%)
    2. THRESHOLD=85
    3. USAGE=$(df --output=pcent / | tail -1 | tr -dc '0-9')
    4. if [ "$USAGE" -ge "$THRESHOLD" ]; then
    5. echo "System drive usage is ${USAGE}%. Consider cleaning caches and logs."
    6. fi

    Combined with monitoring and alerting, bringing disk usage and cache directory growth rate into your observability metrics lets you step in before the limit is reached, instead of waiting until sessions can no longer be created.

    6. Common Pitfalls and Notes

    • Do not delete a directory that is in use by a process. Exit the tool first.
    • Do not use cleanup scripts of unknown origin. The deletion scope must be auditable.
    • Logs may contain local paths and code snippets. Clean them up after troubleshooting to avoid leakage risk.
    • After migration, verify that the symbolic link is valid. Otherwise, the tool may recreate the directory on the system drive and consume space again.