r/ClaudeCode • u/PreferenceBudget3127 • 1d ago
Tips & Workflows My Claude Code agents shut down my Mac
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:
Has something like this happened to you when you ran several agents at once? What did you change after it?
•
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/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/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/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/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:
xcrun simctl shutdown all,xcrun simctl delete unavailable, andadb emu killfor 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.kill -0 <pid>first. If that process is gone, the lock is stale and can be taken. macOS doesn't shipflock, somkdir /tmp/sim.lockis 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/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.