# Privacy-preserving Mac space review ## Scope first Use `df -h /System/Volumes/Data` for filesystem-level capacity, then choose explicit source roots relevant to the request. Suitable candidates can include Downloads, Movies, approved asset and code workspaces, Library/Caches, Xcode DerivedData and specific package-manager caches. Do not recursively scan the whole home directory, all of Library, external disk roots, or personal backup locations. Never scan MobileSync, Time Machine stores, personal backup trees or Photos packages as incidental cleanup candidates. Exclusion rules are an additional guard, not a replacement for an allowlist. Prune protected directories before descending; do not enumerate their children. Skip symlinks and filesystem boundary crossings. Skip ambiguous backup/archive packages unless explicitly within an authorized nonpersonal scope. Read metadata only, not file contents or hashes. Compare names with `unicodedata.normalize("NFC", name)` on BOTH sides before matching an exclusion set. macOS returns Turkish names such as `Kişisel Klasör` or `Öğrendiklerim` in decomposed (NFD) form from `os.scandir`/`os.listdir`, so a literal NFC set silently fails and the excluded folder gets scanned and listed. This leaked a user-excluded folder's subfolder names into a desktop map once. Verify the exclusion actually fired (e.g. assert the excluded name never appears in output) before showing results. ## Measurement Aggregate file sizes programmatically, retain per-root records, and report permission failures, exclusions and partial/time-limited scans. Count inode pairs once within a measurement scope to avoid hardlink duplication. On macOS, `st_blocks * 512` estimates allocated bytes; `st_size` is logical length. APFS clones, compression and snapshots can prevent these totals from equalling reclaimable space, so do not promise exact savings from a size scan. Bound runtime and output: top directories plus a small set of large authorized files, not a full path dump. Persist results for aggregation rather than mentally adding sizes. A nearly empty Downloads folder may coexist with large caches elsewhere; do not infer whole-disk coverage from the selected roots. ## Classify before proposing action - Personal media and creative project data: candidates for copy/validation/backup, not cache deletion. Editor folders can contain source media, project databases and cache together; inspect only permitted metadata or use the application's storage controls before classifying. - Build output and download caches: often regenerable, but use application/package-manager cleanup controls and explain regeneration costs. Do not describe every path containing `cache` as disposable. - Git worktrees used for parallel agent dispatches each carry their own full build cache (Gradle `.gradle/`/`app/build/`, `node_modules`, `target/`, etc.) — these compound fast (observed: ~4-5GB per worktree, ~30GB+ across 9 worktrees from one parallel-dispatch round) and are near-pure waste once that worktree's branch is merged into the integration branch. - Separate from each worktree's own build output, the GLOBAL shared package-manager cache (`~/.gradle/caches`, `~/.cache/uv`, `~/.npm`, etc.) is itself a single large, regenerable deletion candidate when disk space is critically low (it can reach 10+ GB) — measure it in the SAME pass as the per-worktree `app/build` sweep and include it in the list you show the user for approval, since it is often bigger than any individual worktree's build output and nothing re-downloads it until the next build actually needs it. - Measure the worktree's own children before assuming the bulk is the obvious build dir: deleting `app/build`/`.gradle`/`build` across 11 worktrees once reclaimed only ~1GB, because the real cost was a per-worktree `.toolchain/` directory (3.4GB each, ~38GB total) holding a private Go toolchain — `gocache/` 2.4GB + `gopath/` 737MB + the `go` compiler 271MB — created because one feature (an embedded Tailscale build) needed Go and every dispatched worktree provisioned its own copy. A foreign-language toolchain pinned inside a project/worktree is the same shared-cache anti-pattern as a project-local package cache: keep it for the one worktree whose unmerged feature actually needs it, delete it from the rest, and prefer a shared `GOPATH`/`GOCACHE` next time. Check merge status (`git log --oneline` vs the integration branch, or `git branch --merged`) before suggesting cleanup; a merged worktree's build output is safe to `clean`/delete since it regenerates from source, an unmerged one is still active work. When several parallel dev sessions run on one project, the disk can fill again within an hour of a fix, each time from a DIFFERENT worktree re-downloading its own toolchain. Per-worktree toolchain removal alone may not keep pace; the GLOBAL `~/.gradle/caches` is the next big regenerable candidate (pure downloaded-dependency cache; the next build re-downloads it, slower first build only). Propose it to the user together with the worktree items and trash it (`/usr/bin/trash`, not permanent delete) only after approval. If parallel sessions will keep running, agree with the user in advance how often to re-check `df -h /` and what may be cleared without asking again; a one-time approval does not cover future cleanups. This exact pattern RECURS even after a prior cleanup, repeatedly, on the same project: a disk-full crisis gets traced to the identical `.toolchain/` copy sitting in every worktree (observed growing from 11 worktrees/31GB to 19/68GB to disk down to ~1GB free across separate incidents) because whatever provisions the toolchain per-worktree was never changed to use a shared `GOPATH`/`GOCACHE` — each newly created worktree, including ones made to fix the PREVIOUS crisis, picks up its own fresh copy the moment it runs a build. A one-time sweep does not prevent recurrence; treat this as a standing check every time disk space is reviewed on a project using worktrees with a per-worktree language toolchain, not a problem that was already solved. Check whether the ORIGINATING feature itself has since been merged (`git log main --oneline | grep -i ` for a `Merge branch ''` line) — if so, delete the toolchain from EVERY worktree including the one that originally needed it; there is no longer an unmerged-work exception to preserve. The actual root-cause fix (not yet done, worth proposing each time this recurs) is changing the provisioning script itself (e.g. a `build-aar.sh`-style helper invoked per-worktree) to point at one shared `GOCACHE`/`GOPATH` outside any worktree, so new worktrees stop re-downloading a multi-GB toolchain at all. Before deleting a worktree's `.toolchain`/build-cache directory, confirm no build is actively using it right now (`ps aux | grep -i gradle` or the language's equivalent, filtered to that worktree's path) — deleting out from under a live, in-progress build corrupts that build rather than just costing it a future re-download. If a dispatched session's build is currently running in that worktree, wait for it to finish (or skip that one and clean the others) rather than deleting unconditionally just because the branch is merged. This live-process check generalizes beyond build caches: a directory that LOOKS disposable by name/location alone (e.g. a project's `cache/hf` model-weight folder, duplicating a shared package-manager cache) can be the active backing store of a long-running SERVER process, not a build artifact. `lsof +D ` revealing an open log/data file handle is the tell; confirm with `ps -p -o command` what that process actually is before deleting anything. If it's a live service (not a stale/orphaned handle), stop it cleanly (`kill -15 `, confirm the port is freed with `lsof -i :`) before deleting its cache — say so explicitly to the user rather than deleting out from under a running server. The directory regenerates safely on the service's next run; the risk is an in-flight read/reload failing mid-request, not permanent data loss. Treat the emulator/AVD disk image (`~/.android/avd/*.avd`, often 2-8GB each) as a HIGHER-risk deletion candidate than a toolchain cache, even though it is large and looks similar at a glance: it holds live device state (not a pure network-fetched cache), several AVDs are typically running at once across parallel dispatches, and `ps aux` does not cleanly map a running `emulator-NNNN` ADB serial back to the AVD name that owns it. Do not delete or wipe an AVD reactively during a disk-space crisis unless you have independently confirmed which AVD is idle/unused; prefer finishing the toolchain-cache sweep first; only consider an AVD once its owning dispatch has confirmed-finished and the mapping is unambiguous. When a single project's workflow dispatches several PARALLEL feature-worktree builds (each provisioning its own multi-GB toolchain the moment it runs a build), the critical-disk crisis in this section recurs predictably as EACH worktree's build independently downloads its own copy — reactive cleanup after `no space left on device` is a treadmill, not a fix. Before dispatching N parallel worktree builds on a project with this per-worktree-toolchain pattern, check `df -h /` and budget roughly (toolchain size × N) of headroom up front, or stagger the dispatches so they don't all provision simultaneously; don't wait for the Nth build to fail. - One-off AI video/image-production project folders on this machine (named by project or experiment, e.g. under `Desktop/Projeler/`) follow a repeatable internal pattern: check for it before classifying the whole folder as either precious or disposable. - An `out/` (or similarly-named sprawling) directory full of many versioned subfolders (`v2/`, `v3/`, `hype/`, `det/`, `frames/`, ...) is almost always disposable mid-pipeline render/experiment iterations — tens of thousands of intermediate frame images are common and reflect iteration, not final content. A much smaller, cleanly-named `output/` (or `dist/`) directory holding a handful of final `.mp4`s is the actual deliverable — check file counts and names in each before treating the folder as uniform. - `node_modules/`, `.uv-cache/`, `__pycache__/`, a bundled `cpython-*` interpreter, or a `venv/`/`.venv/` nested inside the project (not the shared global cache) are pure dependency cache, zero reuse value, and typically the single largest line item in a project that otherwise looks small (observed: a 5GB project folder dropped to 282MB after removing only its local HF model cache and a nested venv). Delete these outright before deciding whether the remainder is worth archiving — do not count their size toward 'valuable project data' when sizing an archive destination. - **User rule for video `out/` frames (the user):** keep `out/` render frames for as long as the project is in revision, because a revision reuses them instead of re-rendering. They become deletable only once kullanıcı declares that project "hazır" (ready/final). Do not propose deleting `out/` of an active project, and do not recommend piping frames straight to ffmpeg for in-progress projects. Recent mtime alone is not readiness; ask project by project. Measured 2026-10-29: `out/` was 24.3 GB of ~37 GB across video folders, 23.4 GB of it JPG frames, while delivered mp4s were ~3.2 GB. - Only after the above two cuts, archive what remains (final outputs, `ref/` reference material, small `tools/`/`scripts/` source) — this is usually a small fraction of the folder's original reported size. - Before archiving a tree with many small files (dependency caches, interpreter installs, thousands of frame images) to an ExFAT external destination: check the volume's allocation block size first (`diskutil info /Volumes/ | grep "Allocation Block Size"`). Every file consumes at least one full block regardless of its content size — a 256KB block size observed on one such volume inflated a 290MB source tree to 1.6GB on the destination, confirmed by comparing `du -sh` (block-based) against a raw `stat -f%z` byte sum on both sides. macOS also writes a `._` AppleDouble sidecar file for every real file copied to ExFAT (it cannot hold native resource-fork/xattr metadata), roughly doubling the file count and compounding the per-block waste. This penalty is negligible for a few large media files but severe for many small ones — weigh it before choosing an ExFAT destination for a cache-like or many-small-file tree; a destination with a smaller block size avoids it, or prune to just the large final files before copying. - macOS's bundled `rsync` is the older BSD/openrsync variant (`rsync --version` prints "rsync version 2.6.9 compatible"): the entire GNU `--info=` family (`--info=stats2`, `--info=name0`, etc.) is unrecognized and fails immediately with a usage dump — copying NOTHING, for every single invocation, before any file transfer happens. This is the dangerous failure mode: a loop script that doesn't check rsync's exit code will log "copied: " for every folder while the destination stays empty, and only a later independent size/count verification catches it. Always check the exit code (or just omit GNU-only `--info=`/`--progress2`-style flags entirely) before trusting an rsync-based bulk copy loop; use `--stats` for a BSD-compatible summary instead. Prefer `-rt` (recursive, preserve times) over `-a` (archive mode) when the destination is ExFAT, since ExFAT cannot hold the POSIX permissions/ownership `-a` tries to preserve. For a tree large enough that copy or deletion exceeds the foreground command timeout (many small files over USB are slow even at modest total size), run it with `background=true, notify=true` rather than shelling out to `nohup`/`disown` — the terminal tool rejects shell-level backgrounding wrappers outright. - A `du`-based size mismatch between a verified-identical source/destination pair is not limited to ExFAT cluster-size inflation — it also appears APFS-to-APFS when one volume has transparent compression enabled and the other doesn't, with byte-for-byte identical content. Treat `du`/size-only comparison as a fast first pass, not the final verdict: when file COUNT matches but total size doesn't, run a real content check (`diff -rq --exclude=.git --exclude=node_modules --exclude=.DS_Store `) before deciding the copy is suspect — a `0`-difference result from `diff -rq` is the authoritative confirmation that content is intact regardless of what `du` reports, and clears the pair for source-side deletion. ## Git worktrees and multi-branch repos as deletion/move candidates Before bulk-copying or deleting ANY folder as part of a space-reclaim sweep, check whether it is a git worktree, not a plain directory: a worktree's `.git` is a FILE (not a directory) containing `gitdir: /.git/worktrees/`. Confirm with `[ -f "$d/.git" ] && cat "$d/.git"` rather than assuming a visible `.git` is always the real repo. Moving or `rm -rf`-ing a worktree directly (via Finder drag or shell) leaves the MAIN repo's worktree registry pointing at a path that no longer exists (`git worktree list` shows it as broken/prunable, and the branch's checkout state is left dangling) — always use `git worktree remove ` (from the main repo) instead, or `git worktree prune` afterward to clean the registry if the folder is already gone. Before deleting a whole repository folder on the premise that "it's all on GitHub, we can re-clone" — even when `git remote -v` shows a valid `origin` URL — verify every LOCAL branch actually exists on the remote with `git ls-remote --heads origin` compared against `git for-each-ref --format='%(refname:short)' refs/heads/`, including the CURRENTLY CHECKED OUT branch. Do not treat "no upstream tracking configured" (`git rev-parse @{upstream}` failing) as evidence either way — it is inconclusive, not proof the branch is unpushed, and chasing it burns time; the direct `ls-remote` diff is the only real answer. A repo can have a perfectly valid `origin` remote while the branch actually in use (and potentially dozens of feature-branch worktrees built from it) exists ONLY locally because the remote's default/working branch is a differently-named branch (e.g. local work happens on `sprint-11` while GitHub only has `main` and `sprint-12`) — this is a plausible, easy-to-miss setup, not a weird edge case, especially on a repo with many parallel feature-branch worktrees. If any local-only branch is found, refuse the delete-and-reclone plan and say exactly which branches would be lost; push them (or confirm the user accepts the loss) before any deletion. - When a user has accumulated many one-off content-production project folders (video/image generation experiments, each named per-project) alongside real software projects in the same parent directory, periodically group them under one category subfolder (e.g. a `Video Projeleri` or similarly-named umbrella) so they stop mixing with and cluttering the list of actual product/app repositories. Keep each project's own subfolder and identity intact inside the umbrella — grouping is about location, not merging content. - SDKs, Playwright browser installations, environments, active code repositories and global package directories: dependencies, not automatically disposable caches. Preserve the user's local coding workspace convention. - Existing backups and Photos libraries: excluded unless the precise operation and data boundary are independently authorized. ## Report wording Present measured candidates with proposed next action and risk. Separate 'can archive on the external disk' from 'can clean/rebuild'. State that nothing was deleted or moved when only metadata was examined. Say 'personal backups were excluded by policy', not 'I found other personal backups', unless an authorized discovery actually established that fact. Before archiving a creative/code project to external disk, ask whether it is still active (expecting more feedback/revision rounds) rather than assuming finished-looking output means done. Moving an active project off the internal disk adds real friction to its next revision: USB read/write is slower than internal SSD for many-small-file trees, and if dependency caches were cleaned as part of the same pass, the next run must re-download/reinstall them first. Archive confidently once a project is confirmed finished; for an active one, clean its disposable caches in place but leave the project on the internal disk. ### Selective archiving: keep the reusable 'recipe', offload only the bulk A user who produces many style/technique variants of the same kind of project (video, design, etc.) will want to re-reference or reuse a past project's approach even after it is archived — a full move that empties the local folder forces mounting the external disk just to remember how something was done. Don't present 'fully move the whole folder' and 'leave it alone' as the only two options. The technique that satisfies both space reclamation and future reuse: 1. Copy the WHOLE project tree to the external destination first; verify with a file-count AND byte-size comparison on both sides (not `du`, which is cluster-size-inflated on ExFAT — sum raw `stat` sizes). Do not delete anything locally before this verification passes. 2. Only after verification, prune LOCALLY by size, not by deleting the whole folder: walk the project's immediate children and remove only the ones at or above a size threshold (e.g. 150MB) — these are almost always the render/output/cache bulk. Leave everything smaller in place untouched: scripts, source, prompts, config/recipe JSON, reference images, README/STORYBOARD docs. This is exactly the material that defines the reusable 'style', and it is normally a tiny fraction of the folder's reported size. 3. Drop a short local marker file (e.g. `_ARSIV_BILGISI.md`) in the pruned folder recording the verified backup's full path and date, and which size threshold was applied — so a future session (or the user) immediately knows the rest exists and where, without guessing or re-deriving it. 4. If this is automated (e.g. a recurring cron sweep over many project folders), make the whole operation idempotent and resumable: skip a folder that already has the marker file, and never let a partial/killed run leave a folder in an ambiguous state — the verify-then-prune order means a killed run before verification leaves the local copy completely untouched, which is the safe failure mode.