Building an Autonomous Computer-Use Agent with Claude
A button moved 10 pixels to the left and my coordinate-based automation clicked empty space, then kept going as if nothing had happened. That is the failure I wanted to design out. A script that replays fixed click coordinates has no way to know the click missed, so a small layout change broke it, and broke it silently.
The Computer-Use Agent platform I built takes a different approach. Claude looks at the screen the way a person would and decides what to do next. The hard part turned out not to be the model. It was the loop around it: how fast it runs, and how it notices when an action didn't do what it was supposed to.
Four layers
- Capturescreenshot on change
- AnalysisClaude Vision + task context
- Planningvalidate tool-use command
- Executionact, then verify
The Capture Layer takes screenshots and compares screenshot hashes to decide whether the screen changed. That detects a visual difference, not a meaningful one: any pixel change, including a blinking cursor, an animation or a clock, can trigger a new frame. This comparison has no diff-ratio threshold to filter out small changes. The Analysis Layer sends only changed frames to Claude, along with the current task. The Planning Layer receives structured tool-use commands (click at coordinates, type text, scroll direction) and validates them before anything runs. The Execution Layer performs the action and then checks that the expected UI change actually happened.
Latency was the first problem. Each step is a screen capture, an API call, response parsing and an action, and it has to feel interactive. Sending a frame only when the screen changed, instead of on a fixed interval, cut API calls by 60% compared with fixed-interval capture. That figure comes from my own workloads, not a controlled benchmark.
A feedback loop, not a fixed sequence
My earlier automation was a fixed sequence of actions: step 4 ran because step 3 had run. The version I built is a state machine with feedback. Each iteration moves through observe, plan, act and verify. If verify confirms the expected change, the loop carries on to the next observe. If verify is inconclusive, it moves to a wait state, which holds until the expected change shows up or the timeout fires. Seeing the expected outcome during the wait resumes normal execution. An expired timeout, or a failure I can confirm, moves to a recover state, which asks Claude about the new screen. If recovery fails, it moves to escalate.
Running several at once
A FastAPI orchestrator queues tasks and starts one Docker container per session. Each container has its own virtual display and runs the agent loop.
- FastAPI orchestrator
- Session lifecycle, task queuing and state recovery.
- Container + virtual display A
- Container + virtual display B
- Container + virtual display C
- FastAPI orchestrator → Container + virtual display A: starts and tracks
- FastAPI orchestrator → Container + virtual display B: starts and tracks
- FastAPI orchestrator → Container + virtual display C: starts and tracks
Every agent gets its own desktop in a Docker container with a virtual display, so one session's popup can't steal another's focus. The orchestrator handles session lifecycle, the task queue and state recovery.
After three months in production
- 90% of tasks ran end to end without help. The other 10% are edge cases that escalate to a human.
- Decision latency was under 2 seconds per step.
- Three parallel sessions ran in my deployment.
Treat these as operating figures from my own deployment, not benchmarks. I'm not giving a task count, a latency percentile or hardware specs here, so they don't tell you what your workload would see.
That 10% is the number I watch. Escalation is the designed outcome when the agent can't verify its own progress, and I would rather have it hand off than guess.
- Q: Why not just use selectors and fall back to vision?
- A: I didn't build a selector-first hybrid. Desktop accessibility APIs can expose controls without access to an app's internals, but how much they expose varies from app to app, and a selector that resolves is not proof the control does what you expect. Vision gave me one code path across the apps I tested, and the verify step checks the result on screen either way. The cost is that every step with a changed screen needs a model call, which a selector would have avoided where it worked.
- Q: Why validate commands before executing them?
- A: The validator checks that a command is well-formed, that its coordinates fall inside the screen, and that it was based on the latest frame rather than a stale one. That catches malformed or out-of-date commands. It does not check that a click lands on the intended target, because coordinates alone don't say what the model meant. That is the job of the verification step after the action, and it can still miss a wrong click that changes the screen in the expected way.
- Capturing on screen change instead of on a timer cut API calls by 60% compared with fixed-interval capture, on my own workloads.
- Comparing screenshot hashes detects visual change, not meaningful change: even small changes from cursors or animations can trigger frames.
- Four layers: capture, analysis, planning, execution, with verification closing the loop.
- An unchanged screen is ambiguous, so each action has an expected outcome and a timeout, and the timeout moves the loop to recovery.
- Feedback through verify, wait, recover and escalate states handles popups and layout changes that break fixed sequences.
- Isolated Docker sessions let three agents run in parallel.
- After three months: 90% of tasks without escalation and under 2 seconds per decision, as operating figures from my deployment, not benchmarks.
Cite this article
Mohamed Hosny, “Building an Autonomous Computer-Use Agent with Claude”, www.mohamed-hosny.dev, . https://www.mohamed-hosny.dev/blog/building-computer-use-agent
Referencing this? Please credit Mohamed Hosny and link to the original page.