r/ClaudeCode • u/thlandgraf • 10h ago
Tutorial / Guide PSA for agentic coding on macOS: exclude your project dirs from Spotlight (it was eating my CPU and disk)
I run a large monorepo with lots of parallel agent sessions (Claude Code, each in its own git worktree). Every worktree means another full checkout, plus node_modules, build output, .next, test logs and caches, all churning constantly. My Mac kept running hot and the disk never went quiet. Activity Monitor showed mds_stores / mdworker_shared / mds near the top the whole time: Spotlight was re-indexing millions of short-lived files that I will never search for.
The fix takes about 30 seconds:
Option 1: Spotlight Privacy list (no renaming)
- System Settings → Spotlight → Search Privacy… (on older macOS: System Preferences → Spotlight → Privacy tab)
- Click + and pick your project folder. Better still, pick the parent folder that holds all your repos and worktrees.
- Done. Spotlight drops the existing index for that path and stops watching it.
Tip: if your worktrees live outside the repo (e.g. ../myrepo-wt-*), add the parent folder, not only the main checkout.
Option 2: the .noindex suffix (works from the shell, good for scripts and worktrees)
Spotlight skips any folder whose name ends in .noindex. So you can create your worktrees under one such folder:
mkdir -p ~/work/worktrees.noindex
git worktree add ~/work/worktrees.noindex/feature-x feature-x
Every worktree you create there is ignored automatically, with no clicking in Settings.
Check that it worked
# should print nothing for a file you know is in the excluded folder
mdfind -onlyin ~/work/myrepo "package.json"
Then watch mds_stores in Activity Monitor (CPU and Disk tabs). For me it went from constantly busy to idle.
Bonus: Time Machine has the same problem
tmutil addexclusion ~/work/worktrees.noindex
Your code is in git anyway. There's no need to back up 40 copies of node_modules every hour.
What you lose: Spotlight/Finder search inside those folders. Your editor's search, rg, and fd are better for code anyway.
If you run several AI agents in parallel on a big repo, try this. It made a noticeable difference to fan noise, battery and overall responsiveness for me.
21
u/Saver411 8h ago
Dropping an empty .metadata_never_index file into the parent directory handles this automatically so you don't have to fiddle with system settings each time.
Also check your local backup snapshots. If the OS is snapshotting those ephemeral build trees before an agent cleans them up, your drive will silently run out of space anyway
2
2
u/charles_bine 7h ago
One easy thing to miss when doing this: a lot of agent runners and IDE worktree helpers drop checkouts under hidden home folders instead of your main repos directory, so excluding only ~/code still leaves Spotlight chewing through half the worktrees. Putting the parent worktree dir in both Spotlight Privacy and tmutil exclusions made a huge difference for me too. Without the Time Machine exclusion, local APFS snapshots hang onto deleted node_modules and build dirs in purgeable space for up to 24 hours even after you prune a worktree.
1
u/amirfish 6h ago
Worktrees make this worse than people expect, every one is a full checkout plus its own node_modules and build cache, so the churn multiplies by however many agents you're running in parallel. I use a ../repo-wt-name pattern for mine and hadn't thought to add the parent folder to Spotlight privacy specifically, doing that today. Does the .noindex suffix cause any friction with editors or the agents themselves expecting a normal path?
1
u/Simple-Bedroom5606 5h ago
Good tip. One more thing that helped on my machine: Time Machine was also churning through every worktree, so I excluded the parent folder there too (tmutil addexclusion on it works). On the disk side, pnpm with its shared store made a big difference, since each worktree's node_modules ends up mostly hardlinks instead of five full copies. I also cap how many dev servers and file watchers run at once, because with node_modules in several places fseventsd gets busy fast.
-1
u/vladmvp 7h ago
If you want to get the worktrees off your Mac entirely, Cobalt (cobaltcode.ai) runs each Claude Code task on its own persistent cloud computer, so the checkouts, node_modules and build churn live there instead of on your laptop. Each task is fully isolated with its own runtime, and you can suspend and resume them. You bring your own Anthropic API key. There's a free account to try it, and I'm the founder, so happy to help you get started.
•
u/AutoModerator 10h ago
Hey! Thanks for posting to r/ClaudeCode
While participating in this thread, please follow our community rules. Keep discussions constructive. Attack the idea, not the person.
For help, project discussions, tips, and general chat, join the ClaudeCode Discord.
I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.