OpenProgram Docs

Working behind the user

While an agent operates an application, a browser or a page, the user goes on working in something else. Seven things of theirs stay as they are.

KeptMeaning
Front applicationThe application the user is in stays the one that takes their keys.
Window orderNo window moves in front of, or behind, where the user left it.
Tab in viewThe tab they are looking at, in their own browser and in the App, stays the one shown.
PointerThe real pointer does not move.
Keyboard focusWhat they type goes where they were typing.
ClipboardWhat they copied is still there.
SpaceNo desktop switches, and no window changes Space.

Two layers

LayerWhat it covers
Delivery that takes nothingEach target sends its input so that nothing is activated or raised: Accessibility and per-process events for applications (macOS delivery), trusted input into hidden pages for the built-in browser (Browser tab driver), background tabs in the user's Chrome or Edge.
Giving back what is takenAn application that starts, or opens a page, a document or a dialog, may activate itself, and no option of the sender stops it. Measured on macOS 15: Chrome comes in front of every application whenever a tab opens in front, whether the tab was opened from the command line, by open -g or by AppleScript. openprogram/host/_platform/front.py answers all of these in one place.

Giving the front back

The window server changes the front application first and tells the applications afterwards, with events. An application brings its windows forward and draws its menu bar, and the one before it dims its title bars, only when its own event arrives. The events are held back, so nothing of the change is drawn.

  1. A step starts: front.kept(operated) records the front application and the window stack. One event tap serves every step that is running.
  2. The event telling the user's application that it lost the front reaches the tap before the application.
  3. An operated application is in front: inside the tap the front goes back to the user's application, and the event is dropped.
  4. The events that follow are dropped too: the operated application's "gained" and "lost", and the user's "gained". Neither application learns of it.
  5. For 0.5 s the window stack is read every 4 ms. An application that moved its own window forward anyway has the windows that stood over it raised again, deepest first.
  6. The step returns at once; the watch goes on for 0.8 s, since an application may activate itself a moment later.

Measured on macOS 15 in three cases: Calculator starting in front, Calculator activated while running, and Chrome opening a tab in front.

EventsResult
DroppedThe user's window on top in every reading; its title bar unchanged by one pixel; the front back within 2.8 ms of the event
Let throughCalculator's window on top; the title bar dimmed
Rule
Whose change it isoperated(pid) names the processes a step operates: the application a window call names (app, front.named), the user's Chrome or Edge, or the App for the built-in browser (front.bundles). Any other application that comes to the front is one the user switched to: it is left there and becomes the one the front is given back to.
User already thereWhen the user is in the operated application as the step starts, nothing is watched.
BoundedA step that keeps taking the front is answered six times, then left.
Events held backAn active tap on the annotated session for event types 19 (lost the front), 20 (gained it) and 13 with subtype 1 or 2 (the pair an application gets while it starts). An event is dropped only after the front has really been given back, so no application is left believing something untrue.
GrantThe tap needs the Accessibility grant and is not asked for without it, since asking would put a prompt in front of the user.
Without the tapThe front is read every 50 ms, given back, and the windows raised again; the operated application's window is then on screen for 15 to 43 ms. With the tap, this reading acts only on a theft it sees twice.
Reading the frontGetFrontProcess, 0.6 ms a call. NSWorkspace keeps its answer current from the main run loop, which a worker thread does not turn.
Giving it backSetFrontProcessWithOptions with the front-window-only option, 2 ms. NSRunningApplication.activateWithOptions called from a worker thread waits one second before it takes effect.
Window orderAXRaise on each window, found by its window-server id; the windows are looked up as the step starts, so that raising is one call. Windows that touch none of the operated application's are left alone. A 0.25 s messaging timeout is set so that a busy application is not waited for. Without the Accessibility grant the front application is still given back and the order is left.
RecordEach time is logged with the application's name, and kept in the block's Watch.taken.
EntryUsed by
kept(operated)The window, built-in browser and user browser providers (providers/window/provider.py, providers/browser/built_in.py, providers/browser/user.py) around every call, so structured steps and code mode are both covered.
watch_for(operated, seconds)The self-update switch, for the 30 s in which the desktop shell relaunches.
front.py <bundle path> <seconds>scripts/local-instances/install-dev-app.sh, which runs the file by itself; it needs only the standard library there, and without the Accessibility grant it reads the front every 50 ms.

