When Claude Code CLI Uses 100% CPU β Causes and Solutions
Discovery
While working the previous day, Claude Code suddenly froze, so I forcibly terminated it. The next morning, my MacBook was hotter than usual. I opened Activity Monitor and found that the Claude Code v2.1.27 process was consuming 100% CPU.
Path: ~/.local/share/claude/versions/2.1.27
Command: claude --continue
CPU: 99.5%
Memory: ~600MB
Uptime: Approx. 8 hoursThe development server process, which Claude Code had previously executed as a Skill, had not terminated and remained as a zombie, eating up the CPU.
I tried pkill claude, but it didn't die, so I had to force kill it with kill -9 <PID>.
Eventually, I resolved it by cleaning up session files + downgrading to the stable version with claude install 2.1.22. No CPU usage recurrence since then.
Cause
This is a known bug reported in Claude Code CLI v2.1.27. There are multiple issues registered on GitHub with the same symptoms.
1. Bloated Session Files (Most Likely)
If the .jsonl session files accumulated under ~/.claude/projects/ get too large, parsing enters an infinite CPU loop.
claude --continue is directly affected by this problem because it loads the previous session file.
- Confirmed reproduction in v2.1.27, while v2.1.25 works normally.
- Immediately resolved upon deleting session files.
Reference: #22041 β CLI hangs at 99% CPU on startup with large session .jsonl files
2. Hooks + Parallel Instance Conflict
Since v2.1.23, if multiple Claude Code instances are run with hooks enabled, a 100% CPU hang occurs.
Reference: #22172 β v2.1.23+ causes 100% CPU hang with multiple parallel instances and hooks
3. Busy-wait in Idle State
setImmediate() calls are repeatedly scheduled without yielding, consuming CPU even when doing no work.
Reference: #17148 β Claude Code consumes 100%+ CPU when idle in terminal
Solutions
Step 1: Find Zombie Processes
ps aux | grep claude | grep -v grepCheck the claude related processes and PID in the output.
Step 2: Terminate Process
pkill claude does not work on this zombie process. You must specify the PID to terminate it.
# pkill doesn't work
pkill claude # β No response
# Force kill by specifying PID directly
kill -9 <PID>Step 3: Clean Up Bloated Session Files
# Check session file size
du -sh ~/.claude/projects/*/
# Delete problematic session files
rm ~/.claude/projects/<project-path>/*.jsonlIf you delete the session file, you cannot continue the previous conversation with claude --continue. Back up before deleting if necessary.
Step 4: Version Downgrade (for hooks users)
If you are using hooks, downgrade to a previous stable version.
You can install a specific version using the claude install command.
# Downgrade to specific version (without v prefix)
claude install 2.1.22
# Verify
claude --versionCaution: Running
claude install stableorclaude updatewill update it back to the latest stable version.
Prevention
If using v2.1.23 or higher:
| Method | Description |
|---|---|
| Periodically clean session files | Clean up if .jsonl files under ~/.claude/projects/ exceed 10MB |
| Habit of checking termination | After quitting claude, check if the process is actually dead with ps aux | grep claude |
Avoid spamming --continue |
As the session gets longer, .jsonl becomes bloated. Starting a new session is safer |
| Caution with hooks + parallel execution | Do not run multiple instances simultaneously while hooks are active |
| Track updates | Check for relevant fixes in anthropics/claude-code Issues |
/clearonly initializes the conversation context; it does not delete the.jsonlfile itself. It has no direct effect on preventing session file bloat.
Related Issues Collection
- #22041 β CLI hangs at 99% CPU on startup with large session .jsonl files
- #22172 β v2.1.23+ causes 100% CPU hang with parallel instances and hooks
- #17148 β Claude Code consumes 100%+ CPU when idle in terminal
- #11122 β Multiple Claude CLI processes accumulate causing high CPU usage
- #11377 β Memory leak: 23GB RAM and 143% CPU after 14 hours
Ask AI Immediately
Copy and paste the prompt below suitable for your situation to an AI (Claude, ChatGPT, etc.), and it will diagnose and clean it up for you.
When Claude Code froze and you just closed the terminal
I was using Claude Code and it froze, so I force-closed the terminal.
There might be a zombie process left in the background, so please check and clean it up.
1. Check for remaining processes with `ps aux | grep claude | grep -v grep`
2. If found, force kill with `kill -9 <PID>` (pkill doesn't work)
3. Check for bloated session files with `du -sh ~/.claude/projects/*/` β Delete .jsonl over 10MB
Show the execution results for each step and explain what you did.When the MacBook gets hotter than usual
My MacBook is hotter than usual. A Claude Code zombie process might be consuming the CPU.
Please diagnose and resolve it.
1. Check for zombie processes with `ps aux | grep claude | grep -v grep`
2. If found, force kill with `kill -9 <PID>` (pkill doesn't work)
3. Check for bloated session files with `du -sh ~/.claude/projects/*/` β Delete .jsonl over 10MB
4. If using hooks, consider downgrading to a stable version with `claude install 2.1.22`
Show the execution results for each step and explain what you did.I am currently downgraded to claude install 2.1.22. I plan to update when a version with this issue fixed is released.