AI Coding Tools Are Eating Your Disk: Root Cause Analysis and a Layered Cleanup Guide
AI coding assistants quietly consume tens of gigabytes in the user directory as their reasoning caches, local model files, vector indexes, and session histories accumulate. This article explains why disk space disappears, how to measure exactly which directory is growing using du and find, and how to reclaim capacity with a three-tier strategy: clean up low-value runtime artifacts, manage rebuildable indexes by last-access time, and migrate large static files to a separate data disk. It also covers configuration changes that reduce disk writes, a lightweight threshold check for capacity alerts, and cloud-based patterns for teams that want centralized governance.
Why AI Coding Tools Keep Consuming System Disk Space
As coding assistants built around code generation and conversational interaction become part of everyday development workflows, more and more developers run into the same pattern: new sessions grow noticeably slower, the system disk is not deliberately filled by anything, and yet one day the OS reports insufficient free space. Tracing it back usually reveals that a hidden directory has quietly accumulated tens of gigabytes of data.
This kind of data shares a few traits: it is generated automatically by the tool, lands in the user home directory by default, grows linearly with usage, and is rarely cleaned up proactively.
To understand how the space gets eaten, start by recognizing that these files are not garbage. They are intermediate artifacts that the coding capabilities depend on. Their composition can be broken down along four dimensions.
Reasoning and Context Caches
On every interaction, a coding tool must assemble a context from the project structure, dependency declarations, the snippets of currently open files, and code retrieved by search. To avoid re-indexing and re-encoding the same content again and again, the tool typically persists those results as an on-disk cache. The larger the project and the more repositories you switch between, the faster the number of cache entries grows.
Local Models and Vector Indexes
Some implementations keep lightweight model weights, tokenizer files, or similarity indexes locally to power completion, reranking, and code snippet retrieval. These files are large and almost never change, which makes them a “write once, stay resident” category. Take a vector index as an example: indexing a mid-sized codebase commonly produces index files in the hundreds of megabytes. Switching branches frequently invalidates old indexes, but the stale copies are not reclaimed right away.
Sessions and Conversation History
Conversation records are usually appended one entry at a time, either as plain text or in a lightweight structured format. They are not just text: they also carry file snapshots, diffs, tool call arguments, and tool call results. The characteristic here is that each entry is small but the accumulated total is enormous, and the data has almost no reuse value over time.
Logs and Crash Diagnostics
For observability, the tool keeps writing debug logs, performance metrics, and exception stack traces. The default log rotation policy is usually bounded by “number of files” rather than “total bytes.” As a result, when individual log entries balloon because of attached context, the total size far exceeds expectations.
Layered together, these four sources form a continuously rising curve. That also explains why the disk emergency tends to show up after prolonged use rather than right after installation.
How to Locate What Is Actually Using the Space
The first step is not deletion. It is accurate mapping. Run the checks below in order to narrow the scope down to specific directories.
Start with the overall distribution by measuring top-level directory sizes, and confirm whether the abnormal growth is concentrated in the user directory rather than the system directories:
du -h --max-depth=1 ~ 2>/dev/null | sort -rh | head -20
Then drill down into the likely hidden cache locations under the user directory, level by level:
du -sh ~/.cache/* 2>/dev/null | sort -rh | head -20du -sh ~/.<your_tool_dir>/* 2>/dev/null | sort -rh | head -20
If you want to identify data that has not been touched for a long time by using modification time, add a time filter:
find ~/.cache -type f -mtime +30 -size +50M -printf '%s\t%p\n' | sort -rn | head
After mapping, you will usually end up with a clear inventory: which category of cache takes the most space, when it was last accessed, and which capabilities are affected if it is deleted. That inventory is the basis for every decision that follows.
A Layered Governance Strategy
Deleting an entire directory outright is the most common approach, and also the easiest way to create side effects. For example, dropping a project index forces every tool to rebuild it, which creates far greater disk and CPU pressure in the short term. A safer approach is to handle things in tiers.
Tier 1: prioritize runtime artifacts with no reuse value. Logs, crash reports, and old session records belong here. The cleanup order matters: first reduce future output through configuration, then delete the historical backlog:
# Delete log files older than 7 daysfind ~/.cache/logs -type f \( -name "*.log" -mtime +7 \) -delete
Tier 2: handle data that can be rebuilt but is expensive to rebuild, such as code indexes and retrieval caches. The key question is whether the data will still be used in the near future. For projects you have not opened in a long time, deleting the index has clear benefits. For your current main project, deletion means paying the rebuild cost immediately. A useful transitional approach is to mark the data as unused rather than deleting it right away:
# List index directories not accessed in the last 30 days; review before deletingfind ~/.cache/index -mindepth 1 -maxdepth 1 -type d -atime +30
Tier 3: handle data that is large and rarely updated, typically local models and static resource files. These are not good candidates for frequent deletion and are better addressed by moving storage rather than removing data.
Migrating the Storage Location: From Cleanup to Capacity Expansion
For data that must be kept, repeated cleanup only postpones the problem. The more fundamental fix is to change where the data lives, pointing large subdirectories under the user directory at a dedicated data disk. On Linux, symbolic links are the common approach: the setup is simple and transparent to the tool.
mkdir -p /data/tool-cachemv ~/.cache/tool-models /data/tool-cache/modelsln -s /data/tool-cache/models ~/.cache/tool-models
Three things need attention. First, verify that the tool reads correctly after the migration, since some implementations validate whether the path is real. Second, back up the metadata of the original directory so you can roll back. Third, if you use a containerized development environment, confirm that the mount point is also visible inside the container.
On Windows, directory junctions achieve the equivalent effect, or you can adjust the “new content save location” setting in the system preferences. macOS also supports symbolic links, but be aware of sandbox permission restrictions on some applications.
Configuration: Make the Tool Write Less to Disk
The final form of governance is prevention. Most tools expose several tunable parameters, and adjusting them in the right direction can significantly slow the growth rate. General-purpose measures include:
- Disable or downgrade telemetry and verbose logging, changing the log level from debug to errors only.
- Cap the total log size and the number of rotated files instead of relying solely on the default policy.
- Disable local model downloads and let completion and inference requests be handled by a remote service.
- Narrow the index scope, explicitly excluding build artifacts, dependency directories, and binary resources in the configuration.
An illustrative exclusion configuration looks like this:
{"index": {"exclude": ["**/node_modules","**/dist","**/build","**/.git","**/*.min.js","**/*.map"]},"logging": {"level": "error","maxTotalSizeMB": 500,"rotate": 3},"cache": {"modelDownload": false,"sessionRetentionDays": 14}}
Excluding dependency directories and build artifacts delivers the highest return of all. Such directories usually contain large numbers of third-party files and generated code that add no comprehension value yet take up the majority of the index space.
Observability: Set Up Capacity Alerts
Remediation after the fact costs far more than early detection. It is worth adding a lightweight routine check to the development machine that alerts when total cache size in the user directory or free space on the system disk crosses a threshold. It can be written as a scheduled task that performs a check before a session starts:
#!/usr/bin/env bashset -euo pipefailCACHE_DIR="${HOME}/.cache"THRESHOLD_BYTES=$((20 * 1024 * 1024 * 1024))usage=$(du -sb "${CACHE_DIR}" 2>/dev/null | awk '{print $1}')if (( usage > THRESHOLD_BYTES )); thenecho "Cache usage $(numfmt --to=iec "${usage}") exceeds the threshold. Consider running a cleanup."du -sh "${CACHE_DIR}"/* 2>/dev/null | sort -rh | head -10fi
At the team level, this check can also be wired into the CI pipeline so that machine health becomes part of build quality, preventing any single developer’s local environment from becoming a delivery bottleneck.
A General Practice Supplement on Baidu AI Cloud
If a team wants to move from “local accumulation” to “centralized governance,” it can follow the general cloud architecture pattern: migrate large artifacts that used to land on individual machines to centralized locations and let the platform manage their lifecycle uniformly. Concretely, static resources and model files are a good fit for object storage, where lifecycle rules can automatically archive or delete objects that have not been accessed for a long time. High-frequency call and operation records are better buffered through a message queue before landing in a logging service, so a single machine’s disk does not become the bottleneck. Service runtime state can be hosted by a container platform, combined with monitoring and alerting for continuous capacity observation.
The value of this division is a clear responsibility boundary: the personal development machine retains only the high-frequency working set, while cost and governance pressure shift to centralized storage that is more elastic and cheaper per unit. Baidu AI Cloud offers general implementations for each of these capabilities, and teams can choose the combination that fits their scale without changing their existing development workflow, gaining stable capacity guarantees.
Summary
The disk space problem with AI coding tools is fundamentally a mismatch between “local caching strategy” and “long-term usage habits,” not a defect in the tool itself. Effective governance takes three steps. First, map it: use directory size and access time to locate the real source of the problem. Second, tier it: treat “no reuse value,” “rebuildable,” and “static large files” differently. Finally, get ahead of it: use configuration tuning and capacity alerts to keep the problem under control before it occurs. Turning these three steps into a routine maintenance practice for the development machine lets you enjoy the efficiency gains of AI coding while avoiding the system disk as a hidden risk point that could interrupt your work at any moment.
