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.

More: all Electron rules · all Windsurf rules

Related rules

Electron app AGENTS.md

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

AGENTS.mdElectron

Tauri 2 desktop app Windsurf rules

Windsurf rules for Tauri 2 desktop/mobile apps: Rust commands, capabilities and permissions, and a web frontend.

WindsurfTauri

Tauri 2 Rust backend rules

Cursor rules for the Rust side of Tauri 2 apps: commands, typed errors, state, plugins, and capability files.

CursorTauri

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

Agent safety guardrails Windsurf rules

Always-on Windsurf rules that stop agents from running destructive, costly, or externally visible actions without approval.

WindsurfAny stack

Ansible Windsurf rules

Windsurf rules for Ansible playbooks and roles: FQCN modules, idempotency, check mode, vault secrets, and ansible-lint.

WindsurfAnsible

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.