{"slug": "building-a-multi-agent-token-usage-widget-in-under-500-kb", "title": "Building a Multi-Agent Token Usage Widget in Under 500 KB", "summary": "A developer built Leap EDGE, a macOS desktop quota monitor for parallel AI coding subscriptions (Gemini via Google Antigravity, Claude Code, OpenAI Codex, GitHub Copilot) that computes burn rate and projected run-out time from used-versus-elapsed quota fractions. Shipped as a 483 KB Swift dual-engine universal binary, it avoids an embedded WebView by default, drawing five quota cards with AppKit and NSBezierPath and polling data every 300 seconds, versus roughly 220 MB for Electron and 6 MB for Tauri v2.", "body_md": "*Series 2/2: Multi-Model Collaboration & Quota Management in Practice ([Part 1: Building a Cross-Model Collaborative Workflow with Google Antigravity](https://dev.to/gde/building-a-cross-model-collaborative-workflow-with-google-antigravity-2jj5))*\n\nWhen you run tasks in parallel across **Google Antigravity (Gemini)**, **Claude Code**, **OpenAI Codex**, and **GitHub Copilot**, a progress bar that simply says `40% used` is not very useful.\n\nBurning 40% in the first 30 minutes of a 5-hour quota window means you will hit a wall in another hour; burning 40% with 20 minutes left before reset means you have more quota than you can finish.\n\nTo make an always-on desktop quota monitor answer **\"At my current pace, how much longer can I keep working today?\"**, I worked with the agents to build two things:\n\n`paceFraction`)` 0.0%`.\nTo know whether a quota pool is about to blow up—or whether it still has plenty of slack—you only need to compare two ratios:\n\n`usedFraction` \n\n```\nusedFraction    = consumed / total\npaceFraction    = 1.0 - (resetsAt - now) / windowDuration\nrate            = usedFraction / paceFraction\nprojectedRunOut = windowStart + windowDuration / rate\n```\n\nFor example: suppose a 5-hour window starts at `09:00` and resets at `14:00`. At `10:00`, one-fifth of the window has passed (` paceFraction = 20%`, so the white tick sits at `20%`).\n\nIf you have already used `40%` by then, your burn rate is **2x** the sustainable pace (`rate = 2.0`). At that speed, your entire quota will bottom out `5 / 2 = 2.5` hours after the window started—at **`11:30`**.\n\nSo on each `Leap EDGE` card:\n\n`rate > 1.15`), the bar shifts color and lights up a red pill: `▲ RUNS OUT 11:30`.`⏱ LASTS TO RESET`.\nWith a single glance, you immediately know whether to route the next heavy task to another AI subscription.\n\nAll of this came out of iterating back and forth with **Gemini 4 Argon** while designing and tuning the implementation.\n\nI already had a 22 KB vanilla HTML/CSS/JS web dashboard (`?mode=edge`). My initial idea was to wrap it in **Tauri v2 (Rust + system WebView)** as a desktop widget for macOS and Linux.\n\nHowever, this widget isn't used like a normal app: you don't open it for five minutes and close it—it stays pinned to your desktop all day as a background monitor.\n\nAfter looking into how macOS handles WebView processes, I decided not to put a WebView in the default path:\n\n| Dimension | Electron | Tauri v2 (Rust + WKWebView) | Leap EDGE (Swift Dual-Engine Universal Binary) | \n|---|---|---|---|\n| **Binary size** | ~220 MB | ~6 MB ( `target/` build cache ~800 MB) | **483 KB** (`arm64` +`x86_64` combined) | \n| **Persistent processes** | 4+ (Chromium) | 3 ( `Host` +`WebKit.WebContent` +`GPU` ) | **1** (pure CoreGraphics by default, zero WebKit) | \n| **Background wakeups & App Nap** | High idle drain | 1s JS `setInterval` clock keeps waking IPC | **300s data poll + 60s clock tick (with 5s tolerance)** | \n| **macOS desktop integration** | Needs plugins | Requires `objc2` FFI for low-level window flags | **Native 1-line desktop-level pinning & `👻 Click-Through`** | \n\nAccording to [Apple's WebKit `WKProcessPool` documentation](https://developer.apple.com/documentation/webkit/wkprocesspool) and the [Apple App Nap Power Efficiency Guide](https://developer.apple.com/library/archive/documentation/Performance/Conceptual/power_efficiency_guidelines_osx/AppNap.html), simply instantiating a `WKWebView` spawns separate web-content and rendering subprocesses; on top of that, a 1-second JavaScript `setInterval` for a live clock keeps waking the rendering pipeline.\n\nJust to draw five fixed-format dark quota cards, the default path doesn't need a browser engine running 24/7.\n\nSo we built a **dual-engine switch** inside a single `leap-edge.swift` file:\n\n`/api/usage` JSON and draws the five cards (Copilot, AGY, Claude Pro/Team, Codex) plus live macOS Menu Bar indicators using AppKit and `NSBezierPath`. Idle CPU stays at `window.ignoresMouseEvents = true` so mouse clicks pass straight through to the Terminal or IDE behind it.`WKWebView` (🌐 Web Mode)`removeFromSuperview()` and sets the instance to `nil`, returning all WebKit subprocess memory to the OS.\nWith both Macs covered, I also have two Ubuntu machines on my desk: a **ThinkPad X1 Carbon**, and a **Surface Pro 7** used for demos and meetings.\n\nOn Linux, we applied the exact same philosophy—a single-file, zero-third-party-dependency `leap-edge.py` that supports two modes:\n\n`leap-edge.py --status` and `--json`)`--gui`)\nLooking back at this two-day build, the biggest win wasn't saving a few dozen megabytes of RAM—it was clarifying two things:\n\nThanks for reading.", "url": "https://wpnews.pro/news/building-a-multi-agent-token-usage-widget-in-under-500-kb", "canonical_source": "https://dev.to/gde/building-a-multi-agent-token-usage-widget-in-under-500-kb-1fih", "published_at": "2026-10-23 00:51:00+00:00", "updated_at": "2026-10-23 01:11:58.323332+00:00", "lang": "en", "topics": ["ai-tools", "developer-tools", "ai-agents", "ai-products"], "entities": ["Google Antigravity", "Gemini", "Claude Code", "OpenAI Codex", "GitHub Copilot", "Tauri", "Electron", "Apple"], "also_reported_by": [], "alternates": {"html": "https://wpnews.pro/news/building-a-multi-agent-token-usage-widget-in-under-500-kb", "markdown": "https://wpnews.pro/news/building-a-multi-agent-token-usage-widget-in-under-500-kb.md", "text": "https://wpnews.pro/news/building-a-multi-agent-token-usage-widget-in-under-500-kb.txt", "jsonld": "https://wpnews.pro/news/building-a-multi-agent-token-usage-widget-in-under-500-kb.jsonld"}}