# Claude Code making your Mac slow? Find the cause and fix it

Why your Mac slows down and the fans spin up while Claude Code works, how to find the process using CPU and memory, and how to fix it.

Source: https://hivemux.dev/guides/claude-code-mac-slow/

> The claude process itself is light. What loads the Mac are the commands Claude runs, such as test runners, builds, dev servers, Docker and watchers left running, multiplied by every session you have open. Find them with Activity Monitor or `ps -Ao pid,pcpu,rss,command -r | head`, stop leftover servers, limit test workers, cap Docker's memory, or run the heavy commands on another Mac.

You start a few Claude Code sessions, and half an hour later the Mac is sluggish, the fans are loud and switching apps takes a second. It is tempting to blame Claude Code, but the `claude` process spends most of its time waiting for the model. The load comes from what Claude runs: `npm test`, `cargo build`, `npm run dev`, `docker compose up`, a `tsc --watch` started an hour ago. One session doing that is fine. Four sessions doing it at once, on top of a browser and an editor, is more than most laptops have.

This guide finds the process that is actually busy, fixes what can be fixed on the same Mac, and covers what to do when the Mac is simply too small for the work.

## Step 1. Find the process using CPU

Open Activity Monitor (Applications › Utilities), choose the CPU tab and sort by **% CPU**. 100% means one full core, so a test runner on an 8-core Mac can show 700% or more. View › All Processes, Hierarchically shows which terminal or session a process belongs to.

The same in a terminal:

```sh
top -o cpu
```

Or a one-off list, highest CPU first:

```sh
ps -Ao pid,pcpu,rss,command -r | head -15
```

`pcpu` is the CPU percentage and `rss` the memory in kilobytes. Things you will typically see near the top:

- `node` running Jest, Vitest, webpack, Vite or a Next.js dev server
- `rustc`, `cargo`, `clang`, `swift-frontend` or `java` from a build
- `com.apple.Virtualization.VirtualMachine`, the VM behind Docker Desktop or OrbStack
- `mds`, `mds_stores` and `mdworker_shared`, Spotlight indexing (see Step 3)
- several copies of the same MCP server, one per Claude Code session

## Step 2. Check memory and leftover servers

In Activity Monitor's Memory tab, look at **Memory Pressure** at the bottom. Green is fine even if "Memory Used" looks high; macOS uses free memory as cache. Yellow or red, with a growing "Swap Used", is when the Mac slows down. Sort by memory to see what holds it, or use `ps -Ao pid,pcpu,rss,command -m | head -15` to sort by memory in a terminal.

Dev servers are the most common leftovers. Claude starts one to check a page, the task ends, and the server keeps running in the background. List everything that listens on a TCP port:

```sh
lsof -nP -iTCP -sTCP:LISTEN
```

Each line shows the command, the PID and the port (`*:5173`, `127.0.0.1:3000`). Stop the ones you no longer need:

```sh
kill 41237          # the PID from lsof
```

Docker is the other large holder. Docker Desktop and OrbStack run a Linux VM, and its memory counts against your Mac whether or not the containers are doing anything. `docker ps` lists running containers; `docker compose down` in the project stops a compose stack.

## Step 3. Spotlight indexing new folders

Every `npm install`, new git worktree or fresh build folder creates thousands of files, and Spotlight indexes each one. While it does, `mds_stores` and `mdworker_shared` can use several cores for minutes. With several sessions each creating worktrees and installing dependencies, it keeps happening.

You rarely need Spotlight to search source trees. Two ways to keep it out:

- **System Settings › Spotlight › Search Privacy:** add your code folder (for example `~/code`). Spotlight stops indexing everything inside it.
- **A folder name ending in `.noindex`:** Spotlight skips such a folder and everything in it. Handy for scratch copies and caches, for example `~/scratch.noindex/`.

Excluding the code folder also hides it from Spotlight search in Finder; Finder's own folder browsing and `grep` work as before.

## Step 4. Make the commands lighter

Most of the load can be cut without changing how you work.

**Limit test workers.** Jest and Vitest start one worker per core by default (minus one), and several suites at once compete for the same cores. Both accept a percentage:

```sh
npx jest --maxWorkers=50%
npx vitest run --maxWorkers=50%
```

Put it in the `test` script in `package.json` so Claude uses it too. Other tools have their own switch, for example `cargo build -j 4` or `make -j4`.

**Run tests once, not in watch mode.** `jest --watch`, `vitest` (watch by default in a terminal), `tsc --watch` and `nodemon` keep running after Claude has read the result. Use `vitest run` and plain `jest`.

**Tell Claude.** A few lines in the project's `CLAUDE.md` change its habits:

```markdown
- Run only the tests related to the change, not the whole suite, unless asked.
- Do not start watchers (--watch, nodemon). Run tests once.
- Stop any dev server you started once you have checked the page.
- Check `lsof -nP -iTCP -sTCP:LISTEN` before starting a dev server; reuse one that is already running.
```

