← sources

Claude Code kept filling my 256 GB Mac, so I had Claude clean it up. 45 times in 3 weeks.

source: reddit (reddit:ClaudeCode)published 2026-11-18 14:30ingested 2026-11-19 02:39

retained text

256 GB MacBook, 16 GB RAM, Claude Code + Codex + opencode running pretty much all day.

For the last three weeks I've been typing "clean up junk" into a Claude session about twice a day. 45 times in 19 days. My low point was 125 MB free.

Every cleanup got back 10–16 GB, and it never lasted. On a busy day the running sessions wrote 17 GB back in two and a half hours.

So I made the agent log every deletion and tell me what it found. It's mostly not caches and logs. It's the agents' own leftovers.

**What actually ate the disk**

| What | Worst I saw | Where |
|---|---|---|
| Build copies in agent scratch folders | 26 copies of DerivedData, 6.5 GB | `/private/tmp` |
| Claude Code transcripts | 11 GB. One log was 262 MB, 175 MB of it base64 screenshots | `~/.claude/projects` |
| Rust `target` | 9.8 GB in one project, 5.3 GB in a single worktree | `<project>/target` |
| iOS simulators | 6.1 GB for one device, 17 GB for the iOS runtime | `~/Library/Developer/CoreSimulator` |
| Codex sessions | ~650 MB a day, plus a 1.4 GB history database | `~/.codex` |
| Swap | up to 16 GB | `/System/Volumes/VM` |

The scratch builds were the big surprise. When an agent compares a few approaches, it builds each one in its own folder. One session left 6 full copies of DerivedData behind, 6.9 GB, one per variant. Nothing ever deletes them.

The second surprise: simulators eat RAM, and on 16 GB that RAM turns into disk. `SimMetalHost` grew to 8–13 GB and swap went up to 16 GB. Shutting down one simulator dropped swap from 14.3 GB to 5.1 GB.

**The time Claude deleted source code**

Early on, it decided two folders were build junk and wiped them. They had the source of two test packages in them. Nothing important, but that was the end of "just clean stuff up". These are the rules it gets now:

- Only delete what hasn't been touched for 3+ hours. Anything newer belongs to a session that's still working, and it'll just rebuild it. I watched one session rebuild 3 GB within 2 hours of me deleting it.
- Run `lsof +D <folder>` first. If anything has it open, skip it.
- Nothing while a build is running.
- Full paths only, no globs, and every deletion goes into a log.
- Hands off the pnpm store, browser profiles and memory folders.

**If you'd rather do it yourself**

Scratch builds:

```
du -sh /private/tmp/* 2>/dev/null | sort -h | tail -20
find /private/tmp -maxdepth 3 -type d -name DerivedData -mmin +180 -exec du -sh {} +
```

Heaviest Claude Code transcripts:

```
find ~/.claude/projects -name '*.jsonl' -size +50M -exec du -h {} + | sort -h
```

Old transcripts go away after `cleanupPeriodDays`, which is 30 by default. I set `"cleanupPeriodDays": 7` in `~/.claude/settings.json`, and the first cleanup with that rule freed 7.4 GB. Deleting a transcript only means you can't `/resume` that session.

The rest:
- Simulators: `xcrun simctl shutdown all` when you're done with them. `xcrun simctl delete unavailable` clears devices for runtimes you don't have anymore.
- Rust: `cargo clean` in finished projects. Each worktree gets its own `target`.
- Xcode: deleting `~/Library/Developer/Xcode/DerivedData` is always safe, it just rebuilds.
- Node: `npx npkill` shows every `node_modules` with its size and age.

**Stuff that fooled me**

- Deleting `node_modules` in a pnpm project frees almost nothing. They're hard links into the store. Run `pnpm store prune` instead.
- If the agent moves files to the Trash, you get nothing back until you empty it.
- `du` said two old Chrome copies took 2.2 GB. Deleting them freed nothing, because they were APFS clones of the installed app.
- Some things come right back. Codex re-downloads its 1.6 GB runtime, and a project using Hugging Face models pulls its 1.9 GB again.
- A macOS update downloading in the background grew Preboot to 19.4 GB. It went back to 9.8 GB once I installed it.

**What I'd set up on day one**

`cleanupPeriodDays: 7`, the same 7 days for Codex sessions, and simulators off unless I'm taking screenshots. And when the disk gets low, this prompt:

> Free disk space. Only delete build outputs and caches (DerivedData, target, .build, node_modules, package caches) that haven't been modified for 3+ hours and that no process has open (check with lsof). Skip anything while a build is running. Use full paths, no globs. Never touch the pnpm store, browser profiles or memory folders. Log every deletion with its path and size to ~/cleanup.log. Ask before deleting anything that isn't a build output or cache.

I still have to run it every day or two, which is kind of absurd. Has anyone found a better setup? Cursor and Windsurf folks, what do yours leave behind?

document fetched 2026-11-19 00:41 · canonical https://reddit.com/r/ClaudeCode/comments/1xzgmo3/claude_code_kept_filling_my_256_gb_mac_so_i_had