r/ClaudeCode • • 1d ago

Tips & Workflows My Claude Code agents shut down my Mac

Post image

The first time, I thought my Mac had died.

I started building my app in March. I think it was April when I had six Claude Code sessions running at once. Each one took a task from my backlog and worked on it. The sessions wrote the code for the iPhone and Android app. They did not coordinate with each other, and nobody told them how to share one computer. They booted phone simulators and the Android emulator, left them running and booted new ones. They saved test files everywhere. My Mac has 16 GB of memory, and they ate all of it. Then the computer switched itself off. I was honestly scared.

Later, temporary test files filled the disk three times. Each time, every session stopped. Once the files took 49 GB.

If you plan to run several agents on one computer, here is what I wish I had known at the start.

The rules came one by one. The ones I use now are:

  • a session takes a lock before it boots a simulator or the emulator;
  • only one simulator runs at a time, never two;
  • heavy builds wait in a queue;
  • every session closes what it started and deletes its temporary files.

My Mac stopped switching off, and my heart finally calmed down.

Then I had a different problem: too many chats to watch. Now one session is the coordinator. Think of it as my deputy. The other sessions talk to it, and I talk only to it. Usually that is the coordinator and three or four sessions. There is one device under a lock. The coordinator decides who gets it, and the queue follows task priority, not who asked first. The coordinator can keep work going through the night, and in the morning I read one report. That alone made development faster.

One thing did not change. Nothing goes into a release without me. I check the result myself before it ships.

Some things still go wrong. Sometimes a session writes down a decision I never made. My "not yet" once became "never". Yesterday one session checked all of those notes.

 If you're curious what came out of all this, the app is called ClariMeal:

App Store

Google Play

Has something like this happened to you when you ran several agents at once? What did you change after it?

0 Upvotes

17 comments sorted by

•

u/AutoModerator 1d 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.

1

u/Ok_Tea4891 1d ago

The lock-before-launching-a-simulator rule is the useful part. Since the disk filled three times, it may also be worth making each session write temp files into its own directory that gets cleaned when the session ends, and having the lock hold a simple limit on how many emulators run at once. That way a crashed session can't leave 49 GB behind or keep a simulator booted.

1

u/PreferenceBudget3127 1d ago

Thanks. The 49 GB were temp files the tests never deleted. The tests now have to clean up after themselves. A temp folder per session is a good extra layer, I'll add it. One simulator is my rule, but the script only shows the count. It doesn't block a second one yet.

1

u/amirfish 1d ago

Six sessions with no shared lock is the exact failure mode. Reasoning was never the limit, keeping them from fighting over your one Mac is. The lock-before-boot rule you landed on is the right instinct, I use the same idea for any shared resource across parallel agents, not just simulators. I built CCC around the next step of that: agents work a queue on their own, and the only thing that reaches you is a numbered question when one actually needs your call. Did the RAM problem ever show up in builds too, or just the simulators?

Free and open source: getccc.dev · GitHub

1

u/PreferenceBudget3127 1d ago

Builds too. Two sessions built at the same time and one build failed. Now heavy Gradle builds take one of two slots, and a third one waits.

1

u/amirfish 1d ago

Same pattern here. Heavy builds and shared resources are where parallel sessions actually collide, not the reasoning itself. I cap build-heavy sessions at two for that exact reason and let everything else run unlimited since it isn't fighting over CPU or a test runner. The other one that got me was the git index, one session staging mid-commit from a sibling. Are you slotting by resource type across the board or just for builds?

1

u/PreferenceBudget3127 1d ago

By resource type. Heavy Gradle builds get two slots. The simulator and the emulator each have a lock, and only one session at a time can run live checks. Docs and research tasks don't need a slot.

The git index got me too. One session ran a plain git commit and took another session's staged work into it, 78 files in total. Now every task runs in its own git worktree, and a commit names its own files.

1

u/AryanThakor 1d ago

I'd also cap booted simulators, not just lock them. have the lock script check xcrun simctl list devices booted and refuse past 2, and run simctl shutdown all when no session holds the lock. agents almost never shut down the ones they start

1

u/PreferenceBudget3127 1d ago

My cap is one, never two. But you're right, the lock counts sessions, not simulators. Once a single session kept three simulators up and swap went to 89%. Making the lock refuse a second boot is my next fix.

1

u/radim11 1d ago

49 GB of temp files would’ve taken me a while to figure out too! I like the simulator lock. The bit I’d move to the coordinator is cleanup. Give each session its own temp dir, then the coordinator can remove it even if the session crashes halfway through a build. Do you have a way to reclaim the simulator lock if the session holding it dies?

1

u/PreferenceBudget3127 1d ago

Not automatically yet. The lock keeps the session's process ID. If that process is gone, the status check marks the lock as stale, and I clear it myself. Moving cleanup to the coordinator makes sense. It already checks the disk every day.

1

u/Mountain_Fudge3980 1d ago

The weak spot in that setup is cleanup that only runs when a session exits politely. If a session gets killed or just stalls, nothing runs, the simulator stays booted and the lock stays taken.

Two changes that make it hold up:

  • Do the cleanup at the moment a session takes the device lock, not only when it finishes. Whoever holds the lock is by definition the only one allowed to have a simulator up, so anything still booted at that point is orphaned and safe to kill: xcrun simctl shutdown all, xcrun simctl delete unavailable, and adb emu kill for the Android emulator. All of these are harmless when nothing is running, so you don't need to track who started what. A Claude Code SessionEnd hook can run the same script as a second line of defence.
  • Write the holder's PID into the lock and have a waiting session check kill -0 <pid> first. If that process is gone, the lock is stale and can be taken. macOS doesn't ship flock, so mkdir /tmp/sim.lock is the cheap atomic version.

On the disk side, besides a per-session TMPDIR, keep an eye on ~/Library/Developer/Xcode/DerivedData. Xcode keeps a separate folder per project path, so several sessions building the same app from different worktrees each get their own copy, and it lives outside the repo where nobody looks.

1

u/PreferenceBudget3127 1d ago

Thanks, this is useful. The PID check and the mkdir guard I already have, but stale locks I clear by hand. Cleanup at the moment a session takes the lock is what I'm missing. I'd only kill what I know is orphaned, so first I need to track who booted what. Good point about DerivedData. Every task here has its own worktree, so I'll check how big it got.

1

u/TouristInternal7308 1d ago

the lock helps until the agent holding it dies. id kill the worker mid-test on purpose and see if the coordinator can reclaim the simulator without touching anything it didn’t start. if cleanup only happens on a polite exit, that’s the bit id fix first.

1

u/PreferenceBudget3127 1d ago

Fair point. Right now a session shuts down its simulator when it finishes. If it dies first, the lock waits for me. I'll kill one mid-test on purpose and see what stays behind.