Giving every coding agent its own iOS simulator
I run several coding agents on one Mac, all working on iOS apps.
They build, install, launch, take screenshots and run UI tests, and every one of those steps needs a simulator.
Left alone, each agent picks one the same way a person would: booted, -destination 'name=iPhone 18 Pro', or the first line of xcrun simctl list.
So they all pick the same one.
What follows is random failure. One agent installs its build while another one runs tests on the same device. A test run dies because a different agent just relaunched its app. A screenshot shows the wrong app. None of it reproduces, and the agent then spends ten minutes “fixing” a flaky test that was never flaky.
The fix is boring and old: treat a simulator like a lock. An agent takes one, keeps it to itself, and gives it back when it is done. That is what simctlhouse does, and this post is about the parts that turned out harder than “keep a list of who has what”.
What it looks like
The common case is one command that needs a simulator from start to finish, such as a test run:
simctlhouse run --holder "fix login test" -- xcodebuild test -scheme App
run leases a free iPhone, boots it, adds -destination id=<UDID> to xcodebuild, and hands the device back to the pool when the command exits.
When several steps must happen on the same device, the agent holds it across them:
UDID=$(simctlhouse acquire --holder "check onboarding screen")
xcrun simctl install "$UDID" build/App.app
xcrun simctl launch "$UDID" com.example.app
xcrun simctl io "$UDID" screenshot onboarding.png
simctlhouse release "$UDID"
A released device goes back to the pool still booted, so the next agent gets it in about two seconds instead of waiting for a boot. Agents learn all of this from an Agent Skill that ships with the binary, so I did not change a single prompt or project.
The pool has to live where xcodebuild can see it
The obvious design is to keep pool devices away from mine, in a separate device set with simctl --set <path>.
It does not work: xcodebuild -showdestinations and -destination id=<UDID> cannot see devices in a custom set.
So pool devices are plain simctl create simulators in the default set, right next to my own, and visible in Xcode.
That moves the safety guarantee somewhere else. simctlhouse keeps a registry of the UDIDs it created and never touches anything outside it. My own simulators are off limits by construction, whatever they are called.
One JSON file instead of a service
The whole pool is ~/.simctlhouse/state.json.
Every command takes an exclusive flock on a lock file, reads the state, changes it, and writes it back through a temp file and an atomic rename.
I considered SQLite and a server process, and both were more machinery than a few hundred records need.
flock has one property that makes it a great fit: the kernel releases it when the process dies.
A crashed or killed agent can never wedge the pool.
The lock is held for milliseconds. Creating, booting and shutting down a simulator takes seconds, so that work happens outside the lock while the device is marked as busy, with a claim that names the process doing it. An early version found in-flight work by device name, and on a heavily loaded machine a slow erase could put a device that someone had leased in the meantime back into the pool, and it got leased twice. Claims fixed that: the transaction that finishes the work only applies if its own claim is still there.
Leases that cannot leak
Agents forget to release things.
A lease from acquire lasts 30 minutes unless renewed, and when it runs out, the device is reclaimed.
The interesting part is what reclaim means. Handing the same device to the next agent would be a trap: the forgetful agent may come back and keep driving a simulator that now belongs to someone else. So an expired device is deleted and created again, under a new name and with a new UDID. A stale agent that returns fails loudly with exit code 3, instead of silently breaking another agent’s test run.
Tie the lease to a process
Even with expiry, the lease history showed agents forgetting to renew and losing their device in the middle of a long test run.
run fixes this by binding the lease to its own process instead of a timer.
The lease records the pid and start time of the run process, and lives exactly as long as it does.
A wrapper that calls renew on a timer looked simpler, and it breaks at the worst moment.
Agent harnesses kill commands with SIGKILL on a timeout, and nothing in a killed process gets to clean up.
With the owner recorded in the lease, it does not have to: the daemon sees that the owner is gone and reclaims the device within a minute.
A daemon that comes and goes
Expiry and idle shutdown have to happen on time, even when no command runs for an hour.
That usually means a launchd agent: a plist to install, a process running from login to shutdown, and one more thing to remember when uninstalling.
simctlhouse has none of that.
The first acquire, release, renew or run that finds no daemon starts one in the background, in its own session, so closing the terminal does not end it.
It sleeps until the next lease expires or a free device’s idle time runs out, and a command that changes the pool wakes it early.
Once nothing is leased, booted or in progress, it exits on its own, with the defaults about 15 minutes after the last device goes back.
On a day without iOS work, nothing of simctlhouse runs at all.
The tricky part of a daemon that quits is the moment it quits. A command could lease a device just as the daemon decides there is nothing left to watch, and that lease would then expire with nobody watching. So the daemon makes that decision while it holds the state lock, and gives up its own lock before letting go. A command that adds work right after it sees no daemon and starts a new one.
It has no port, socket or protocol.
Everything it needs is already in state.json, so commands and the daemon only ever talk through that file and its lock.
Whether a daemon runs is answered by another flock, held for the daemon’s whole life, which unlike a pid file cannot go stale.
After an upgrade, the first command from the new binary replaces the old daemon.
CoreSimulator sometimes lies
Early on, a leased device vanished in the middle of a test.
Nobody had deleted it, and the only way to find out who held it was to dig through agent transcripts.
That is why simctlhouse history exists, and it is how I found the cause.
simctl list devices can briefly return an incomplete list, for example while CoreSimulator restarts.
The pool treated a missing device as gone and dropped it.
Now a device counts as gone only when its device.plist has also disappeared from disk.
One that is only missing from the listing stays in the pool as Missing until the listing includes it again.
Agents ignore warnings
The skill tells agents never to pass their own -destination to run.
They do it anyway, because name=iPhone ... is in every tutorial they learned from.
A warning would not help, since agents read past warnings, so run refuses a destination that names another simulator, with exit code 125 and a message that says to delete the option.
The agent fixes it on the next try.
The same thinking runs through the whole CLI. Exit codes are documented API so agents can branch on them, stdout carries only machine output, and every command accepts both a device name, which people read, and a UDID, which agents hold.
What it does not solve
simctlhouse gives every agent its own device, and nothing limits how many.
A freshly booted simulator uses close to a full core, and with enough agents building and testing at once I have seen the load average pass 500.
Separate devices fix the collisions, and the CPU is still shared.
Each booted simulator also takes about 2.4 GB of disk, and the pool only grows, so simctlhouse delete --unused cleans up devices nobody has used for a week.
Try it
brew install juraj-blahunka/tap/simctlhouse
simctlhouse skill install
skill install links the skill into Claude Code, Codex, pi and other agents that load Agent Skills, and from then on they lease a simulator whenever they are about to build or test.
The source, the full decision log and the docs are on GitHub.
If your agents still fight over a simulator, or you run into something the pool gets wrong, please open an issue.