Back to Terragrunt

Check what you are about to delete first

docs/src/data/faq/is-it-safe-to-delete-the-terragrunt-cache-directory.mdx

1.1.21.9 KB
Original Source

Yes. .terragrunt-cache is scratch space. Terragrunt downloads remote OpenTofu/Terraform configurations into it and runs commands there, and it recreates whatever it needs on the next run. Your state lives in your backend, not in the cache.

To clear every cache directory in a project:

bash
# Check what you are about to delete first
find . -type d -name ".terragrunt-cache"

find . -type d -name ".terragrunt-cache" -prune -exec rm -rf {} \;

On Windows, using PowerShell:

powershell
Get-ChildItem -Path . -Filter .terragrunt-cache -Recurse -Directory

Get-ChildItem -Path . -Filter .terragrunt-cache -Recurse -Directory | Remove-Item -Recurse -Force

Stopping it from growing in the first place

Deleting the directory reclaims the space, but it comes back on the next run. The size comes from every unit keeping its own copy of the same two things: the providers it downloads, and the repositories it clones for module sources. Share both and the directories stay small.

Share provider downloads. On OpenTofu 1.10 and later, Automatic Provider Cache Dir is on by default and points OpenTofu at one shared cache directory, so providers are downloaded once rather than once per unit.

If you use Terraform, an older OpenTofu, an NFS-mounted cache, or you are at a scale where lock contention on that directory hurts, use the Provider Cache Server instead:

bash
terragrunt run --all --provider-cache -- plan

Deduplicate repository clones. The Content Addressable Store stores the content of a git clone once and reuses it across every unit that sources from the same repository, rather than cloning it again per unit. It is on by default as of 1.1; on earlier versions, enable it with --experiment cas.

See Performance for how these fit together.