Dev.to AI ๐Ÿค– Ai ๐Ÿ‘ 0 ๐Ÿ“– 7 min read

My agent builds its own windows and checks them by screenshot

At the start of November someone whose opinion I value looked at my app and said it felt like too many menus. I counted. 16 windows, a dozen overlays, 24 actions in the command palette. Fair point. The obvious fix would

My agent builds its own windows and checks them by screenshot

At the start of November someone whose opinion I value looked at my app and said it felt like too many menus. I counted. 16 windows, a dozen overlays, 24 actions in the command palette. Fair point.

The obvious fix would have been one more panel, the one he was missing. But the panels I'd want myself are small and personal: "which session is waiting for me", "the open tasks in this project", "how many tokens did I burn today". I can't build all of them, and I shouldn't.

So I gave Claude Code a way to build them itself.

VibeDesk is a desktop app around Claude Code. It already had an MCP server for things like arranging windows. I added six tools to it: desk_app_create, desk_app_snapshot, desk_app_code, desk_app_list, desk_app_open and desk_app_delete. You ask in any session, "build me a window that shows which session needs me", and a few seconds later it's on your desktop, in the same glass look as everything else.

The one on my own desktop is a list of open tasks from the project's notes, newest first, with a filter and checkboxes to tick them off. Exactly the kind of window I'd never have built as a feature for everyone.

What a call looks like

Claude sends three strings and a name (shortened here):

{
  "name": "Waiting on me",
  "html": "<div class=\"row\"><h2>Waiting on me</h2><span class=\"spacer\"></span><span id=\"today\" class=\"muted small\"></span></div><ul id=\"l\" class=\"list\"></ul>",
  "code": "vd.watch('sessions', (all) => vd.mount('#l', all.map((x) => vd.h('li', { class: 'row' }, ...))))",
  "css": ""
}

html is the body, without any <script>. code is JavaScript that runs after it. The window already has VibeDesk's styles loaded, so a button, a .badge or a .dot.waiting looks native without Claude writing CSS. The tool description lists those classes in one paragraph, plus a one-line example.

The script talks to a global vd object, and that's all it gets:

  • await vd.data('sessions' | 'brain' | 'usage' | 'project') reads, and vd.watch(kind, fn) calls fn on every change. Read only.
  • vd.store.get/set is the window's own storage, at most 200 kB of JSON.
  • vd.h(tag, props, ...children) builds elements. Text never gets parsed as HTML.

The loop: build, report, look

The app saves the files, opens the window and waits up to 6 seconds for it to report back. The window only reports "ok" after it has run for 500 ms without an error, so an error after the first await still makes it in. Only then does the tool return.

I broke a window on purpose to show it. I changed u.today.tokens to u.totals.tokens, a field that doesn't exist. The tool came back after 584 ms with:

Tool window "Waiting on me" saved (id: waiting-on-me, 460ร—250).
ERROR: Cannot read properties of undefined (reading 'tokens')
Fix it and call desk_app_create again with id "waiting-on-me" (only the changed parts are needed).

