/cua:macos-harnessfrom cua
Documents the browser-use/macos-harness CLI for whole-Mac control from one persistent session: screenshots, PID-targeted input, virtual pointer, Apple Accessibility, Apple Events, and CDP escape hatch for Chromium apps. Includes failure-mode guides for Electron web views, native dialogs, and HID-only apps.
Ships in cua. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
Read when SKILL.md points to them.
Control a Mac from one persistent scripting session: one CLI call per decision point, not per primitive.
macos-harness <<'PY'
app = "Spotify"
mac.see(app)
mac.key("cmd+k", app=app)
mac.type("Alessia Cara", app=app)
print(mac.see(app))
PY
The CLI preloads mac, browser, Path, and subprocess. Prefer bounded stdin
programs; reserve macos-harness repl for manual exploration and always exit it.
This skill documents the browser-use/macos-harness CLI (MIT), pinned to the v0.1.x line — upstream v0.2.0 rewrote the interface, and the six-verb contract below (
see,key,type,click,ax,script) exists only there. Install v0.1.2:uv tool install --python 3.12 --from git+https://github.com/browser-use/[email protected] macos-harnessThe core sections are upstream's
skills/macos-harness/SKILL.md(v0.1.0) with local additions and generalizations — seeUPSTREAM.mdandLICENSEin this directory. If you prefer not to depend on that CLI, wrap your own over the standard pieces (screenshots plus the accessibility tree, e.g. Peekaboo; Quartz event posting viaCGEventPost;osascriptfor Apple Events;screencapture; raw CDP for Chromium surfaces) and follow the same conventions — the behavioral rules and failure modes below are what matter.
Think in six verbs: see, key, type, click, ax, script.
frame = mac.see("Spotify")
mac.key("cmd+k", app="Spotify")
mac.type("Alessia Cara", app="Spotify")
mac.click(640, 420, app="Spotify")
item = mac.ax.at(640, 420, app="Spotify")
mac.ax.perform(item["element_index"], "AXPress")
mac.script('tell application "Spotify" to play')
Use ordinary Python for local context and one-off logic. Do not add app-specific helpers when a short program can resolve the task.
my, friend, or prior activity),
inspect that context and correlate stable fields; a loose text hit is not enough.mac.script() for a known exact, focus-safe app command.mac.see(app) and vision.mac.ax only when semantic identity or state matters. Do not dump
a full AX tree before trying the direct route.After a failed verified burst, switch mode or stop. Never repair uncertainty with repeated keys, clicks, deletion loops, or bulk input.
FocusChangedError; never
manipulate focus to restore it.mac.click() is raw PID-targeted input. It never guesses an AX action.mac.move() moves only that pointer; it cannot produce native hover.mac.see() and preserve window
bounds and Retina scaling.Secondary primitives are mac.move, drag, scroll, show_pointer, and
hide_pointer. mac.ax.query() returns compact matches and bounds fallback
traversal; lower max_nodes for especially large apps.
mac.see reads these fine; input does not reach them. The window is a web page,
so the AX tree collapses to a single AXScrollArea exposing no actions, and
mac.click produces a hover outline with no state change. That is structural,
not a focus problem — retrying, activating, or falling back to mac.ax all fail
the same way. Spend one verified failure, then leave the harness for CDP
(agent-browser, browser-harness, or raw CDP — see the cua router for the
options).
Native panels those apps open are the exception: an Open/Save sheet is AppKit,
so mac.ax drives it in the background while CDP cannot see it. Open: AXOpen
on the file's AXTextField; Save: set AXValue on identifier
saveAsNameTextField, then AXPress on OKButton. An AXError -25205 can
arrive after the panel already acted, so judge by the app's state, not the call.
A folder picker has no file to open: set AXSelected on the folder's AXRow,
then AXPress the Open button. Moving the panel elsewhere is the trap. It
runs in openAndSavePanelService, so mac.key aimed at the app never reaches
it; filling the Go-to sheet's field by AX and AXConfirm/AXOpen on its path
items report success and do not move it, nor does writing NSNavLastRootDirectory
into the app's defaults; and keys posted at the HID level go to
whichever app owns that combo globally (Cmd+Shift+G opened another app's
screen-capture overlay and a macOS screen-recording prompt). Put the folder
where the panel already is (it opens at the last folder used), and do not
screenshot it there: it lists the user's own files. A signed, hardened app's
panel may expose no AX nodes at all.
Some apps refuse a debugging port by policy (Feishu/Lark sets
RemoteDebuggingAllowed off); there CDP is not an option at all.
Such apps usually expose no debugging port; check before assuming one
(lsof -nP -p <pid> -iTCP -sTCP:LISTEN). Relaunch the app yourself with one:
open -a <App> --args --remote-debugging-port=9333
curl -s http://127.0.0.1:9333/json # pick the target whose type == "page"
Then drive that port directly (Runtime.evaluate, Input.dispatchMouseEvent,
Page.captureScreenshot). The port is a live remote-control channel into the
user's app: relaunch without the flag when done and confirm it stopped
answering — same discipline as unloading any other injected runtime state.
Relaunching restarts an app someone may be using, so it is a decision to surface, not a step to slip in — say so first when the app was already running, and on a machine that is not yours, ask before quitting anything.
Three traps once you are inside the page:
element.click() often does nothing. React/Radix menus and popovers open on
real pointer events. Read getBoundingClientRect(), then dispatch
Input.dispatchMouseEvent mouseMoved → mousePressed → mouseReleased.offsetParent !== null. It is null for every
position: fixed element, so headers and toolbars drop out of your query and
the page reads as empty. Use checkVisibility() plus a rect test.Page.getFrameTree, call
Page.createIsolatedWorld passing frameId = that frame's .id (frame
objects carry no .frameId), and evaluate against the returned
executionContextId.WeChat for Mac (com.tencent.xinWeChat) is not Chromium but fails the same way:
see captures fine while click, double-click, and scroll all no-op — observed
even with the window fully visible. Its data lives in a sandboxed container
(~/Library/Containers/com.tencent.xinWeChat/Data) that reads
Operation not permitted without Full Disk Access, so files are not a fallback.
Two extra quirks:
WeChatAppEx renderer) with overlapping windows; resolve by
CGWindowListCopyWindowInfo and capture each candidate with
screencapture -o -x -l <window_id>, which works for off-screen/occluded
windows that mac.see cannot reach.When input is dead, the working loop is: ask the user to scroll/flip, poll
screencapture -l <id> every ~2s and save on checksum change. One verified input
failure, then switch to this — do not retry bursts.
ToDesk (com.youqu.todesk.mac) only forwards HID-level input: PID-targeted
mac.click moves the remote pointer but never presses, and mac.key never
arrives. Custom-rendered UIs (Flutter, e.g. a proxy client's window) fail the
same way from the other side: mac.ax exposes only the menu bar, so ax.at()
returns AXMenuBar for every point, and PID clicks no-op even when frontmost.
One such failure is enough — do not retry. What works, with the user's
consent (it takes over their real keyboard and mouse):
CGEventPost(kCGHIDEventTap, …). Run them under your automation
environment's own sys.executable; a plain python3 may lack Quartz.
Map screenshot coordinates to screen with bounds and scale_x/scale_y
from mac.see.ctrl+shift+v lands as a bare V).
Paste through the remote's right-click menu instead; the Mac clipboard syncs
to the remote. Clear it afterwards if it carried a secret.Use a CDP-based tool for DOM, tabs, network, downloads, and uploads. Do not
substitute AX for CDP inside a web page. When a CDP client first attaches to the
user's own Chrome, the browser shows an Allow remote debugging? sheet — accept
that exact prompt once through system-wide AX. Never activate Chrome or emit a
mouse event to do it.
Before real work, check permissions without prompting (doctor --request asks
the OS to prompt, so run it only with user approval). Accessibility, screen
recording, and event posting are global; Apple Events Automation is per target.
What SKILL.md sets; muted values are Claude Code's defaults
Three short reads, in order
3 skills in this plugin
/cuaSingle entry point for operating any GUI: desktop windows, browsers, Electron apps, dialogs, iOS/Android simulators, physical and cloud phones. Routes each request to the right detail skill and gets out of the way. Fires on 「打开网页」「点一下」「截个图」「帮我操作」「填表」「手机上跑一下」「自动化浏览器」 「控制电脑」「用某个 profile」「在我已登录的账号里」「装个 APK」「看 logcat」 「模拟器上验证一下」「adb 连不上」「设备被别人占着吗」「双指缩放」「手机上输中文」, "open the site", "click", "fill the form", "log in to the site", "use my logged-in account", "take a screenshot", "drive the app", "automate the browser", browser QA or dogfooding, driving VS Code/Slack/Figma desktop UIs, simulator evidence for an app change, simulator or real-device taps, pinch zoom, "WebDriverAgent won't start", Apple Events or background input without stealing focus. Not for calling an API or reading a URL's raw response (「查一下这个接口返回什么」→ curl/xh), and not for terminal/worktree/agent management./phone-useThe one manual for phones and emulators, companion detail skill of the `cua` router: Android emulator/phone via adb + uiautomator2, iOS Simulator via AXe/Appium, real iOS via WebDriverAgent, cloud real devices (BrowserStack, AWS Device Farm); element taps, UI tree, Chinese text input, pinch zoom, screenshots/recording, app install with hash proof, logs, deep links, mobile QA — plus how to tell whether a human is using the device before you touch it.npx claudepluginhub sunflowerslwtech/sunkit --plugin cuaOther plugins' skills for the same job