**Cap Docker's memory.** In Docker Desktop, Settings › Resources sets the CPU and memory limit of its VM. OrbStack has a memory limit in its settings as well. Stop compose stacks of projects you are not working on.

**Stagger heavy work.** Two sessions writing code and one running the full test suite is fine; three full test suites and a production build at the same moment is not. With [several sessions in parallel](/guides/run-multiple-claude-code-sessions/), let the heavy runs take turns.

## Step 5. When the Mac is simply too small

A 16 GB laptop running four sessions, each with a dev server and a test suite, may have nothing left to trim. If you have another Mac, such as a desktop at home or an older one at the office, it can take the heavy commands while you keep working on this one.

### By hand over ssh

Turn on Remote Login on the other Mac (System Settings › General › Sharing), copy the project and run the command there:

```sh
rsync -a --exclude node_modules ~/code/shop/ me@other-mac.local:code/shop/
ssh me@other-mac.local 'cd code/shop && npm ci && npm test'
```

This works for a single run you start yourself. It does not fit Claude's loop: Claude runs `npm test` here, not your ssh line, the copy goes stale after every edit, and a dev server started there is not on this Mac's `localhost` until you forward its port (see [opening a remote dev server on localhost](/guides/remote-dev-server-localhost/)).

### With hivemux swarm

hivemux swarm does the same automatically. A Claude Code PreToolUse hook sees a command such as `npm test`, `cargo build` or `npm run dev` in a project you turned on and runs it on whichever of your Macs has room. Claude reads the same output and exit code as if it had run locally, and a dev server's ports open on this Mac's `localhost`.

```sh
brew install hivemux/tap/hivemux-swarm
hivemux swarm add                   # prints one line to paste in Terminal on the other Mac
cd ~/code/shop && hivemux swarm on
hivemux swarm hook install          # Claude sessions started from now on use it
hivemux swarm status
```

Without hivemux installed, the command is `hivemux-swarm` instead of `hivemux swarm`. Things that matter for a slow Mac:

- The Mac you work on counts as a worker too, but keeps 2 cores and 4 GB for Claude and you.
- Before each run the other Mac's copy is brought up to date (what git tracks plus `.env*`, over rsync). `node_modules`, `target` and `.venv` are never copied; each Mac installs its own when the lock file changes.
- Docker jobs use the other Mac's Docker Desktop or OrbStack, and the ports containers publish come back.
- Copies on the other Mac live under `~/hivemux-swarm.noindex/`, so Spotlight there does not index them.
- If the scheduler is stuck or gone, commands run on this Mac as if swarm were not installed. `HIVEMUX_SWARM=0` keeps a single command here.
- The hook only answers "allow" when your permission rules allowed the original command; otherwise Claude Code asks as usual.

The full setup is in [hivemux swarm](/docs/extensions/swarm/), and [running Claude Code builds on another Mac](/guides/claude-code-builds-on-another-mac/) walks through it step by step.

## Quick checklist

| Symptom | Likely cause | Fix |
|---|---|---|
| `node` at several hundred % CPU | Test runner using every core, in several sessions | `--maxWorkers=50%`, run related tests only |
| Ports you do not recognise in `lsof` | Dev servers left running | `kill <PID>`, a line in `CLAUDE.md` |
| High memory with Docker idle | Docker VM holding memory | Lower the limit in Docker Desktop or OrbStack |
| `mds_stores` busy after installs | Spotlight indexing `node_modules` and worktrees | Search Privacy, or a `.noindex` folder |
| Memory Pressure yellow or red | Too much running at once for the Mac | Stagger heavy runs, or move them to another Mac |

## FAQ

### Is Claude Code itself using all my CPU?

Rarely. A Claude Code session mostly waits for the model's reply. The busy processes are usually the ones it started, such as node running tests, a compiler, a dev server or Docker, plus any MCP servers each session starts. Sort Activity Monitor by % CPU and look at what sits under the session's terminal.

### Why do the fans get loud when I run several Claude Code sessions?

Each session runs its own tests, builds and servers, and they overlap. Three sessions each starting a test suite that uses every core means three times the work at once. Limit test workers, stop servers you no longer need, or move the heavy commands to a Mac with room.

### Why is mds or mdworker using CPU after Claude installs dependencies?

Spotlight indexes every new file, and a fresh node_modules or build folder can hold tens of thousands. Add the code folder to System Settings › Spotlight › Search Privacy, or keep throwaway copies in a folder whose name ends in .noindex, which Spotlight skips.

### How do I find a dev server Claude left running?

Run `lsof -nP -iTCP -sTCP:LISTEN` to list every process listening on a TCP port, with its PID. Stop the one you no longer need with `kill <PID>`. If it does not exit, `kill -9 <PID>` ends it.

### Can Claude Code run tests on another Mac without me changing how I work?

Yes, with hivemux swarm. A Claude Code PreToolUse hook sends tests, builds, dev servers and Docker from projects you turn on to the Mac with the most room, and the output, exit code and localhost ports come back as if they ran locally.
