Claude Code Using High CPU or Memory: How to Find the Cause

Claude Code Using High CPU or Memory: How to Find the Cause

If you are seeing Claude Code high memory usage or a fan that won’t stop spinning, the usual cause is a session that has grown too big: a long conversation, large file or command output, a background command that is still running, or an add-on that loads at startup. The fastest fix is to exit, start again with claude --continue so you keep the conversation, and see if the numbers drop.

If memory is already high the moment Claude Code starts, restart it with claude --safe-mode. That turns off plugins, MCP servers, hooks and your other customizations, so you can tell whether one of them is the problem. If nothing helps, the hidden /heapdump command writes a memory report you can study or attach to a bug report.

Below, we measure a real session step by step with ps, show what made memory grow and what brought it back down, and walk through every fix from Anthropic’s troubleshooting page.

Browse all our Claude Code tutorials for more fixes and how-tos.

Tested with Claude Code v2.1.330 on macOS on November 24, 2026, in a throwaway demo project. Every screenshot shows a real run. We tested on macOS; the Windows and Linux steps follow Anthropic’s official instructions and standard system tools.

Quick Summary

What you seeLikely causeFix
Memory keeps climbing over a long sessionBig conversation history and tool outputExit, then claude --continue; run /compact between tasks
High memory right after startupA plugin, MCP server or hookStart with claude --safe-mode and compare
CPU busy while Claude is doing nothingA background command still runningCheck /tasks and stop what you don’t need
Slow and heavy after reading a big file or logHuge output filling the contextRead files in smaller pieces or use a subagent
Slow searches in a big repoBuild folders being scannedAdd build directories to .gitignore
Critical memory usage warningHeap memory passed 2.5GBRestart and resume, then /heapdump if it returns

Why Claude Code Uses CPU and Memory

Claude Code is a program that runs on your own computer. It keeps your whole conversation in memory, reads files, runs shell commands and draws the terminal screen. Each of those costs some memory and CPU, and they add up the longer you work.

Anthropic’s troubleshooting page says Claude Code may use significant resources when it processes large codebases. It also sets one hard line: if a session’s heap memory passes 2.5GB, a critical memory usage warning appears.

Most of the time, though, high usage is not a bug. It is a sign that one session has done too much, or that something you added is heavier than you think. The trick is to measure before you guess.

Decision diagram for Claude Code high CPU or memory: match the symptom, such as memory growing over a long session or high usage at startup, to the fix on the right
Match the symptom on the left to the first fix to try on the right.

Step 1: Measure Claude Code Memory and CPU

You need a number before you can fix anything. The simplest way is to read the memory (RSS) and CPU of the claude process with ps, which ships with macOS and Linux.

You can do it without leaving your session. Type ! at the start of the prompt to run a shell command directly, and use $PPID, which points at the Claude Code process that started the shell:

!ps -o pid,rss,%cpu,etime,comm -p $PPID

The RSS column is in kilobytes, so 345920 means about 338 MB. In our test, a fresh, idle session sat at 338 MB with under 1% CPU after 45 seconds.

Claude Code session running ps from bash mode, showing the claude process at 345920 KB RSS and 0.8 percent CPU after 45 seconds
Our baseline: a fresh session used about 338 MB and almost no CPU.

In our session, Claude also read the ps output and explained it in a short reply. That is handy, but it does use a few tokens each time.

Other ways to check

  • On macOS, open Activity Monitor and search for claude, or run top -o mem in a terminal to sort every process by memory.
  • On Linux, run top or ps aux | grep claude.
  • On Windows, open Task Manager and look for the Claude Code process.

Write down the number with the time. One reading tells you little; a few readings over several minutes tell you whether memory is steady or still climbing.

Step 2: Find What Makes Claude Code Memory Grow

Next, we gave Claude a small job on a 478 KB log file with 6,000 lines. We asked it to run cat logs/server.log and report the last request ID.

Claude chose to read only the end of the file instead of dumping the whole log into the chat. Memory still went up, from 338 MB to 364 MB, because the conversation and the tool call both added to it.

Claude Code reading the end of a 6,000-line log with tail instead of cat, then ps showing memory at 372224 KB
One small task added about 26 MB. Claude read only the end of the log, which kept the output small.

That gives you the first rule of thumb. Every file you read and every long command output stays in the conversation, so big outputs are the quickest way to grow a session.

Background commands keep running

Then we asked Claude to start sleep 300 as a background task. The footer changed to show 1 shell, and ps found two new child processes under Claude Code: a shell wrapper and the sleep command itself.

