r/ClaudeCode • • 18h ago

Tips & Workflows Claude Code froze my laptop running a Rust audit tool

I had Claude doing a security audit on one of my Rust projects. It ran cargo-geiger, which forked about 6,000 processes and used up my RAM and swap in two minutes. The screen froze and I had to hard reset.

systemd-oomd was turned off on my distro. Here's what I set up after:

  • turned systemd-oomd on
  • a memory and process cap on the slice my terminals run in
  • cargo-geiger swapped for a script that exits
  • a hook that blocks fork bombs, pkill -f and a few other commands when Claude runs them

The hook blocked Claude today when it ran pkill -f. That would have killed its session lol.

If your screen freezes and you can't tell why, run journalctl -b -1 -k and look for oom-kill.

0 Upvotes

7 comments sorted by

•

u/AutoModerator 18h ago

Hey! Thanks for posting to r/ClaudeCode

While participating in this thread, please follow our community rules. Keep discussions constructive. Attack the idea, not the person.

For help, project discussions, tips, and general chat, join the ClaudeCode Discord.

I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.

2

u/Naive-Tip7231 17h ago

Good writeup. A few guards that pair well with the slice cap:

  • Give heavy commands their own scope with its own cap. A runaway command then hits that cap first: systemd-run --user --scope -p MemoryMax=4G -p TasksMax=500 cargo geiger
  • A PreToolUse hook can make that automatic. Match commands like cargo, npm test or docker build. Block them unless they come wrapped.
  • earlyoom is a lighter option if systemd-oomd seems too aggressive on your distro.
  • For normal Rust builds, set CARGO_BUILD_JOBS to a small number. It caps parallel rustc jobs.

The journalctl tip is the one most people miss. Those oom-kill lines save a lot of guessing.

1

u/Zito_Kadaken 9h ago

Nicely laid out. I like the idea of giving heavy commands their own scope. Thanks.

1

u/Late_Wave_5600 14h ago

the hook saving Claude from killing its own session is a great detail lol
what does it match on, the command text ? I'd expect it to miss the same thing wrapped in a script

1

u/Zito_Kadaken 9h ago

I had it match the command text. It catches bash -c, but a script with pkill -f inside would get past.

1

u/Late_Wave_5600 4h ago

yeah that's the gap, matching the text will always lose to a script checking which process it targets would hold better than the command that asks for it