Managing AI Coding Tool Local Cache Growth: A Practical Guide

    AI coding tools can silently consume tens of gigabytes of system disk space within weeks of installation. This article explains why local cache growth outpaces intuition, how to quantify and locate the largest consumers across directory, file type, and time dimensions, and how to apply a four-layer governance model: migrating cache off the system disk, pruning rebuildable assets, tightening logging and diagnostics, and managing session and context retention. It also covers long-term prevention through scheduled pipelines, capacity thresholds, and environment isolation, along with common pitfalls and dry-run safety practices for any deletion script.

    1. Background: The Engineering Reality of a Silently Consumed System Disk

    Once AI coding tools become part of the daily development workflow, a frequent engineering problem is not model capability but local disk usage. A typical pattern: installation takes only a few hundred megabytes, but after several weeks of use, free space on the system disk drops from tens of gigabytes to single digits. Eventually, creating a new session fails with an out-of-space error, and no meaningful interaction is possible at that point.

    What makes this hard is that the growth is gradual and silent. Developers usually watch code repositories and dependency directories, while overlooking several categories of “hidden write sources”:

    • Local model and weight caches: to reduce time-to-first-token latency, tools store model files, tokenizers, and quantization artifacts locally.
    • Plugin and extension directories: runtime files and unpacked artifacts from language servers, indexers, and helper plugins.
    • Inference and context records: session history, code snippet snapshots, retrieval indexes, and intermediate reasoning traces.
    • Logs and diagnostic data: high-frequency rolling logs, crash dumps, and performance samples.
    • Index and cache databases: vector or inverted indexes built for semantic retrieval, growing non-linearly with repository size.

    It is worth stressing that most of these files “must exist” to preserve the experience, so deleting them outright is not an option. The governance goal is not zero usage, but tiering, rebuildability, and relocatability.

    2. Root Causes: Why Growth Far Exceeds Intuition

    2.1 Write Amplification and Multiple Copies

    A single conversation often triggers multiple rounds of retrieval and reranking, with intermediate artifacts written to disk in full. The same code context is repeatedly serialized across different sessions, creating multiple copies. Total write volume is therefore far larger than the size of the conversation text itself.

    2.2 Non-Linear Relationship Between Indexes and Repository Size

    The size of a semantic index typically grows with the number of files and the number of chunked passages, plus a constant multiplier from vector dimensions. The larger the repository and the longer its history, the more pronounced the index bloat.

    2.3 Default Log Level and Rotation Policy

    The default log level often includes debug information. Without a size cap and a rotation retention policy, a single log file can keep appending until it reaches gigabyte scale.

    2.4 Cache Directories Overlapping the System Disk

    Most tools place caches under the user home directory by default, and the home directory usually resides on the system disk. As a result, “cache growth” is directly equivalent to “less free space on the system disk,” with no isolation between the two.

    3. Identification and Localization: Quantify First, Then Act

    The first step in governance is obtaining a trustworthy quantitative view rather than deleting by feel. A three-way cross-analysis by directory, file type, and time is recommended.

    1. # 1) Locate the top-level subdirectories with the highest usage under the home directory (illustrative)
    2. du -h --max-depth=1 "$HOME" 2>/dev/null | sort -hr | head -n 20
    3. # 2) Find the 30 largest files and inspect the type distribution
    4. find "$HOME" -type f -size +200M 2>/dev/null -printf '%s\t%p\n' \
    5. | sort -nr | head -n 30
    6. # 3) Total up log file usage and find the oldest timestamp
    7. find "$HOME" -type f -name "*.log*" -printf '%s\t%TY-%Tm-%Td\t%p\n' 2>/dev/null \
    8. | awk '{s+=$1} END {printf "logs_total=%.2f GB\n", s/1024/1024/1024}'

    How to read the results:

    • If the largest usage is concentrated in “model/weights” directories, prioritize migration over deletion.
    • If it is concentrated in “index/cache databases,” prioritize rebuildable cleanup.
    • If it is concentrated in “logs,” prioritize rotation and lowering the log level.
    • If it is concentrated in “session/inference records,” prioritize a retention window policy.

    4. Governance Strategy: A Four-Layer Divide-and-Conquer Model

    4.1 Layer 1: Migration (Moving Growth Sources Off the System Disk)

    Pointing the cache root directory at a data disk via environment variables or configuration is the highest-value step. A general approach (illustrative; refer to the documentation of the tool in use for exact variable names):

    1. # Illustrative: migrate the user-level cache and temp directories to the data disk
    2. export XDG_CACHE_HOME=/data/cache
    3. export TMPDIR=/data/tmp
    4. mkdir -p "$XDG_CACHE_HOME" "$TMPDIR"

    After migration, verify that new sessions can be created normally, plugins load normally, and retrieval hit rate does not drop noticeably.

    4.2 Layer 2: Rebuildable Cleanup (Indexes and Temporary Artifacts)

    Indexes, temporary snapshots, and intermediate inference artifacts are “rebuildable assets”; deleting them costs a slower next interaction, not lost functionality. Cleanup with a dual constraint of “retention window plus total size cap” is recommended:

    1. import os, time
    2. from pathlib import Path
    3. def prune(root: Path, keep_days: int, max_gb: float):
    4. cutoff = time.time() - keep_days * 86400
    5. files = [(p.stat().st_mtime, p.stat().st_size, p)
    6. for p in root.rglob("*") if p.is_file()]
    7. # First delete files past the retention window by time
    8. for mtime, size, p in files:
    9. if mtime < cutoff:
    10. p.unlink(missing_ok=True)
    11. # Then enforce the total size cap, deleting oldest first
    12. files = [(p.stat().st_mtime, p.stat().st_size, p)
    13. for p in root.rglob("*") if p.is_file()]
    14. total = sum(s for _, s, _ in files) / 1024**3
    15. for mtime, size, p in sorted(files):
    16. if total <= max_gb:
    17. break
    18. p.unlink(missing_ok=True)
    19. total -= size / 1024**3
    20. prune(Path("/data/cache/index"), keep_days=14, max_gb=20)

    4.3 Layer 3: Taming Logs and Diagnostics

    • Lower the log level from debug to info or warning;
    • Set a per-file size cap and a number of retained files (rotation);
    • Disable non-essential performance sampling and crash dumps;
    • Archive periodically to object storage or a logging service, keeping only the most recent copy locally.

    4.4 Layer 4: Session and Context Governance

    The value of session records decays over time. A “hot-warm-cold” three-tier scheme is recommended: hot data keeps the most recent sessions; warm data is compressed and archived; cold data is moved to external storage. For key sessions that must be retained long term, export them as plain-text archives to avoid long-term dependence on proprietary binary formats.

    5. Long-Term Prevention: Turning Governance into a Pipeline

    One-off cleanup cannot prevent recurrence. Governance actions should be solidified into repeatable mechanisms:

    1. Scheduled jobs: daily incremental cleanup plus weekly deep maintenance, with total-size threshold alerts.
    2. Threshold monitoring: set capacity watermarks for cache directories (for example 70%/85%) with tiered alerts wired into monitoring and alerting capabilities.
    3. Environment isolation: use separate cache roots for different projects to avoid cross-contamination and single-point bloat.
    4. Rebuildable first: before any cleanup, confirm whether the directory is rebuildable; data that cannot be rebuilt must be backed up first.
    5. Capacity budget: write the “local cache limit” into team engineering standards so new members configure it at machine setup.
    1. # Illustrative: daily incremental cleanup plus watermark check (can be attached to a scheduler)
    2. 0 3 * * * /usr/local/bin/prune_cache >/var/log/prune_cache.log 2>&1

    6. Common Pitfalls and Risk Notes

    • Pitfall 1: deleting the entire user cache directory outright. The risk is that plugins and models must be re-downloaded, and index consistency may break. The correct approach is to handle subdirectories by category.
    • Pitfall 2: cleaning only logs while ignoring indexes. Indexes are often the largest consumer, so cleaning logs yields limited total reduction.
    • Pitfall 3: leaving the cache on the system disk and relying only on periodic cleanup. The recurrence cycle is short, which treats symptoms rather than the root cause; migration is the fundamental fix.
    • Pitfall 4: deleting session data without a backup. Sessions may contain troubleshooting conclusions not yet written elsewhere, so export before cleaning.
    • Risk note: any deletion script should first run in “dry-run” mode to output the list of files to be deleted, and only execute for real after confirmation.

    7. Extensions for Cloud Collaboration Scenarios

    When local storage no longer carries all cache responsibilities, cold and archival data can be pushed down to the cloud side: object storage for session archives and index snapshots, a logging service to consolidate diagnostic data, and a container platform to standardize cache directory conventions across the team’s development environments. Baidu AI Cloud offers corresponding capabilities in these general categories and can serve as the foundation for a unified team governance plan; refer to the official documentation for specific integration details. This article does not cover any proprietary interface specifics.

    8. Conclusion

    The local footprint problem of AI coding tools is essentially a hidden cost of performance optimization. The core logic of governance comes down to three sentences: quantify and locate first, then handle in layers, and finally prevent through pipelines. Separate rebuildable data from non-rebuildable data, migrate growth sources off the system disk, and turn cleanup into a scheduled pipeline. That keeps the system disk footprint stable within a predictable range while preserving the interaction experience.