u2-agent converts messy Android accessibility trees into ultra-compact semantic handles (@1, @2, ...) with sub-15ms cached execution. Built specifically for Claude, GPT-4o, and autonomous agent loops.
Standard mobile tools dump raw Android View hierarchies containing thousands of useless container nodes. Your agent's context window gets choked before it even takes its first action.
Slide to see how much context and API budget your agent saves across an automation workflow:
Zero token overhead, predictable deterministic error codes, and warm background sessions.
u2-agent ui snapshot strips frame containers, merges overlapping ghost wrappers, and indexes every interactive button, input, and item with an ephemeral reference handle (@1, @2, ...).
The LLM issues an action specifying --ref "@N". The background daemon resolves exact screen coordinates directly from RAM in sub-15ms without cold re-dumping or ADB disconnects.
stdout emits strictly compact machine text (ok or snapshot trees). Diagnostics, self-healing hints, and audit logs flow to stderr, preventing agent reasoning contamination.
Strictly adhering to the architectural rules defined in AGENTS.md.
Crafted purely with Bun and native TypeScript APIs. No bulky WebDriver dependencies, Puppeteer emulators, or Java runtime wrappers on the host.
Keeps ADB socket forwards and UIAutomator2 JSON-RPC sessions alive in the background, slashing per-action execution latency from 800ms to under 15ms.
Automatically collapses nested ghost wrappers with ≥ 85% bounding box overlap into single high-level semantic components (Input, Button, Tab, Toggle).
Drop-in compatible with Claude Code, OpenCode, Cursor, Antigravity, AutoGen, and custom Python / LangChain agent orchestration loops.
Export standard function-calling schemas with tools schema --format openai ready to plug into Anthropic, OpenAI, or Gemini tool call catalogs.
Every failure emits distinct machine error codes (SELECTOR_NOT_FOUND, DEVICE_OFFLINE, USAGE) accompanied by actionable recovery hints on stderr.
Test drive u2-agent commands and inspect their LLM-compact output shapes live.
Extracts the screen view tree and maps actionable items to handles.
u2-agent ui snapshot --limit 30
All you need is Bun and an Android device with USB debugging enabled.
Clone the repository and install dependencies with Bun:
git clone https://github.com/themikehage/u2-agent.git && cd u2-agent && bun install
Verify your connected device and install the lightweight UIAutomator2 RPC server:
bun run src/index.ts setup install
Take your first compact semantic snapshot and tap elements by handle:
bun run src/index.ts ui snapshot
Build a single self-contained binary without needing Bun on PATH:
bun run build
How u2-agent achieves sub-15ms interaction loops over ADB.