Home › Electron › Electron app Windsurf rules

Electron app Windsurf rules

Windsurf rules for secure Electron 44 apps: context isolation, preload bridges, typed IPC, and packaging.

WindsurfElectron

How to use

Save this as .windsurf/rules/electron.md in your repository root, commit it, and your agent will pick it up automatically. Edit the commands to match your project.

.windsurf/rules/electron.mdDownload  
---
trigger: glob
globs: src/main/**,src/preload/**,src/renderer/**,electron/**
---

# Electron (44)

## Process boundaries
- Main process (`src/main`): windows, native APIs, file system, IPC handlers. Renderer (`src/renderer`): UI only, no Node access.
- Keep defaults: `contextIsolation: true`, `sandbox: true`, `nodeIntegration: false`. Never turn them off.
- The preload script exposes a minimal, typed API with `contextBridge.exposeInMainWorld('api', {...})`. Expose specific functions (`api.openFile()`), never `ipcRenderer` itself.

## IPC
- Request/response via `ipcRenderer.invoke` + `ipcMain.handle`; channel names are constants shared in `src/shared/ipc.ts` with typed payloads.
- Validate every argument in the main process and check `event.senderFrame` origin for sensitive handlers.

## Security
- Strict Content-Security-Policy; load the app from `file://` or a custom protocol, not remote URLs.
- Block unexpected navigation (`will-navigate`) and new windows (`setWindowOpenHandler`), opening external links with `shell.openExternal` after an allowlist check.
- No `remote` module, no `eval`, no `webSecurity: false`.

## Packaging
- Build with the existing tool (Electron Forge or electron-builder); keep native deps rebuilt for the Electron ABI.
- Auto-update only over HTTPS with signed builds.

## Done when
Typecheck, lint and unit tests pass, and `npm run make` (or `npm run build`) produces an app that launches.

Related rules

Web accessibility (WCAG 2.2) rules

Windsurf rules for building accessible web UIs to WCAG 2.2 AA: semantics, keyboard, focus, contrast, and testing.

WindsurfAccessibility

Django Windsurf rules

Windsurf rules for Django 5.2 LTS projects: apps, models and migrations, ORM performance, forms, and tests.

WindsurfDjango

Documentation writing rules

Windsurf rules for writing and updating READMEs, docstrings, ADRs, and changelogs alongside code changes.

WindsurfAgent workflows

Electron app AGENTS.md

AGENTS.md for Electron desktop apps (Electron Forge or electron-vite): process layout, IPC contracts, and release safety.

AGENTS.mdElectron

Get new rules weekly

One email a week: fresh rule files, agent tips, and what's changing in Cursor, Claude Code and Copilot. Free, unsubscribe anytime.

Opens the Rulestack Newsletter on beehiiv in a new tab. Or subscribe directly on beehiiv.