Run three or four coding agents on a MacBook for an afternoon and the fans might come on even when no build is running. Open Activity Monitor and you will often find two processes near the top: mds_stores and fseventsd.
The common advice is to exclude agent folders from Spotlight, or to turn Spotlight off completely. The first part works. Turning it off goes further than most people need, and the advice often credits the Spotlight change for calming fseventsd, which it does not do. This guide covers the folder exclusion, a way to check it actually worked, and what to do about the rest.
Why Agents and Spotlight Fight
Spotlight is three kinds of process working together. mds is the metadata server. mdworker and mdworker_shared open files and pull out what Spotlight searches: names, text, dates. mds_stores writes the index itself. The workers wake up when a volume is mounted or when a file changes.
That last part is the problem. A coding agent writes files constantly. Each git worktree is a full checkout of the project. Each npm install drops thousands of small files into node_modules. Run several agents in parallel, each in its own worktree, and Spotlight is asked to read and index a large tree that changes every few minutes.
One developer documented this in a public gist. The mds process was at 84 percent CPU. The code folder held 111 worktrees and 231 node_modules folders. Spotlight had 119,329 package.json files in its index.
None of those files need to show up when you press Command+Space.
Step 1: Confirm It Is Spotlight
Before changing settings, find out what is actually busy. A hot laptop could be Spotlight, but it could also be five dev servers watching the same build folder.
Open Activity Monitor, sort by CPU, and look for mds, mds_stores and mdworker_shared. To see which paths they are touching, run a short trace (this command comes from Flavio Copes' write-up on agent file churn):
sudo fs_usage -w -f filesys -t 10 fseventsd mds mdworker_shared
The output prints real paths from your disk, so keep it local. If most lines point into your projects folder, node_modules or worktree folders, Spotlight is the culprit.
Step 2: Exclude the Smallest Folders That Solve It
Apple's Search Privacy guide gives the path:
- Open System Settings and click Spotlight in the sidebar.
- Click Search Privacy in the lower right.
- Click the plus button and pick a folder, or drag folders into the list.
Good candidates for an agent workstation:
- The folder that holds your projects and worktrees (for example
~/Developeror~/code) -
~/.claude, where Claude Code keeps sessions and local state -
~/Library/Developer, which holds Xcode's DerivedData and simulator files
Two details trip people up. First, the list takes specific folders, not name patterns. You cannot add "node_modules" once and have it apply everywhere, so exclude the parent projects folder instead. Second, ~/.claude and ~/Library are hidden. Press Command+Shift+Period in the file picker to show them.
There is also a second setting that looks similar and is not. The same gist found that unticking a folder under Spotlight's results options only hid the results. The files stayed in the index and kept being re-indexed. Search Privacy is the list that stops indexing.
Step 3: Check That the Exclusion Worked
Don't judge this by CPU alone. Agents go idle, and CPU drops for that reason too. Ask the index directly:
mdfind -onlyin ~/Developer -name package.json | wc -l
Run it before and after. Once Spotlight finishes cleaning up, the count should fall to zero or close to it. If it does not, the exclusion did not take.
Expect one last spike while that cleanup runs. In the gist, removing 119,000 entries pushed mds_stores to about 98 percent CPU and 2 GB of memory for a few minutes. After that it dropped back under 100 MB.
Step 4: Make the Agents Write Less
Excluding folders treats the symptom. The cause is that agents create a lot of files. Claude Code has two settings for this, both documented in its large codebase guide:
{
"worktree": {
"sparsePaths": [".claude", "packages/api", "packages/shared"],
"symlinkDirectories": ["node_modules"]
}
}
sparsePaths uses git sparse checkout, so a new worktree only gets the listed directories plus root-level files. symlinkDirectories links each worktree's node_modules back to the main copy instead of duplicating it. Fewer files on disk means less for Spotlight, your file watchers and your backups to process.
Both come with a trade-off. A sparse worktree simply does not contain the directories you left out, so an agent that needs one of them will not find it. A symlinked node_modules is one shared copy, so if an agent installs or upgrades a package in one worktree, every other worktree sees the change. Use it when parallel agents work on the same dependency set, not when one of them is testing a dependency upgrade.
The same idea works with any agent tool. Reuse a running dev server instead of starting one per agent. Skip npm install when the lock file has not changed. Delete worktrees when their branch is merged.
What the Spotlight Fix Does Not Touch
This is where the usual advice gives the fix too much credit. fseventsd is not part of Spotlight. It is macOS's file change notification service. Spotlight listens to it, and so do Time Machine, editors, language servers and test runners. As Flavio Copes puts it, the two systems are separate, so "turning off Spotlight for a volume only pauses search indexing. File events still fire."
So if fseventsd drops to almost nothing right after a Spotlight change, the more likely reason is that the agents stopped writing at the same time. Excluding folders from Spotlight does not reduce the events your agents create. Only writing fewer files does that (Step 4).
Leave fseventsd itself alone. Killing it on a schedule, or disabling it, breaks backups and file watchers well outside the folder you wanted to quiet down.
When Turning Indexing Off Makes Sense
The bigger switch, sudo mdutil -a -i off, turns indexing off on every volume. The mdutil reference confirms the syntax. It is reasonable on a machine that only runs agents and that nobody searches.
On your daily laptop it is a bad trade. Spotlight, Finder search and Mail search all depend on the index. Excluding your whole home folder causes much the same damage. Apple also warns in the Search Privacy guide that excluding certain folders can stop update notifications for some apps.
If you want a clean boundary without losing search, there is a middle option: put agent work on its own APFS volume and turn indexing off only there.
mdutil -s /Volumes/AgentWork
sudo mdutil -i off /Volumes/AgentWork
The volume shares the same SSD, so it is not faster. It just keeps the settings separate. Moving projects there can break absolute paths in editors and agent configs, so plan for that. To undo either change, run the same command with -i on, then give Spotlight time to catch up.
Quick Checklist
- Confirm with Activity Monitor or
fs_usagethat Spotlight is actually the busy process. - Add your projects folder,
~/.claudeand~/Library/Developerto Search Privacy. - Verify with
mdfind -onlyin <folder> -name package.json | wc -l, not with CPU alone. - Cut file churn at the source with sparse worktrees and shared
node_modules. - Leave
fseventsdalone, and savemdutil -a -i offfor machines nobody searches.
Have you traced a hot Mac back to something other than Spotlight while running agents?
Top comments (1)
The
mdfindbefore/after count is a useful search-level check. One thing I would pin down is whether zero results means index cleanup has finished, or only that Search Privacy now suppresses those results. If the latter, CPU can still spike after the count reaches zero.A controlled comparison would keep the agents running at the same workload and sample
sudo fs_usage -w -f filesys -t 10 mds_stores mdworker_sharedfor equal intervals before and after. Pairing that withmdutil -s <volume>would separate search visibility, index state, and actual filesystem activity instead of relying on the count alone.