What can take the screen, and the answer

SourceAnswer
An application is started for a stepStarted with open -g; one that activates itself anyway gives the front back.
A coordinate click orders the clicked window forward in its levelThe windows stacked over it are raised again (macOS delivery).
The user's browser opens the extension's connect pageThe front is given back. The page stays open as a tab of that browser.
The extension focuses the browser's window once connectedThe connect link carries the extension's own background=true when a token is set.
Playwright opens tabs in front and brings a selected tab forwardplaywright_background_tabs.cjs opens them inactive and drops the call.
Connecting without a tokenThe user approves the connection on that page, so the browser stays in front for that one call.
An agent's Cmd/Ctrl+F, L, K or P in a built-in pageThe App takes these as its own shortcuts only from a page that is on screen in the focused window and has the keyboard; otherwise the key stays in the page.
A page asks to confirm leavingA page nobody is looking at leaves without the dialog.
A site asks for camera, location or notificationsFrom a page nobody is looking at: refused this time, not remembered, so the user is asked when they open it.
An agent's click in the user's own tab opens a popupThe popup opens beside the tab; the tab in view and the route stay.
The App is reinstalled or relaunched by an updateIt reopens in front only when the user was in it as it closed.
An MCP server needs a sign-in when the worker connects it by itselfNo browser opens; the link stays in /api/mcp/auth/pending, and reconnecting the server opens it.

What the user still sees

ShownWhy
Agent cursor and window markerClick-through overlays shown without activation, so the user can tell which window an agent holds (Computer use interface).
Page preview in the conversationInside the App, for the conversation on screen; hidden once the user hides it.
NotificationsOnly while no App window has the focus; the App comes forward when one is clicked.
What a command opensA shell command an agent runs to show something (open report.html) opens it in front, as asked.

Linux and Windows

Neither system has a place where the events can be held, so the front is read, given back, and the windows put back in order.

WindowsLinux, X11
Reading the frontGetForegroundWindow every 20 msxprop -spy reports each change of the active window and the stacking order
Giving it backSetForegroundWindow from the foreground thread's input queuewindowactivate
Window orderSetWindowPos without activatingwindowraise, which a window manager may decline
Rule
Whose change it isApplications are told apart by process. A backend names the process it resolved (front.note); while it starts one (front.starting), a process that had no window as the step began is the new one. Browsers are told by executable (front.programs).
Forward on purposeInput those systems give only to the front window brings the window forward for the step (Linux and Windows backends); the approval card says so. The guard stands aside (front.forward), and the backend puts back the front window, the pointer and the window's place in the order.
WaylandAn application cannot take the focus without a token from the compositor; nothing runs.

Measured in a Debian container with Xvfb and Openbox: a running application that activated itself lost the front after 8.6 ms and the stacking order read the same afterwards; a window brought forward on purpose was left alone; a user's own switch was left alone.

Implementation status

StateScope
Implemented on macOSgiving the front back unseen for application steps, the user's browser and the built-in browser, measured live against Calculator starting and activating and against Chrome opening a tab (front application, window order and the user's title bar); the App's reopening behind the user; the shortcut, leave-page, permission and popup rules of built-in pages; no browser for unattended MCP sign-ins. Unit tests cover the rules with a stand-in desktop.
Implemented on Linux (X11)giving the front back and the window order, measured as above.
Implemented, not yet run on Windowsgiving the front back and the window order. The macOS machines this is built on have no Windows guest; the rules have unit tests with a stand-in desktop.
Not implementedon Windows: paste restores only text to the clipboard.
Last updated · 2026-11-25