Accidentally created my first fork bomb with Claude Code
TL;DR Highlight
A SessionStart hook recursively launched claude -p overnight, creating a fork bomb that froze the machine.
Who Should Read
Developers building Claude Code hooks and skills who worry about infinite recursion and runaway API bills
Core Mechanics
- A SessionStart hook became a fork bomb
- The hook spawned 2 background CC instances with claude -p.
- Each instance ran the normal startup sequence, triggering the hook again.
- Growth went 1→2→4→8, i.e. 2^N.
- Leaving it overnight bricked the machine
- The terminal slowed at 2AM, and the author went to bed.
- At 11AM the mouse, keyboard and trackpad were dead and the chassis was hot.
- Activity Monitor showed hundreds of CC instances.
- Killing processes couldn't keep up
- Instances spawned faster than they could be killed in Activity Monitor.
- A forced restart via the power button was needed.
- Only after removing the hook from ~/.claude/settings.json did a single instance start.
- The bill rose only $600
- The Usage page showed a $600 increase on the company API account.
- The author says each instance's heavy memory use (Bun → React → TUI) locked the computer first, which limited the spending.
- The whole month's API bill was $3800.
- Tools built during the month
- /yadumb (log mistakes), /memento (conversation logs), /yablind (subagent handles screenshots to save context), /adhd (to-do roundup), /money (save project state).
- PreToolUse/PostToolUse hooks log Bash commands to a daily append-only jsonl.
Community Reactions
- A question about the recursion's purpose
- One commenter asked what the hook intended by spawning two more CC instances.
- The article doesn't detail the purpose of the spawned instances.
- Python multiprocessing causes the same accident, per a commenter
- A commenter said that on Windows, without an if __name__ == "__main__" guard, a worker pool reloads the module in every child.
- They explained Windows has no fork(), so children keep spawning children.
- An opinion on how scary fast bad code is
- One commenter said it's scary that even badly running code is faster than a human.
- They noted the author was lucky it hogged so much RAM.
- Interest in the /adhd skill internals
- A commenter found the morning to-do skill useful and wanted to know how it works.
How to Apply
- Find any hook that calls claude
- Open ~/.claude/settings.json now and check whether hooks like SessionStart contain claude -p.
- If so, add an environment-variable recursion guard first.
- Watch instance counts when testing automation
- When testing a new hook, filter Activity Monitor by claude and keep a hand near the power button.
- Run it once and confirm only 1 process exists before leaving it unattended.
- Set API spend limits and alerts
- On a company API account, configure spend limits and alerts on the Usage page.
- After overnight automation, check usage first thing in the morning.
- Log executions with Pre/PostToolUse
- Append Bash command contents and per-tool_use_id completion status to a daily jsonl.
- This lets you trace which commands ran when something misbehaves.
Try It
# Paste into Claude Code terminal or Claude (checklist prompt to prevent the incident in the article)
Below is my ~/.claude/settings.json hook config.
{{settings.json contents}}
1. Find any place where a hook re-runs Claude Code, e.g. with claude -p.
2. Judge whether that call can re-trigger the same hook and cause recursion (a fork bomb).
3. Show a fix with an environment-variable guard (e.g. the hook exits immediately if it's already set).
4. Give me a safe procedure to test it just once.Terminology
Related Papers
Frostbite: A new CPU architecture discovered, designed and verified by AI
AI agents designed a CPU from scratch, claiming 4.59x perf/W over a traditional core
Restricting AI agents in mobile operating systems platforms from capturing data
Signal now blocks OS-level AI agents from reading its screen on iOS 27 and Android
Actions Speak Louder than Words: Stateful Privacy Sniffing of LLM Agents via Behavioral Covert Channels in Web Interactions
Agents' link choices alone let attackers rebuild user queries at F1 0.89; SOR cuts it to 0.39.
Tracking and Limiting Unsupported Claim Propagation in Multi-Agent LLM Systems: A Provenance-Aware Framework
Passing claims with source, evidence and history kept equivalence at 5 agent stages at 96% versus 31%.
LLM assisted reverse engineering
Pointing an agent at binaries with skills and MD notes made years-long hacks feasible
Metrics-in-the-Loop: Complexity Feedback Reshapes Agent-Written Code
Injecting per-turn complexity reports into coding agents cut code erosion without changing correctness
Why is Gemini 4 Carbon taking so long?
Carbon took nearly an hour on bug fixes that Astra and Opus finished in minutes, mostly from extra unrequested work.
Weight-Space Programming builds neural networks like a 1990s researcher
LLM hand-wrote MNIST weights to 91.3%, using 1990s-style techniques