DEV Community

Zeeland
Zeeland

Posted on Originally published at cublet.cc

MCP vs. Shell Loops for AI Coding Agent Disk Cleanup on macOS APFS

When a Mac runs low on disk space in the middle of a multi-worktree Rust or Go session, letting a coding agent clean up via raw shell commands is slow and token-heavy. The agent typically chains du, find, lsof, rm -rf, and df across multiple turns, dumps noisy directory listings into its context window, and risks touching active build directories or misreading APFS available space.

We built Cublet, an open-source (MIT) macOS disk space analyzer backed by a native Rust scanner and local SQLite index, and bundled a local stdio MCP server (cublet-cleaner) inside it. Then we ran matched APFS benchmarks comparing the same coding agent using raw shell commands against the same agent using Cublet MCP.

Full benchmark data and methodology are published on cublet.cc/benchmarks/agent-mcp-vs-shell-cleanup/.

Benchmark summary: MCP vs. shell loops on APFS

Across six paired repeated-use runs on controlled APFS volumes (normalizing the shell baseline to 100, lower is better):

Metric Shell baseline Cublet MCP Observed savings
Recovery time 100 27 ~73% less time
Total tokens (input + output) 100 34 to 42 58 to 66% fewer tokens
Workload tokens (uncached input + output) 100 50 to 69 31 to 50% fewer tokens

These ranges span the paired medians across three controlled APFS test cases under the same Codex configuration:

  1. Nested Rust Git worktrees: multiple branches holding separate rebuildable target/ directories next to an active build.
  2. Changed scope with stale history: previously saved scan data no longer matches current directory contents, requiring fresh verification before cleanup.
  3. Ongoing disk writes: background writes continue during cleanup, testing whether the agent recovers sustained available space rather than a temporary dip.

Every run had to pass the same gate: at least 320 MiB of sustained available space on the APFS volume, followed by a real 96 MiB write check and an offline cargo continuation check.

These numbers come from controlled APFS development fixtures rather than a universal guarantee across every machine or MCP client, but the structural reason for the gap is straightforward: structured tool responses keep raw directory trees out of the LLM context window and fold scope checks, active-build protection, deletion, and space verification into one local call.

Native Rust scanner and SQLite baseline restore

Cublet's scanning core is written in Rust (rust-core). It uses macOS bulk metadata reads (getattrlistbulk) with bounded parallel workers and stores completed directory totals in a local SQLite index. That lets both the desktop app's Growth diff view and the MCP server compare scans over time without blindly re-walking unchanged trees.

In development timings on macOS (5-run median, warm OS cache, empty 256 MiB app cache):

  • 8,329 folders / 643 file entries: 193 ms complete scan, 21 ms stored measurement restore from SQLite.
  • 52,009 folders / 4,003 file entries: 1,128 ms complete scan, 75 ms stored measurement restore from SQLite in a fresh process.

The 75 ms number is restoring an already-saved SQLite measurement in a new process, not a cold full-disk crawl.

Why APFS cleanup needs explicit guardrails

Deleting files on APFS does not always immediately raise reported free space. Local Time Machine snapshots, APFS clones, hard links, and purgeable space can hold blocks even after rm returns success. We documented the verification steps in our APFS purgeable space guide and our Rust target/ and Git worktree cleanup guide.

Because disk deletion is destructive, cublet-cleaner enforces three boundaries by default:

  • Connecting MCP does not authorize deletion: you still explicitly authorize the task and target scope before cleanup runs.
  • Active-build protection: rebuildable Rust target/ and Go build caches are checked for active or uncertain inputs before removal, and receipts report deleted allocation separately from observed APFS available space.
  • Local-only scanning: scans stay on your Mac; only the structured paths, metadata, and cleanup receipts returned to your connected agent are processed by whichever AI model provider you use.

Try Cublet and the local stdio MCP server

Cublet is MIT-licensed, free, and ships signed and notarized macOS 13+ builds for both Apple Silicon and Intel:

brew install --cask undertone0809/tap/cublet
Enter fullscreen mode Exit fullscreen mode

Or download the signed DMG directly from cublet.cc.

To wire cublet-cleaner into Claude Code, Codex, or Cursor over local stdio:

{
  "mcpServers": {
    "cublet-cleaner": {
      "command": "/Applications/Cublet.app/Contents/Resources/bin/cublet-cleaner",
      "args": ["--mcp", "--profile", "cleanup", "--allow-cleanup"]
    }
  }
}
Enter fullscreen mode Exit fullscreen mode

Full tool contracts, safety flags, and client setup instructions are at cublet.cc/mcp-disk-cleaner/, and the full source code is on GitHub at Undertone0809/Cublet.

Top comments (0)