ps output listing a background sleep 300 process started by Claude Code, with the footer showing 1 shell still open
A background command shows up as its own process, and the footer counts open shells.

A sleep uses almost nothing. A dev server, test watcher or build in the background can use far more, and it keeps going while Claude looks idle. If your CPU stays busy while nothing is happening on screen, check the footer and run /tasks to see what is still running.

Step 3: Free Memory With Restart, Resume and /compact

Anthropic lists two ways to free memory. The first is to restart Claude Code and run claude --continue, which resumes the conversation in a fresh process. The second is /compact, which the docs say also frees memory outside fullscreen rendering.

We tried both, and the results were not what we expected. Right after /compact keep only the last request id, memory read 467 MB, higher than before.

Claude Code after /compact, with ps showing the claude process at 467120 KB RSS
Right after /compact, our session used more memory, not less.

Compacting has to read the full conversation and build a summary, so it does work of its own. In our short test, the drop did not show up in ps right away. Your result may differ in a long, heavy session, which is where the docs say it helps.

Restarting worked clearly. We exited and resumed the same conversation, and the new process started at 351 MB, close to a fresh session.

ps output after restarting and resuming the same Claude Code conversation, showing 350864 KB RSS
After a restart and resume, the same conversation ran in a new process at about 351 MB.
Diagram of measured Claude Code memory: 338 MB idle, 364 MB after a log task, 467 MB after compact, 351 MB after restart and resume
Our four readings side by side. Restart plus resume gave the memory back.

When a session feels heavy, a restart with –continue is the cheapest fix: you keep the conversation and get a fresh process.

If you are unsure which reset fits your situation, our guide to clear vs compact compares all three. To pick an older session instead of the latest one, use claude --resume; our fix for session load errors helps if that fails.

Step 4: Rule Out Plugins and MCP Servers With Safe Mode

If memory or CPU is high from the first second, the session’s history is not the problem. Something that loads at startup is. The docs suggest restarting with claude --safe-mode to check whether a plugin, MCP server or hook is the source.

Safe mode shows a yellow banner listing what it turned off: CLAUDE.md, skills, plugins, hooks, MCP, agents and more. Compare its memory reading with a normal start in the same folder.

Claude Code started with --safe-mode, showing the safe mode banner and ps reporting 362576 KB RSS
Safe mode turns off all customizations. Our test folder had none, so it used about the same memory, 354 MB.

Our demo folder had no add-ons, so safe mode used about the same memory as a normal start. In your own setup, a big drop in safe mode points straight at an add-on.

Narrow it down

  1. Run /mcp in a normal session to list your MCP servers and their status.
  2. Turn servers off one at a time; our guide to disabling MCP servers shows how.
  3. Restart and measure after each change until the number drops.
  4. Follow the same steps for plugins and hooks using Anthropic’s configuration debugging guide.

Step 5: Read a Memory Report With /heapdump

When memory stays high after all of that, Anthropic documents a hidden command. Type /heapdump in full, because it does not appear in the command menu.

It writes two files to your Desktop: a heap snapshot named <session-id>.heapsnapshot and a breakdown named <session-id>-diagnostics.json. On Linux without a Desktop folder, they go to your home directory. It also prints a short summary in the chat.

Claude Code /heapdump output listing the heapsnapshot and diagnostics files and a memory summary of JS heap, strings and outside-heap memory
The /heapdump summary splits memory into the JS heap and memory outside it.

Our summary said most memory was in the JS heap, and it flagged a high memory growth rate of 2127.9 MB per hour. That rate came from a session only about five minutes old that had just started up and compacted, so we read it as a hint to keep watching, not proof of a leak.

The summary also reported 0.16 GB of RSS, while ps had shown 467 MB a few minutes before. The two tools count memory at different moments and in different ways, so compare a tool with itself over time rather than mixing them.

What to do with the two files

FileWhat it holdsSafe to share?
-diagnostics.jsonThe statistics behind the summary, with no conversation content or credentialsYes, attach it to a GitHub issue
.heapsnapshotEvery string in the process, including your full conversation and credentialsNo, keep it private

If the summary says most memory is JS heap, you can open the snapshot in Chrome DevTools under Memory, then Load, and sort by retained size. If it says most memory is native, the snapshot can’t show it, so include the summary’s leak indicators in your report instead. Delete both files when you are done, since the snapshot is sensitive.

More Fixes From the Official Docs

