# desktop-cli **Computer-use for coding agents, as a CLI the agent shells out to — not an MCP server.** A coding agent driving a real desktop needs to do four things: read the UI, press keys, move the mouse, and control a browser. The common way to give it those is an MCP server, where every capability is a tool the model loads on each call and every "what's on screen" is an accessibility snapshot streamed back into context. That is expensive in the one resource an agent is always short of: **context**. A Playwright MCP snapshot of a busy page is thousands of tokens, sent every turn, whether or not the model needed most of it. Tool schemas ride along on every call. For a long automation session the bill is mostly overhead. `desktop-cli` takes the other route. It is a plain command-line tool. The agent runs `desktop-cli ui find "Save"` and gets back three lines, not a tree. It asks for the parts of the screen it wants, when it wants them. Nothing is streamed speculatively, and there is no per-call schema tax — the agent already knows how to run a shell. Built for and used by [Claude Code](https://claude.com/claude-code) on Windows. --- ## The tier ladder The design rule is **most direct wins**. Every task is attempted at the highest tier that can do it, and only falls back when it can't: 1. **Programmatic** — a browser over the Chrome DevTools Protocol, files, APIs. No GUI at all. 2. **Keyboard** — key chords, menu mnemonics, app shortcuts. 3. **UI Automation** — the Windows accessibility tree: the "DOM of Windows". Find an element by name or role, click it, read it, set its value. 4. **Mouse** — coordinate clicks, the last resort. Editing a spreadsheet cell is a file write (tier 1), not open-app-snapshot-click-type (tier 4). The ladder is the whole philosophy. --- ## What it does ``` desktop-cli windows # top-level windows desktop-cli focus "Excel" # bring a window forward desktop-cli menu "File > Save As" # navigate real menus (UIA + mnemonic fallback) desktop-cli ui find "Save" # locate an element in the accessibility tree desktop-cli ui click e42 # click it by the ref the tree handed back desktop-cli keys "ctrl+a; ctrl+c" # chords and sequences desktop-cli type "diacritics-safe text" # clipboard-typed, so ěščř survives desktop-cli run "focus 'X'; keys 'ctrl+s'; ..." # many commands, one process ``` ### Browser without stealing focus (CDP) The browser subcommand talks to a running Chrome over the DevTools Protocol via WebSocket, so it drives pages **without touching the mouse or the visible desktop** — the user keeps working while automation runs. It also survives most anti-bot checks that flag Playwright, because it does not set `navigator.webdriver`. ``` desktop-cli browser attach "portal" # attach to a tab by URL/title desktop-cli browser eval "(() => …)()" # run JS, get the value back desktop-cli browser fill "#iban" "…" # set a field + fire input/change desktop-cli browser click-coords X Y # trusted click (Input.dispatchMouseEvent) ``` Trusted clicks matter: some portals reject `element.click()` because `event.isTrusted` is false. CDP's `Input.dispatchMouseEvent` generates events the page can't tell from a human's. --- ## Why a CLI, concretely - **Context economy.** The agent pulls only what it asks for. No snapshot rides along on a turn that didn't need one; no tool schema is re-sent every call. - **Composable.** `run "a; b; c"` executes a batch in one process. Shell pipes and redirects work because it *is* the shell. - **Legible in the transcript.** Every action is a command you can read, copy, and re-run by hand. When something misfires, the transcript shows exactly what was sent. - **No server to keep alive.** No long-lived process, no port, no handshake — just a command that runs and exits. MCP is the right tool when a model needs structured, typed, always-available capabilities. For *driving a machine*, where the expensive thing is context and the actions are legible on their own, a CLI the agent already knows how to call is leaner. --- ## Install ``` pip install -e . desktop-cli help ``` Windows only — it is built on Win32 and UI Automation (`pywin32`, `comtypes`). The browser subcommand needs a Chrome started with `--remote-debugging-port=9222`. ## Licence MIT