Foundry's fork cache grows with every block you test against
Foundry caches RPC responses for fork tests in ~/.foundry and keeps every solc version it downloads. How to measure both on a Mac and clear them safely.
Fork tests are what grow Foundry's cache. Every chain and block number you fork from gets its own cached RPC responses under ~/.foundry/cache/rpc, and a test suite that pins many blocks keeps all of them. Compiler versions add more: each solc release is downloaded once and kept.
forge cache ls
du -sh ~/.foundry/cache ~/.foundry/bin 2>/dev/null
du -sh ~/.svm ~/Library/Application\ Support/svm 2>/dev/null # solc versionsClear it
forge cache clean # all chains
forge cache clean mainnet # one chain
# In a project, compiled output and the build cache
forge cleanCleaning the RPC cache only makes the next fork test slower, because it fetches state from your RPC provider again. That may count against a rate limit, so on a metered provider clean selectively. Old solc versions you no longer target can be deleted from the svm folder; Foundry downloads a version again if a project asks for it.
Hardhat projects
npx hardhat clean removes a project's artifacts and cache folders. In most Hardhat repositories the larger folder is node_modules: see node_modules is eating your disk. For the shared cache other tools use, see the hidden .cache folder.
Common questions
What does forge cache clean delete?
Foundry's cached RPC responses and block explorer data under ~/.foundry/cache. Your contracts, tests and project build output are not touched; forge clean handles the project's out and cache folders.
Where does Foundry keep solc compilers?
In the svm folder, ~/.svm on many setups and ~/Library/Application Support/svm on newer ones. Each version is a separate folder, and unused ones can be deleted.
Will clearing the Foundry cache break fork tests?
No. The next run fetches the state again from your RPC endpoint, so it is slower once and may use more of a metered provider's quota.