Free Disk Space from Flutter Projects on a Mac

Each Flutter project you build keeps its own build/ and .dart_tool/ folders, and every iOS build adds CocoaPods on top. All of it can be rebuilt, except the release files you have not uploaded yet.

Updated:

Where Flutter uses space

There are four places to look, three inside each project and one shared:

  • build/ in the project root: compiled output for every platform you built, including debug builds, intermediate files and release artifacts. This is usually the largest.
  • .dart_tool/ in the project root: the package configuration from flutter pub get plus build caches for the Dart tools.
  • ios/Pods/ (and macos/Pods/): the CocoaPods dependencies of your iOS and macOS plugins, installed by pod install.
  • ~/.pub-cache: the global cache of every Dart and Flutter package version you have ever downloaded, shared by all projects.

Measure before you clean

Check one project, then list the build/ folders of all Flutter projects under your code folder. The find filter skips hidden folders such as ios/.symlinks, where plugin sources are linked into the project.

cd ~/code/my_app
du -sh build .dart_tool ios/Pods 2>/dev/null

# build/ size of every Flutter project under ~/code
find ~/code -name pubspec.yaml -not -path '*/.*' -not -path '*/build/*' -exec dirname {} \; | while IFS= read -r d; do [ -d "$d/build" ] && du -sh "$d/build"; done | sort -h

# the shared pub cache
du -sh ~/.pub-cache

Keep release builds you have not uploaded

Before cleaning, look for release files inside build/. Cleaning removes them together with everything else, and an IPA, AAB or APK you have not uploaded yet can only be recreated by building again from the same code, which is not always possible once the code has moved on.

find ~/code -path '*/build/*' \( -name '*.ipa' -o -name '*.aab' -o -name '*.apk' \) 2>/dev/null

The usual locations are build/ios/ipa/, build/app/outputs/bundle/release/ and build/app/outputs/flutter-apk/. Move anything you still need out of the project, or upload it to App Store Connect or Google Play first.

flutter clean, one project

Run it from the project root:

cd ~/code/my_app
flutter clean

flutter clean deletes build/ and .dart_tool/, removes generated files such as the Flutter/ephemeral folders of each platform and .flutter-plugins-dependencies, and on a Mac with Xcode it also asks Xcode to clean the iOS and macOS workspaces. It does not touch ios/Pods, your source code or pubspec.lock.

What happens afterwards: the next flutter run or flutter build runs flutter pub get on its own and then compiles everything from scratch, so the first build is noticeably slower. Your editor may show errors until flutter pub get has run. Nothing is lost except build output.

Cleaning many projects at once

This loop finds every pubspec.yaml that depends on Flutter and has build output, and runs flutter clean in its folder. Run the release file check above first.

find ~/code -name pubspec.yaml -not -path '*/.*' -not -path '*/build/*' | while IFS= read -r f; do
  d=$(dirname "$f")
  if grep -q 'sdk: flutter' "$f" && { [ -d "$d/build" ] || [ -d "$d/.dart_tool" ]; }; then
    echo "cleaning $d"
    (cd "$d" && flutter clean < /dev/null)
  fi
done

The < /dev/null matters: without it, flutter can read from the same input the loop uses and skip projects. Pure Dart packages have no sdk: flutter line and are left alone. flutter clean takes a few seconds per project because of the Xcode step; deleting only build/ and .dart_tool/ with rm -rf is faster and has the same effect on disk space.

The pub cache in ~/.pub-cache

Every package version a project resolves is stored once in ~/.pub-cache and shared. Over time it fills with versions no project uses anymore. Recent Flutter versions can prune just those; preview it first with --dry-run:

# show what would be removed, then remove packages no known project uses
flutter pub cache gc --dry-run
flutter pub cache gc

# empty the whole cache (asks for confirmation)
flutter pub cache clean

# re-download everything currently in the cache
flutter pub cache repair

After flutter pub cache clean, every project downloads its packages again on the next flutter pub get, so you need a network connection before you can build offline. Packages you depend on through path: are not in the cache and are not affected.

iOS Pods, and what this guide leaves out

ios/Pods/ is safe to delete. Keep ios/Podfile and ios/Podfile.lock: the lock file is what makes pod install bring back the same versions. The next iOS build runs pod install for you when it is needed, which takes a while and may need the network. CocoaPods also keeps its own download cache in ~/Library/Caches/CocoaPods.

Android builds use Gradle, which keeps a large cache in ~/.gradle and a per-project android/.gradle folder. That is a separate topic and not covered here. Xcode itself also writes to ~/Library/Developer/Xcode/DerivedData when you build the iOS app; see clearing Xcode DerivedData. If you build Flutter web or use JavaScript tooling, the node_modules guide covers that side.

Doing it with CleanDev

CleanDev scans the folders you choose for Flutter projects and lists their build/ and .dart_tool/ folders with sizes. It only treats a project as Flutter when pubspec.yaml declares Flutter and build/ contains Flutter output. It applies the same rules as this guide:

  • IPA, AAB and APK files that look unuploaded are held for your review, not selected.
  • Build folders of an app that is currently running are protected.
  • Files in build/ it does not recognize are shown for review.

CleanDev Lite is free on the Mac App Store and covers project folders; the full edition also clears the pub cache.

Questions

Is it safe to delete the build folder in Flutter?

Yes. build/ is generated output and the next build recreates it. The only things to keep are release IPA, AAB or APK files you have not uploaded yet.

Does flutter clean delete my code or packages?

No. It removes build/, .dart_tool/ and generated platform files. Your source, pubspec.yaml, pubspec.lock and ios/Pods stay; packages come back from the pub cache on the next flutter pub get.

Should I add .dart_tool to .gitignore?

Yes. .dart_tool/ is generated per machine by flutter pub get and the build tools. New Flutter projects already list it in .gitignore.

Why is the first build after flutter clean so slow?

Everything is compiled from scratch: Dart code, native plugins and, for iOS, the Xcode project. Later builds are incremental again and return to normal speed.

Where is the Flutter pub cache on a Mac?

In ~/.pub-cache by default, unless the PUB_CACHE environment variable points somewhere else. flutter pub cache gc trims it and flutter pub cache clean empties it.

More guides