fluttercleaner

Run "Flutter Clean" in All Your Project Directories

FlutterCleaner

FlutterCleaner is a lightweight, high-performance CLI tool written in Go. It recursively scans your development directories, identifies Flutter projects, and executes flutter clean on them automatically.

🎉 Success Story

The inspiration for this tool came from a real-world need. On its first run, this tool reclaimed 30GB of disk space by removing old build artifacts and cached data from forgotten projects.

🚀 Why use this?

Flutter projects generate a significant amount of data in the build/ and .dart_tool/ directories. While necessary for incremental compilation, these folders can grow indefinitely. If you have dozens of projects sitting idle, you are likely wasting gigabytes of storage.

  • Automated: No need to manually open terminal windows for every project.
  • Fast: Written in Go for speed; ignores hidden folders like .git and .idea for faster traversal.
  • Safe: Only runs clean commands where a pubspec.yaml exists.

🛠️ Prerequisites

  • Go (Golang) installed on your system.
  • Flutter installed and added to your system PATH.

📦 Installation & Build

  1. Clone this repository or download the source code.
  2. Initialize the module:
    go mod init fluttercleaner
  3. Build the executable:
    go build
    This will generate a binary file named fluttercleaner (or fluttercleaner.exe on Windows).

💻 Usage

  1. Move the fluttercleaner executable to your root projects directory (e.g., ~/Projects or D:\Dev).

  2. Run the tool:

    Mac/Linux:

    ./fluttercleaner

    Windows:

    fluttercleaner.exe

The tool will print the directories it finds and the status of the clean operation:

Searching for Flutter projects in: /Users/dev/Projects
---------------------------------------------------------
Found project at: /Users/dev/Projects/cool_app
  > Running 'flutter clean'... SUCCESS
Found project at: /Users/dev/Projects/old_demo
  > Running 'flutter clean'... SUCCESS
---------------------------------------------------------
Done.

⚙️ How it Works

The application uses Go's filepath.WalkDir to traverse the file system.

  1. It looks for any file named pubspec.yaml.
  2. It verifies the folder is not a hidden directory (starts with .).
  3. It executes exec.Command("flutter", "clean") in that directory.
  4. It captures and reports success or failure.