(Translated. The real tool texts are in German, which is my language. Claude doesn't mind.)

The error also shows up in the window, with a button:

The broken window: the session list renders, and a red bar at the bottom shows the error and a "Let Claude fix it" button

"Let Claude fix it" sends the error as a prompt to the Claude session whose terminal is on top. If that session is busy, the prompt waits in its queue.

Then there's desk_app_snapshot. It brings the window to the front, asks the renderer where exactly it sits, takes a picture of only that rectangle with Electron's capturePage (scaled down to 1,100 px wide at most) and returns it to Claude as an image content block. Claude sees what you see.

That turned out to be the important part. Code that runs without an error can still look wrong: a row that wraps, a badge in the wrong color, a list that's empty because the data has a different shape than Claude assumed. Without the picture, "it runs" is all Claude knows. I first built this loop for animated backgrounds, and it was the biggest quality jump there too.

Fixed, sent again with only code changed, 620 ms:

The fixed window: three sessions, api waiting for you, shop-frontend working, docs-site done, 96 k tokens today

That's a test instance with demo projects, not my real desktop.

Where the walls are

Claude writes the code, but I still don't want code I haven't read running inside my app. So the window has no way out, and each layer is meant to hold even if another one fails.

An iframe with sandbox="allow-scripts" and nothing else. No allow-same-origin, so the frame gets an opaque origin. It can't reach the app's DOM, the preload API, cookies or storage. It can't open popups, submit forms or navigate the top window.

A strict CSP on every file. The window loads from a custom protocol (vibedesk-scene://app/<id>/โ€ฆ), and each response carries:

default-src 'none'; script-src vibedesk-scene:; style-src vibedesk-scene: 'unsafe-inline';
img-src vibedesk-scene: data: blob:; font-src data:; form-action 'none'; base-uri 'none'

connect-src falls back to 'none', so no fetch, no XHR and no WebSocket. No outside scripts, and no inline scripts either.

WebRTC is gone. CSP doesn't cover it. Before Claude's code runs, the runtime replaces RTCPeerConnection and its relatives with undefined, as non-configurable properties, so they can't be put back.

The frame stays where it is. If a script sets location.href to a web page, the main window's own CSP (frame-src 'self' vibedesk-scene:) blocks the load.

Data is a short list. The renderer only answers messages whose source is that exact iframe. There are four kinds of data, all read only. Pushes are throttled to one per 800 ms and only go out when something changed. Code is capped at 150,000 characters and there's a limit of 40 windows.

What went wrong on the way

Every error said "Script error." In a sandboxed iframe, every script counts as cross-origin, even your own, so window.onerror hides the message. The fix: crossorigin="anonymous" on every script tag and access-control-allow-origin: * on the protocol's responses. Then the real message comes through.

Inline handlers fail silently. The CSP blocks onclick="..." without an error the window could report, so the button just does nothing, and the window still says "ok". Now desk_app_create rejects <script> and on...= in the HTML up front, with a message that says to use addEventListener in code instead.

Top-level await costs you line numbers. Claude's code is wrapped in an async function so it can await vd.data(...) right away. Anything that throws inside it becomes a rejected promise, and an unhandledrejection has no line number at all. That's why the error in my broken example above says what went wrong but not where. Errors in event handlers still arrive as normal error events, one line off because of the wrapper, and the runtime subtracts that line again.

My navigation guard never fired. I had a handler on Electron's will-frame-navigate to keep the frame from leaving. For a plain location.href change in the iframe, it didn't fire. The main window's CSP blocked the navigation anyway, so nothing leaked. An end-to-end test now checks exactly that. A fake web server on 127.0.0.1 was useless as a test, by the way: Chromium's Private Network Access blocks that on its own.

What this doesn't cover

  • The window can still show you anything. It can draw a fake dialog that asks for a password. It can't send what you type anywhere, but it can put it in its own storage.
  • The repair button forwards text from the window to Claude. The error message comes from the window's own code. Today Claude wrote that code itself, so it can only prompt itself. If windows ever become shareable, that button is a prompt injection path, and it needs a closer look before then.
  • Read only, local only. A window can't start a session, write a note or call GitHub. That rules out a lot of dashboards people would want. It's deliberate for now.
  • The snapshot needs VibeDesk on screen. If the app is minimized, the tool says so instead of returning an empty image.
  • New tools only show up in new sessions. Claude Code reads the MCP config when a session starts.

This is on main now and ships with VibeDesk 2.1 on December 13. The status side of it, which session is waiting, I wrote about here.

Question

Which window would you want your agent to build for you?

Or pick one:

A) a dashboard: sessions, tokens, cost
B) a tracker for one project: tasks, decisions, checklists
C) a calculator or converter for something I do every day
D) nothing, I want fewer windows, not more

(I build VibeDesk, a free, open-source Windows desktop for Claude Code. The tool windows live in src/main/appStore.ts, src/main/appTools.ts and resources/app-runtime.js if you want to read the actual code.)

๐Ÿ“ฐ Read the original article on Dev.to AI

Originally published by Dev.to AI. Aggregated on AIWithGhost for educational purposes โ€” full credit and traffic to the original publisher.