
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 see | Likely cause | Fix |
|---|---|---|
| Memory keeps climbing over a long session | Big conversation history and tool output | Exit, then claude --continue; run /compact between tasks |
| High memory right after startup | A plugin, MCP server or hook | Start with claude --safe-mode and compare |
| CPU busy while Claude is doing nothing | A background command still running | Check /tasks and stop what you don’t need |
| Slow and heavy after reading a big file or log | Huge output filling the context | Read files in smaller pieces or use a subagent |
| Slow searches in a big repo | Build folders being scanned | Add build directories to .gitignore |
| Critical memory usage warning | Heap memory passed 2.5GB | Restart 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.

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 $PPIDThe 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.

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 runtop -o memin a terminal to sort every process by memory. - On Linux, run
toporps 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.

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.

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.

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.


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.

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
- Run
/mcpin a normal session to list your MCP servers and their status. - Turn servers off one at a time; our guide to disabling MCP servers shows how.
- Restart and measure after each change until the number drops.
- 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.

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
| File | What it holds | Safe to share? |
|---|---|---|
-diagnostics.json | The statistics behind the summary, with no conversation content or credentials | Yes, attach it to a GitHub issue |
.heapsnapshot | Every string in the process, including your full conversation and credentials | No, 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
.gitignorefile, 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
/doctorfor 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
.heapsnapshotfile. It holds your full conversation and credentials; share only the diagnostics file. - Comparing numbers from different tools. Activity Monitor,
psand/heapdumpcan disagree.
Pro Tips
- Start a new session for each big task and use
claude --continuewhen 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
/doctorafter 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

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.


