Desktop Apps
10 min readUpdated: October 2026

Build a Desktop AI Coding Agent with Electron and TypeScript

Technical Review: Smoke Monkey Core Architecture Team
Tested on Node.js 18+ & BunTypeScript 5.x
Quick Answer & Executive Definition

Build a Desktop AI Coding Agent with Electron and TypeScript: Designed as a zero-dependency, open-source TypeScript architecture under the MIT License with native Model Context Protocol (MCP) support and deterministic phase state machines.

Key Architectural Takeaways

Electron + Smoke Monkey Architecture

In an Electron app, Smoke Monkey runs in the main process where it has full Node.js API access. The renderer process (React/HTML UI) communicates via IPC:

  1. Renderer sends user instructions via ipcRenderer.send('agent:run', instruction).
  2. Main process creates an agent and streams events back via ipcMain.on / mainWindow.webContents.send.
  3. Renderer renders the live event stream in the chat UI.

This separation keeps the heavy agent execution away from the UI thread, maintaining a responsive interface.

electron/main.tstypescript
import { app, BrowserWindow, ipcMain } from 'electron';
import { createAgent } from 'smoke-monkey-harness';
let mainWindow: BrowserWindow;
ipcMain.on('agent:run', async (event, { instruction, workspacePath }) => {
const agent = createAgent({
provider: 'ollama',
model: 'qwen2.5-coder:7b',
workspacePath,
autoApprove: false, // Surface permission gates to UI
});
// Stream events to renderer
agent.on('tool.started', (e) =>
mainWindow.webContents.send('agent:event', { type: 'tool.started', data: e.data })
);
agent.on('model.streaming', (e) =>
mainWindow.webContents.send('agent:event', { type: 'streaming', chunk: e.data.chunk })
);
await agent.run(instruction);
mainWindow.webContents.send('agent:event', { type: 'completed' });
});

Configuring Ollama for Fully Offline Operation

To ship a fully offline desktop agent:

  1. Bundle Ollama in your app's resources, or guide users to install it via the onboarding flow.
  2. Pull the model at first launch if not already cached: run ollama pull qwen2.5-coder:7b via Electron's child_process.
  3. Set `OLLAMA_HOST` in the Electron main process environment before initializing the agent.
  4. Detect Ollama availability and show a setup screen if the local server isn't running.

Use qwen2.5-coder:7b for the best offline coding performance

At 7B parameters, it fits comfortably in 8GB of RAM and runs at 20-40 tokens/second on Apple Silicon — fast enough for a responsive desktop experience.

Google Search Questions & Answers

Frequently Asked Questions

Q:Can I package an Electron agent app for both macOS and Windows?

Yes. Smoke Monkey Harness has no platform-specific native dependencies. Use electron-builder to produce .dmg and .exe artifacts from the same TypeScript codebase.

Q:How do I handle the permission gate UI in Electron?

Subscribe to permission.requested events in the main process and use ipcMain to forward them to the renderer. Render a dialog in React and send the user's decision back via ipcRenderer.send.

Related Alternatives & Comparisons

Build with Smoke Monkey Harness

Zero dependencies. 24 built-in tools. Human-in-the-loop safety. 100% open source under the MIT License.

npm install smoke-monkey-harness