These steps come straight from Anthropic’s troubleshooting page. We did not need them in our small demo, but they matter in real projects.

  • Consider adding large build directories to your .gitignore file, as the docs suggest for big codebases.
  • Close and restart Claude Code between major tasks instead of running one session all day.
  • Ask Claude to read a large file in pieces, such as a line range or one function, rather than the whole thing.
  • Move large-file work to a subagent so it runs in a separate context window; our subagent tips explain when that pays off.
  • Run /doctor for an automated check of your install, settings, extensions and context usage.

If the session freezes instead of just slowing down, press Ctrl+C to cancel the current operation, then restart and run claude --resume. Our guide to Claude Code crashing or freezing covers that case in depth. For a context that keeps refilling after compaction, see our fix for autocompact thrashing.

On Windows with WSL

Anthropic notes that working across file systems on WSL can slow searches down. Keep your project on the Linux file system under /home/ rather than /mnt/c/, or run Claude Code natively on Windows.

Try It Yourself

Practice on a throwaway folder, not a real project. Create a few files and a big log, start Claude Code there, and take a reading with !ps -o rss,%cpu -p $PPID. Then paste this prompt:

Read logs/server.log in small pieces and tell me how many ERROR lines it has.
Keep your output short. Then start "sleep 120" as a background task.

Take a second reading, check /tasks, then exit and run claude --continue. Take a third reading and compare all three numbers.

Common Mistakes

  • Judging from one reading. Memory rises after every task, so look for steady climbing while Claude is idle.
  • Treating CPU at startup as a problem. A new process works hard for a few seconds, then settles.
  • Asking Claude to print huge files or full logs into the chat. Ask for counts, summaries or line ranges instead.
  • Forgetting background shells. A watcher or dev server keeps running until you stop it.
  • Sharing the .heapsnapshot file. It holds your full conversation and credentials; share only the diagnostics file.
  • Comparing numbers from different tools. Activity Monitor, ps and /heapdump can disagree.

Pro Tips

  • Start a new session for each big task and use claude --continue when you need the old context back.
  • Keep MCP servers you rarely use turned off, and turn them on only for the task that needs them.
  • If Claude Code also feels slow to answer, our guide to a slow Claude Code covers startup time and response speed.
  • Run /doctor after big setup changes so you catch problems early.
  • Our list of common Claude Code errors covers the error messages you might see along the way.

Claude Code High Memory Usage Cheat Sheet

Cheat sheet of Claude Code commands to measure and fix high CPU or memory: ps, top, /context, /compact, /clear, claude --continue, --safe-mode, /mcp, /tasks, /heapdump and /doctor
The commands from this guide in one place.

Frequently Asked Questions

How much memory does Claude Code normally use?

In our test on macOS, a fresh session used about 338 MB, and a short session grew to a few hundred MB. Anthropic shows a critical warning once heap memory passes 2.5GB.

Why is Claude Code using so much CPU?

Usually because it is working: starting up, running a command or processing output. If CPU stays high while it is idle, look for background commands with /tasks and test add-ons with claude --safe-mode.

Does /compact reduce memory?

The docs say it frees memory outside fullscreen rendering. In our short test, memory read higher right after compacting, while a restart with claude --continue brought it back down at once.

Will I lose my conversation if I restart?

No. Run claude --continue in the same folder to resume the latest conversation, or claude --resume to pick from a list.

Is it safe to share the /heapdump files?

Share only the -diagnostics.json file. The .heapsnapshot contains your whole conversation and credentials, so keep it private and delete it when you are done. Our Claude overview covers the rest of the product.

Conclusion

Claude Code high memory usage almost always traces back to something you can measure: a long session, big tool output, a background command or an add-on that loads at startup. Take a reading with ps, restart with claude --continue when a session gets heavy, use claude --safe-mode to rule out plugins and MCP servers, and save /heapdump for the cases that survive all of that, sharing only the diagnostics file when you report it.

Newsletter

New AI tools in your inbox

The best new tools and the AI news that matters, in one short email. Unsubscribe any time.

Free · No spam · Unsubscribe any time

✓ Looks like you’re subscribed

Loading Google’s sign-up form…

Looks like you’re already subscribed

Thanks for reading! New AI tools and the AI news that matters will land in your inbox.

Not subscribed yet? Refresh the page to load the sign-up form.

The sign-up form couldn’t load. If you use an ad or content blocker, allow news.google.com and reload the page.

Free instant check before you pay. Takes a few seconds.

Scroll to Top