Yesterday at 2:37 PM, macOS showed "Your system has run out of application memory" on my Mac. I run Claude Code all day, and I also run a guard that watches for runaway processes. The guard checked every minute during the whole incident. It stopped nine small leftover processes. It never touched the one that caused the problem.
Between 2:25 and 2:36 PM, a single node helper running under Claude grew from about 10 GB to 268 GB of memory footprint. Swap reached 76 GB.
Why the guard missed it
The guard's rules were written around a real fear: killing an agent while you are using it. So the rule was simple. If a process belongs to a live agent session, leave it alone. That protects a Claude or Codex session that is working hard on a big build.
The same rule also protects a process that is eating the machine. A node helper is a child of the agent, so it inherited the agent's immunity. The guard was doing exactly what it was told to do. The rule was wrong, not the code.
What we changed
Now, when macOS reports critical memory pressure and one process holds at least half of the machine's RAM (never less than 16 GB), the guard stops that process, even under a live agent session. It sends SIGTERM first. If the same process is still running after 3 seconds, it sends SIGKILL.
The check is one pure function:
const RUNAWAY_MIN_MB = 16 * 1024;
const RUNAWAY_RAM_SHARE = 0.5;
function findMemoryRunaways(procs, footprints, { level, ramMB } = {}) {
if (level !== 'critical' || !ramMB) return [];
const fp = footprints || new Map();
const limitMB = Math.max(RUNAWAY_MIN_MB, ramMB * RUNAWAY_RAM_SHARE);
return procs
.filter((p) => {
const mb = fp.get(p.pid);
if (!(mb >= limitMB) || p.pid < 100) return false;
// ...then the spared cases below: system paths, Jamf, VMs, app executables
return true;
})
// (excerpt, trimmed)
}
The real function has more conditions in that filter, and those matter as much as the threshold. It never stops system processes, Jamf, an app's own executable, or browser helpers. It also spares virtual machine and local model runners such as qemu, ollama and llama-server, plus databases like postgres and redis. Runtimes (node, python, bun, deno, ruby, java) count wherever they run.
One bug showed up while testing. App paths can contain spaces, as in "Google Chrome.app", and my first version missed them. The fix reads the executable path until a space is followed by an argument that starts with a slash or a dash. The new table test includes a path with a space so it stays fixed.
Check this on your own machine
- Look at your own guard or cleanup script. Does it have an exemption for processes owned by an agent, an editor or a terminal? Ask what happens when the exempt process is the one that leaks.
- Look at swap during a heavy session with
sysctl vm.swapusage. Swap in the tens of gigabytes means you are already in trouble, even if free memory looks fine. - Find the biggest process by footprint, not resident size:
top -l 1 -o mem -n 5. A leaking helper shows up there before the system warns you.
An exemption that protects your work should have a ceiling. A process using half the machine is not doing your work anymore, whoever started it.
The guard is open source. The code for this change, the incident fixture and the tests are in the repo: https://github.com/IgorGanapolsky/mac-yolo-safeguards