Fork bomb on startup causing system freeze
⚠️ Claude created that issue by itself from the informations gathered in the system. I (human) can add more details if needed.
Description
The Claude CLI spawns an unbounded number of processes on startup, causing a fork bomb that freezes the entire system and requires a hard reboot.
Environment
- Multiple versions of Claude (npm and native). Tried this for multiple months simply giving up.
- OS: macOS 24.6.0 (Darwin)
- Shell: zsh
- Scope: Happens in all directories/repos, not specific to any particular project
- Duration: Has been happening since first using Claude CLI
Severity
After each trivial prompt (like "hello") browser tabs were crashing. More trivial prompts caused all browsers, terminals, npm apps to simply stop responding. 3-4 prompts caused complete system freeze requiring hard reboot.
Workaround
Created a wrapper script that limits process spawning:
#!/usr/bin/env bash
REAL="$HOME/.local/share/claude/versions/current"
# Fall back to searching PATH (skipping this script)
if [[ ! -x "$REAL" ]]; then
IFS=':' read -r -a dirs <<< "$PATH"
for d in "${dirs[@]}"; do
cand="${d:-./}/claude"
if [[ "$cand" != "$0" && -x "$cand" && ! -d "$cand" ]]; then
REAL="$cand"
break
fi
done
fi
[[ -z "$REAL" ]] && { echo "Error: claude not found" >&2; exit 127; }
# Cap max child processes — prevents the fork bomb from taking down the system
ulimit -u "${CLAUDE_CODE_MAXPROC:-1000}" 2>/dev/null || true
"$REAL" "$@"
rc=$?
# Fix bracketed paste mode that claude sometimes leaves enabled
printf '\e[?2004l'
exit $rc
Increasing ulimit -u from 1000 to higher values prevents the system crash and allows Claude CLI to function.
➜ ulimit -uH
9000
➜ ulimit -u
6000
Expected Behavior
Claude CLI should not spawn unlimited processes on startup.
This issue has 4 comments on GitHub. Read the full discussion on GitHub ↗