How to Configure Spotlight Search Privacy and Exclude Folders on Mac in macOS

Spotlight is one of the most powerful navigation features on the Mac, automatically indexing documents, emails, codebases, media files, and system preferences so you can locate anything on your drive in seconds. However, this aggressive background indexing is not always desirable. Developers working with large node_modules directories, git repositories, or virtual machine disk images often notice intense CPU utilization (driven by the mds and mdworker processes) during active indexing. Additionally, storing sensitive financial records, private client documents, or proprietary archives on your Mac can pose confidentiality risks if they appear in casual Spotlight search queries.

Fortunately, macOS includes dedicated Search Privacy controls that allow you to exclude specific folders, volumes, and external drives from the Spotlight index. Adding directories to the exclusion list immediately removes their contents from search results and stops the background indexer from scanning them, saving processor cycles and preserving data privacy. In this guide, you will learn how to access Spotlight privacy settings, exclude directories and external drives, re-index folders to fix search corruption, and verify index status via the terminal.

Why Exclude Folders from Spotlight Indexing?

Managing Spotlight’s indexing scope provides both privacy and performance benefits:

  • Preventing Search Leaks: Keep confidential agreements, client data, and encrypted container files from appearing in Spotlight suggestions when presenting your screen or sharing your desktop.
  • Eliminating Developer Lag: Stop mds and mds_stores processes from thrashing your CPU when building projects with massive dependency folders (such as node_modules, vendor, or .build).
  • Preserving Battery Life and SSD Health: Reduce unnecessary disk writes and background CPU usage on portable MacBooks when managing large external drives or backup archives.
  • Resetting Corrupt Search Indexes: Adding and then removing your primary drive from the Privacy list forces macOS to flush corrupt metadata and rebuild a clean Spotlight catalog.

Step 1: Access Spotlight Privacy Settings in macOS

The Search Privacy exclusion panel is located within System Settings:

  1. Click the Apple menu () in the top left corner of your screen and select System Settings.
  2. In the left sidebar, scroll down and click Siri & Spotlight (or Spotlight on older macOS versions).
  3. Scroll down to the bottom of the right-hand pane and click the Search Privacy… button.

A sheet will slide down titled Prevent Spotlight from searching these locations, displaying your currently excluded directories.

Step 2: Add Folders or Drives to the Exclusion List

You can add folders, complete directory trees, or entire external hard drives to the exclusion list:

  1. Click the + (Add) button at the bottom of the Search Privacy dialogue box.
  2. In the file picker window, navigate to the folder or drive you wish to exclude (for example, a private client directory or a developer workspace).
  3. Click Choose to add the selected folder.
  4. Alternatively, you can open Finder side by side and drag and drop folders or external drive icons directly into the Search Privacy list.
  5. Click Done to save your privacy preferences.

macOS immediately purges the selected location from its active Spotlight index. Files stored within those folders will no longer surface when pressing Cmd + Space.

Step 3: Exclude Developer node_modules Directories

If you build modern web applications, the millions of small JavaScript files in node_modules can drastically slow down your Mac during background indexing. While you can add individual project folders to the Privacy GUI, you can also exclude directories from the command line using terminal metadata flags:

Preventing Indexing with .metadata_never_index

Spotlight respects a special hidden file named .metadata_never_index. If you create this empty file inside any directory, Spotlight will completely ignore that folder and all its subfolders:

touch ~/Projects/my-app/node_modules/.metadata_never_index

Configuring Global Git Clones to Auto-Exclude

You can place .metadata_never_index at the root of a shared developer directory (such as ~/Developer/.metadata_never_index) to prevent Spotlight from ever indexing local development builds.

Step 4: Force Spotlight to Re-Index a Folder or Drive

If Spotlight search becomes unresponsive, fails to locate existing applications, or returns stale results, you can use the Privacy pane to initiate a clean re-indexing cycle:

  1. Open System Settings > Siri & Spotlight > Search Privacy….
  2. Click the + button and select your primary hard drive (e.g., Macintosh HD).
  3. Click Choose to add the drive to the exclusion list. This completely wipes the existing search index.
  4. Wait ten seconds, then select Macintosh HD in the list and click the – (Remove) button.
  5. Click Done.

macOS will automatically begin re-indexing your entire storage drive from scratch. You can monitor the progress bar by pressing Cmd + Space and typing any word.

Step 5: Verify Spotlight Indexing Status via Terminal

To inspect or control Spotlight indexing from the command line, use the native mdutil utility:

Checking Indexing Status for All Volumes

mdutil -s -a

Outputs whether indexing is enabled or disabled for each mounted disk volume.

Disabling Indexing on an External Backup Drive

If you connect a high-capacity external drive that you do not want Spotlight to scan:

sudo mdutil -i off /Volumes/ExternalBackup

Purging and Rebuilding Volume Index via Command Line

sudo mdutil -E /Volumes/Macintosh\ HD

This securely flushes the Spotlight database and triggers an immediate background rebuild.

Get the best tech tips delivered straight to your inbox.

Join thousands of readers mastering Apple, Google, Microsoft, and Linux.