If you have been developing C, C++, or Objective-C projects on a Mac for a while, the words ccache clear cache have probably crossed your mind at some point. ccache is a compiler cache that dramatically speeds up rebuilds by storing object files from previous compilations, but left untended it can silently consume several gigabytes — or tens of gigabytes — of disk space over time. This guide explains exactly where ccache stores its data on macOS, how to measure what it is holding, and how to tune or purge it without disrupting your workflow.
What Is ccache and Where Does It Live on macOS?
ccache intercepts calls to compilers like clang, gcc, and g++. When you recompile a file whose source and flags have not changed, ccache serves the cached object file instead of invoking the compiler. The result is rebuilds that can be two to five times faster — at the cost of disk space.
On macOS, ccache follows the XDG Base Directory specification by default for versions 4.x and later. The cache lives at:
~/Library/Caches/ccache/— default cache directory on macOS (XDG fallback)~/.ccache/— legacy location used by ccache 3.x and older configurations
Some setups also respect the CCACHE_DIR environment variable, which overrides both of the above. Run ccache --show-config | grep cache_dir to see exactly which path is active on your machine.
How Much Space Is ccache Actually Using?
ccache tracks its own size internally, so the fastest way to check is:
ccache --show-stats
This prints cache hits, misses, and the total size in MB or GB. For a raw filesystem view, use:
du -sh ~/Library/Caches/ccache/
du -sh ~/.ccache/
The table below shows typical size ranges you might see depending on how long ccache has been running and what kinds of projects you build.
| Usage scenario | Typical cache size | Default max (if never tuned) |
|---|---|---|
| Single small C project, 6 months | 200 MB – 1 GB | 5 GB |
| Active iOS/macOS SDK development | 2 GB – 8 GB | 5 GB (ccache self-caps) |
| Chromium or LLVM checkout | 10 GB – 30 GB | 5 GB (often manually raised) |
| Multiple projects, years of history | 5 GB – 20 GB+ | 5 GB (excess pruned automatically) |
If you are hunting for other directories that quietly accumulate gigabytes, the guide what is taking up space on my Mac is a good companion read.
How to Clear the ccache on macOS (Step-by-Step)
Clearing ccache is safe: you lose the warm cache, so your next build will be slower than usual, but nothing will break. All source files remain untouched. Here is the full process:
- Verify the active cache directory. Run
ccache --show-config | grep cache_dirand note the path. - Check current size. Run
ccache --show-statsso you know the before-state. - Clear all cached objects. Run:
This deletes every cached result but preserves your configuration file (ccache --clear~/.config/ccache/ccache.confor~/.ccache/ccache.conf). - Confirm the purge. Run
ccache --show-statsagain — cache size should read 0 B. - Optional: also zero the statistics counters.
This resets hit/miss counts so you can measure cache effectiveness from a clean baseline.ccache --zero-stats
Deleting the Cache Directory Manually
If ccache is not installed but you still have leftover cache files from a previous toolchain, you can remove the directory directly:
rm -rf ~/Library/Caches/ccache/
rm -rf ~/.ccache/
This is a blunt approach — it removes configuration files too — so prefer ccache --clear when the binary is available.
Resizing the ccache Limit
The default maximum size is 5 GB. On a large project that limit may be hit quickly, causing ccache to evict recently compiled objects and reducing the hit rate. On a laptop that is running short on SSD space you may want to shrink it. Adjust the cap with:
ccache --set-config=max_size=2G
Common size units are G (gigabytes), M (megabytes), and T (terabytes). The setting is written to your config file and takes effect immediately. ccache will prune old entries on the next compile run to bring the cache within the new limit.
Setting a Per-Project Cache
If you work on a large project that should have its own cache budget, point it at a separate directory by setting CCACHE_DIR in your build environment:
export CCACHE_DIR=~/Developer/my-big-project/.ccache
ccache --set-config=max_size=10G
Each directory maintains its own size limit and statistics independently.
Tuning ccache for Better Efficiency on Apple Silicon and Intel
A few configuration tweaks make a meaningful difference on modern Macs, both M-series and Intel:
- Enable compression. ccache 4.x compresses cached objects with Zstandard by default. If you are on an older version, enable it explicitly:
ccache --set-config=compression=true. Compression can cut cache size by 30–50% with negligible CPU overhead on Apple Silicon. - Use a fast hash. Set
ccache --set-config=hash_dir=falsewhen your build system uses absolute paths that change across machines — this avoids cache misses caused by path differences. - Check the compiler check setting. By default, ccache verifies the compiler binary with a hash. If you update Xcode command-line tools frequently, cached entries from the old compiler will be invalidated automatically, which is the correct behavior.
- Keep sloppiness under control. The
sloppinesssetting trades correctness for hit rate. Unless you understand the trade-offs deeply, leave it at the default; incorrect sloppiness settings can serve stale object files.
ccache vs. Other Caches That Grow on macOS
ccache is one of several build-tool caches that developers accumulate. It helps to understand what each one holds before deciding what to prune:
~/Library/Developer/Xcode/DerivedData/— Xcode's own build artifacts, often 10–40 GB on active projects (see the dedicated guide on why Xcode takes up so much space)~/.m2/repository/— Maven local repository for Java/Kotlin projects~/.gradle/caches/— Gradle build cache~/.cargo/registry/and~/.cargo/git/— Rust crate sources and compiled artifacts~/Library/Caches/ccache/or~/.ccache/— the subject of this article
A tool like Crumb can audit all of these locations at once and show what is safe to delete before anything is removed, which is helpful when you are not sure which cache is responsible for a sudden drop in free space.
How Often Should You Clear or Resize ccache?
There is no universal answer, but a few practical guidelines apply:
- Do not clear it on a schedule. ccache is most valuable when it is warm. Clearing it unnecessarily means slower builds for nothing.
- Resize rather than clear. If disk space is the concern, lowering
max_sizelets ccache self-prune to the new limit. Your most recently compiled objects are retained. - Clear when you suspect corruption or stale entries. If you see unexpected build failures after a compiler update or SDK upgrade, a
ccache --clearis a quick diagnostic step. - Clear before archiving a project. If a project is going into long-term storage, clearing its cache before you zip or back up the directory keeps the archive lean.
Checking Your Configuration File
All persistent ccache settings are stored in a plain-text config file. On ccache 4.x with the default macOS layout the file is at:
~/.config/ccache/ccache.conf
On older installations or when CCACHE_DIR is set, look inside that directory for ccache.conf. The file uses a simple key = value format and can be edited by hand or via ccache --set-config. Running ccache --show-config always prints the fully resolved configuration, including values inherited from environment variables, so it is the authoritative source of truth for what ccache will actually do on the next build.