ai newsMi., 25. Nov.
EilmeldungCan Claude’s storage webhooks miss an hour-long outage?

How I got a phone screen down to 59 tokens and 13ms for AI agents (without screenshots or an installed app)

Scroll a long list on Android and something sneaky happens behind the glass. The view holding "Row 13" does not scroll off the top and vanish. Android peels off its label and hands the exact same node ID to "Row 29" down at the bottom. An AI agent tracking that ID will happily tap sixteen rows off,

dev.toDienstag 21:01 · 24.11.6 Min. Lesezeit
Bild: dev.to

Posted on Nov 24 • Originally published at phonedriver.dev

Scroll a long list on Android and something sneaky happens behind the glass. The view holding "Row 13" does not scroll off the top and vanish. Android peels off its label and hands the exact same node ID to "Row 29" down at the bottom. An AI agent tracking that ID will happily tap sixteen rows off, and Android will return a polite ok.

Most mobile-agent headaches look like that. Reading an accessibility tree fast is the easy half. The hard half is keeping element references honest across scrolls, knowing when a screen has actually stopped moving without hardcoded sleeps, and returning only what changed so the model isn't paying to re-read the whole phone on every turn.

I built phonedriver (Rust, AGPL-3.0, zero telemetry) to solve this for both Android and iOS—over MCP (Claude Code, Codex, Cursor, VS Code, Gemini CLI) or as a plain CLI. Here are the concrete systems tricks, the benchmarks, and the weird OS bugs that actually bit me along the way.

Instead of shipping a screenshot or 25 KB of nested XML on every turn, phonedriver prunes the accessibility tree into a numbered list of things a thumb can touch or an eye needs to read:

$ phonedriver snapshot app com.android.settings ( Settings ) @e1 button "Search Settings" @e2 group scrollable↓ @e3 button "Google" "Services & preferences" @e4 button "Network & internet" "Mobile, Wi‑Fi, hotspot" @e5 button "Connected devices" "Bluetooth, pairing"... @e10 button "Display & touch" "Dark theme, font size, touch" Enter fullscreen mode Exit fullscreen mode Tap @e10, wait for the Display screen to settle, then tap the Dark theme switch ( @e24 ). Instead of dumping the whole screen again, phonedriver replies with just the diff (~20 tokens):

$ phonedriver tap @e24 ok tapped @e24 "Dark theme" ~ @e23 button "Dark theme" "Will turn on when Bedtime starts" → "Will never turn off automatically" ~ @e24 switch "Dark theme" off → on Enter fullscreen mode Exit fullscreen mode + appeared, - disappeared, ~ changed. If more than 60% of the screen's refs turn over, you navigated somewhere new and phonedriver sends a fresh snapshot.

On a real HONOR X8's Display settings page, adb shell uiautomator dump emitted 25,334 bytes of XML. phonedriver sent 461 bytes. Four pruning rules did most of the work:

To prevent the recycled-row bug (in my API 37 spike, scrolling a 1,000-row ListView kept node ID -4294967273 alive while its text flipped from "Row 13" to "Row 29" ), a ref only follows a platform node ID when the role still matches and either the label is untouched or the bounds drifted less than 8 points. Every tap re-resolves against a fresh tree, failing cleanly with the closest match instead of tapping whoever took its chair.

Every adb shell uiautomator dump greets your phone like a stranger: AOSP's wrapper spawns a fresh app_process, opens a new UiAutomation connection, calls waitForIdle(1000, 10000) (insisting on one full second with zero accessibility events), and writes XML to disk.

On an API 37 emulator (median of 50 runs), that took 2,163.7 ms. Worse, on a real HONOR X8 (Android 13), uiautomator dump sat on the main Settings page for 11.5 seconds and gave up with ERROR: could not get idle state. because something on that page never goes idle.

phonedriver borrows scrcpy 's cleanest trick: push a ~40 KB dex jar over adb and start it via app_process as the shell user. No APK installed, no root, no AccessibilityService to toggle in Settings. When the daemon disconnects, the helper exits and leaves nothing behind.

Fixed sleep(2) calls are either sluggish or flaky, and accessibility events fire constantly for blinking carets and ticking clocks.

Instead, the host daemon decodes the H.264 stream with OpenH264 and diffs a 4×4-point luma thumbnail of each frame against the previous one.

My first threshold was 4,096 pt² (a 64×64-point square) to ignore blinking cursors and small spinners. Page transitions worked great. Material switches failed completely: 0 of 20 toggle taps ever reached 4,096 pt², so phonedriver kept saying changed: false after flipping a switch.

The fix was a two-phase settle detector:

On iOS, phonedriver runs a minimal Objective-C XCTest runner speaking length-prefixed JSON on TCP port 27753 (skipping WebDriverAgent's HTTP + XPath layers). Querying eight raw accessibility attributes directly read an iPhone 17 Simulator screen in 22.2 ms vs. WDA's 380.4 ms at depth 30 ( 44.8 ms with every WDA option tuned).

On the Simulator, three wild quirks jumped out during benchmarking:

And as of 0.1.6, a community contributor ( Coreho, PRs #23 and #29) wired up physical iPhone control over USB and Wi-Fi from Windows with no Mac, using Sideloadly + idevice!

Across 9 real Android jobs with Claude Sonnet 5.5 (cropping a photo, changing Chrome settings, pinning/archiving Messages, restricting a wakelock app, hunting planted signup bugs—all graded strictly against device state):

Two small token audits moved the needle even further:

And once an agent works out a flow, you don't need to pay for the LLM again:

phonedriver save signup.steps phonedriver replay signup.steps --var email = test+ { { run } } @example.com Enter fullscreen mode Exit fullscreen mode Replay runs deterministically with zero model tokens (109/110 passed across 11 Android jobs), supports PHONEDRIVER_SECRET_1 env vars for unattended CI logins, and ships as a GitHub Action.

By default, phonedriver pauses any action that would hit Pay, Buy now, Buy with GPay, Place order, Transfer, or Delete account (labels in 11 languages) and triggers MCP elicitation directly to the client UI. The model never sees the prompt and cannot answer it.

After an outside security review in 0.1.7 ( giulioc84, #32–#39), that gate now inspects swipes, drags, pinches, scrolls, press enter, and field clears—not just taps—and binds each approval strictly to the exact button and details shown. --secret values are scrubbed before logs, traces, replays, or truncation.

npx -y phonedriver init Enter fullscreen mode Exit fullscreen mode That registers phonedriver with Claude Code, Codex, Cursor, VS Code, or Gemini CLI and checks your adb/Xcode/device setup.

Expand Abdullah Naseer Abdullah Naseer Abdullah Naseer Follow Indie builder from Pakistan. First app: ShiftLog — free shift & profit tracker for gig workers. https://play.google.com/store/apps/details?id=com.shiftlog.app Joined Oct 26, 2026 • Nov 24 Dropdown menu Copy link Hide The recycled-row detail is the one that would have bitten me — a node ID surviving while its label flips from Row 13 to Row 29 is exactly the kind of bug that looks fine in a demo and taps the wrong row in real use. Curious whether the ref fingerprinting you added to catch it costs much in read time, or if the 12.7 ms already includes it.

Quelle: dev.to (dev.to). Original öffnen