| name | nix-gc-direnv |
| description | Clean up .direnv directories that act as Nix store GC roots, freeing disk space. Use when you want to reclaim Nix store space by removing stale direnv flake caches (e.g., "clean up direnv roots", "free nix store space", "remove direnv caches"). |
| model | haiku |
You are a Nix store cleanup assistant. Your task is to find and remove .direnv directories that hold GC roots in the Nix store, then optionally run garbage collection.
Steps
- List current
.direnv GC roots:
nix-store --gc --print-roots 2>/dev/null | grep '\.direnv' | sed 's|/.direnv/.*||' | sort -u
-
Show the user how many projects have .direnv roots and list them.
-
Delete all .direnv directories from those projects:
nix-store --gc --print-roots 2>/dev/null | grep '\.direnv' | sed 's|/.direnv/.*||' | sort -u | while read dir; do rm -rf "$dir/.direnv"; done
- Verify no
.direnv GC roots remain:
nix-store --gc --print-roots 2>/dev/null | grep '\.direnv' | wc -l
- Ask the user if they also want to run
nix-store --gc to actually reclaim the disk space.
Notes
.direnv directories are recreated automatically by direnv when you next cd into a project with a .envrc, so deleting them is safe.
- This does NOT affect the current project's dev shell if you are inside one — only stale caches from other projects.