r/ClaudeCode • u/thlandgraf • 2h 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:
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
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
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.
•
u/AutoModerator 2h 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.
1
u/_cuddle_factory_ 53m ago
Thanks
1
u/Saver411 13m ago
Dropping an empty
.metadata_never_indexfile 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