How to drive the iOS simulator with Claude Code: my rules for an agent that taps the right spot
Connect an MCP server that can drive the simulator, then give the agent three rules: read the screen through the accessibility tree, never by guessing pixels on a screenshot, stop after two failed taps at the same spot, and one agent per device. For anything that must replay identically, like App Store screenshots, I have the agent write a script instead of improvising.
The problem: an agent looking at an image taps beside the target
Claude Code reads and writes code, but a mobile app is checked on screen. Without a tool, the agent changes a component, runs the tests, and calls the work done without ever seeing the result. So it needs hands: an MCP server that exposes actions like launching the app, tapping, swiping, typing and taking a screenshot.
The trap shows up right away. A screenshot is a scaled-down image. An agent that estimates a button's position from pixels is off by a few points, taps beside it, tries again, and ends up concluding the button is broken. The bug is not in the app, it is in the aiming.
The method: accessibility tree first
I use argent (npm package @swmansion/argent), an MCP server that drives the iOS simulator, the Android emulator and Chrome. It installs with npx @swmansion/argent@latest init -y, and claude mcp list then confirms that Claude Code sees it.
Its instructions live in a file under ~/.claude/rules/, loaded in all my sessions. The ones that matter most:
- Aim with the tree, not the image. Every action returns a screenshot and the list of on-screen elements, with their frame in 0 to 1 coordinates. You tap the centre of the frame. The file marks this rule as important: never derive tap coordinates from screenshot pixels.
- Two failures, then read the screen again. If a tap fails twice at the same spot, the agent stops retrying and asks for the tree again. The screen has often changed in the meantime: a modal, a keyboard, an animation.
- List devices before anything else. The agent starts with
list-devicesand picks a simulator that is already booted, rather than starting a second one. - Wait for an element, not for a duration. To know whether the next screen is there, the
await-ui-elementtool waits for an element to appear or disappear. No screenshots in a loop. - Batch what is predictable. When several gestures follow each other with no need to look in between,
run-sequencesends them in one call.
And one rule from my global CLAUDE.md: on a React Native project, never several agents in parallel. There is one simulator and one Metro server, and two agents driving them get in each other's way. Running several agents is for reading code, not for driving a device. The rest of my React Native setup is in the dedicated article.
A real example: App Store screenshots
My iOS apps need screenshots for their App Store listing, in every language. I turned this into a skill. The agent does not take these screenshots by tapping around: it prepares the app, then a Maestro script replays the flow, one pass per language.
- Demo data through a development-only link. A
<scheme>://demolink resets the database and injects a believable data set, with fixed times. Every screenshot starts from the same state. - A clean status bar:
xcrun simctl status_bar <udid> override --time 9:41with network, wifi and a full battery. - Only `testID`s in the script, never translated text. The same script works in every language of the app. When a
testIDis missing, it gets added to the code. - No keyboard typing during screenshots: the simulator is set to AZERTY, and the skill forbids any typing.
The skill also sets a condition before starting: I have tested the app myself in the simulator and approved it. The agent can check that a screen shows up, it cannot judge on its own that a screen is good.
What went wrong
Several rules in the screenshot skill come from attempts that went badly:
- A tap during a transition gets lost. The script now waits for every animation to end after a back or a close, waits for the next screen's element, and retries the tap that opens a modal.
- Development elements on the screenshots: the dev client's floating tools button and error banners. The button is turned off once in the developer menu, the banners with
LogBox.ignoreAllLogs(true). And the Maestro option that clears the app state brings the button back, so it is banned. - A render that was too plain. My first compositions framed the screen with a simple rounded rectangle. My rule since 11 November 2026: a real iPhone frame, with Dynamic Island and status bar, and the whole phone in the image.
Context cost matters too. The simulator rules file is 198 lines long and loads in all my sessions, including on this Next.js site where no simulator runs. I go into it in the article on CLAUDE.md.
How to get started
npx @swmansion/argent@latest init -y # installs the MCP server
claude mcp list # checks the connection- Write the coordinates rule in a file under
~/.claude/rules/: accessibility tree, never pixels. - Add
testIDs to the elements the agent must touch. They serve both tests and driving. - One agent per simulator. To parallelise the rest, see the article on parallel sessions.
- As soon as a flow must be replayed, have it written as a script instead of asking for it again each time.
Article written with the help of AI, from my daily practice and my projects.
The whole notebook