# iphone-control — setup from zero This guide takes a Mac and an iPhone to a first working tap. It takes about 30 minutes, and most of that is the first WebDriverAgent build. Use it on a new Mac, for a new phone, or to give the skill to someone else. For known errors and older phones, see `install.md` in this folder. ## How it works ``` Claude Code / Codex │ ops.py or phone.py (CLI) ▼ Appium server 127.0.0.1:4723 (Mac) │ XCUITest driver ▼ USB cable WebDriverAgent (WDA) (on the phone) │ accessibility tree, taps, screenshots ▼ Any app on the iPhone ``` - **Appium** is a local server. It holds one session per phone and keeps its connections to the phone open. - **WebDriverAgent (WDA)** is a small test app. Xcode builds it, signs it with your Apple Developer team and installs it on the phone. It reads the screen and sends the input. - Only the USB cable is used. Wi-Fi, Bluetooth, iPhone Mirroring and an unlocked Mac are not needed. The skill has two runtimes: | Runtime | File | Use it for | |---|---|---| | Legacy | `scripts/phone.py` | Setup and the first session start (`setup`, `ensure`, `doctor`) | | Lean | `lean/ops.py` | Driving the phone every day (look, tap, swipe, type, wake, lock) | ## What you need - A Mac with Xcode (with the iOS platform) and Homebrew. - An Apple Developer team. A paid team is best. A free personal team also works, but its profiles expire after 7 days, so WDA must be rebuilt every week. - A USB cable that carries data, not only power. - The iPhone, and a few minutes with it in your hand for Trust and Developer Mode. ## Step 1: Install the Mac tools ```bash brew install node uv ffmpeg npm i -g appium appium driver install xcuitest ``` FlowDeck is optional. `phone.py setup` uses it only to find the phone's UDID. FlowDeck is a paid tool (flowdeck.studio). Without it, pass the UDID to `setup` yourself (step 5). Check them: ```bash appium --version # 3.x (tested on 3.7.0) appium driver list --installed | grep xcuitest # xcuitest 12.x (tested on 12.8.0) xcodebuild -version # tested on Xcode 26.3 security find-identity -v -p codesigning # must list an "Apple Development" identity ``` If the last command lists nothing, open Xcode › Settings › Accounts, sign in to the team and click "Manage Certificates" › "+" › "Apple Development". `uhubctl` is optional (`brew install uhubctl`). It power-cycles one USB hub port when a phone's link gets stuck. ## Step 2: Get the skill onto the Mac Unzip the package into Claude Code's skills folder. Claude Code finds it there by itself: ```bash mkdir -p ~/.claude/skills unzip iphone-control.zip -d ~/.claude/skills/ ls ~/.claude/skills/iphone-control/SKILL.md # the file must be there ``` For Codex, unzip it into `~/.codex/skills/` instead. Run the scripts through their own path, not with `python3 file.py`. Their first line tells `uv` which packages they need. If a copy lost the executable bit, run `chmod +x ~/.claude/skills/iphone-control/scripts/*.py ~/.claude/skills/iphone-control/scripts/*.sh ~/.claude/skills/iphone-control/lean/ops.py`. Runtime state goes to `~/.iphone-control/` (configs, sessions, Appium log). It does not sync and it belongs to this Mac only. ## Step 3: Prepare the phone 1. Connect the phone to the Mac with the USB cable. 2. On the phone, tap **Trust** and enter the passcode. 3. Turn on **Settings › Privacy & Security › Developer Mode**. The phone restarts. After the restart, tap **Turn On** again. 4. Decide on the passcode: - **Passcode off** (recommended for a test phone). The Mac can wake and unlock the phone with no help. Face ID turns off too, so App Store purchases ask for the Apple Account password. - **Passcode on.** Unlock the phone yourself before each session, and set **Settings › Display & Brightness › Auto-Lock** to **Never**. The tool cannot see or type on the passcode screen. With the passcode already off, you can do steps 2 and 3 from the Mac instead (`U` is the UDID from step 4): ```bash uvx pymobiledevice3 lockdown info --udid $U | grep -E 'TrustedHostAttached|PasswordProtected' # want true / false uvx pymobiledevice3 amfi enable-developer-mode --udid $U # restarts the phone and confirms itself uvx pymobiledevice3 mounter auto-mount --udid $U # mounts the developer disk image ``` ## Step 4: Let the Mac sign WDA for this phone Get the phone's name and UDID: ```bash flowdeck device list --json | grep -E '"name"|"udid"' # with FlowDeck: a few seconds ``` Without FlowDeck, open Xcode › Window › Devices and Simulators, select the phone and copy its Identifier. `uvx pymobiledevice3 usbmux list` also works, but it can hang for over a minute, so try it last. The phone must be in your team's Apple Development provisioning profile, or the WDA build fails with "Provisioning profile ... doesn't include the currently selected device". Pick the path that fits the Mac: - **An Apple ID is signed in to Xcode** (most Macs). Do nothing here. Xcode registers the phone during the first WDA build. - **No Apple ID in Xcode** (all Apple access goes through an App Store Connect API key). Register the phone, then make Xcode download a fresh team profile: ```bash asc devices register --name "" --udid --platform IOS ``` Then follow "iOS 16 and older phones" in `install.md`: move the old team profile aside and build any small app once with the API key flags. Xcode then downloads a profile that lists the new phone. ## Step 5: Start Appium and the phone's session Give every phone a short name and always use it. The name keeps each phone's config, session and ports apart, so two phones can run side by side. ```bash S=~/.claude/skills/iphone-control/scripts export IPHONE_CONTROL_DEVICE='test phone' # your name for this phone $S/server.sh start # Appium on 127.0.0.1:4723, log in ~/.iphone-control/appium.log $S/phone.py setup # finds the USB phone by name, finds the team, picks a WDA port $S/phone.py ensure --wait 15 # starts the first WDA build in the background ``` - `ensure` returns exit code 3 while the build runs. Run the same `ensure` again until it prints `ready=true`. The first build takes about 4 minutes. Later sessions start in 1 to 20 seconds. - Unlock the phone during the first build. WDA cannot install on a locked phone, and the build waits up to 30 minutes for the unlock. - Without FlowDeck, or when `setup` cannot find the phone (iOS 16 and older), give the values: `$S/phone.py setup --udid --team `. - `setup` writes `~/.iphone-control/devices//config.json`. **Before the first `ensure`, add your own WDA bundle id** to it. The default, `me.eugenechantk.wda.runner`, belongs to the author's team, and Apple lets each bundle id exist in one team only, so the build fails without this: ```json { "udid": "00008150-0000000000000000", "team": "ABCDE12345", "wdaLocalPort": 8101, "wdaBundleId": "com.yourname.wda.runner" } ``` **Do not** wrap `ensure` in `timeout`, kill the `xcodebuild` process, or start a second `ensure` in another shell. An interrupted session start keeps running inside Appium and breaks the next one. If that happens, wait until every pending `POST /session` in `$S/server.sh log` fails, then run one `ensure`. ## Step 6: Check that it works Run these in order. Each one must succeed before the next. ```bash O=~/.claude/skills/iphone-control/lean/ops.py D='test phone' $S/phone.py doctor # USB, signing, Appium, session: all OK $O --device "$D" status # session alive, screen size, front app $O --device "$D" wake # ends on the Home screen (passcode off) $O --device "$D" shot ~/Desktop/phone-check.jpg # open the file: it shows the Home screen $O --device "$D" launch com.apple.Preferences # Settings opens on the phone $O --device "$D" tree | head -20 # lists Settings rows with tap points $O --device "$D" home $O --device "$D" lock # the screen turns off $O --device "$D" release # frees the phone for other sessions ``` The setup is done when the screenshot shows the phone's screen and Settings opened on the phone. Last, ask Claude Code something that needs the phone, for example "use iphone-control to open Settings on 'test phone' and take a screenshot". It loads the skill from `SKILL.md`. ## Daily use ```bash $S/server.sh start # once after each Mac restart $O --device "$D" status # if the session is gone: $S/phone.py ensure --wait 15 $O --device "$D" wake # always wake before the first look (lock screen shows notifications) $O --device "$D" shot /abs/path.jpg # 1 image pixel = 1 point: tap the pixel you see $O --device "$D" tap 195 113 $O --device "$D" swipe up $O --device "$D" type "hello" ; $O --device "$D" enter $O --device "$D" release ``` Every input waits 0.8 seconds, then returns. Look at the next screenshot and decide. A timeout means "unknown", so look before you send the input again. The full rules are in `lean/README.md`. If every call says "socket hang up", WDA on the phone has died. Run `$O --device "$D" relaunch` (about 30 seconds), then `wake`. ## Add another phone Repeat steps 3 to 6 with a new name. Each named phone gets its own WDA port (8101, 8102, ...), so the phones run side by side on one Appium server. Never run `phone.py setup` without `IPHONE_CONTROL_DEVICE` for a second phone. Without a name it overwrites the default phone's config and orphans its session. ## Values to change for your own setup | Value | Where | Change to | |---|---|---| | WDA bundle id `me.eugenechantk.wda.runner` | default in `scripts/phone.py` | Add `"wdaBundleId": "com..wda.runner"` to each phone's `config.json` | | Team id `39GJBP8V5A` | `install.md` examples | Your team id. `setup` finds it from your signing identity. | | Phone names (hihi, dumb dumb, oldie) | `lean/ops.py` aliases, `install.md` examples | Your own names | `server.sh` refuses port 8766 (reserved on the author's Macs). Appium uses 4723. To change it, set `IPHONE_CONTROL_PORT` for `server.sh` and `APPIUM_URL` for `ops.py`. ## When it breaks | Symptom | Fix | |---|---| | `InvalidHostID` when the session starts | Re-pair: `uvx pymobiledevice3 lockdown pair --udid `, tap Trust | | `Unlock to Continue` in the build log | Unlock the phone. The build waits. | | Provisioning profile does not include the device | Step 4 was skipped. Register the phone and refresh the profile. | | `socket hang up` on every call | `$O --device "$D" relaunch`, then `wake` | | Black screenshot and empty tree | A secure screen (passcode, payment sheet). The owner of the phone must take it. | | The USB link is stuck and calls time out | `uhubctl` port cycle (see `install.md`) | The full table, iOS 16 phones and the USB hub fix are in `install.md`.