Skip to content

project rulesFrontendelectrontypescript

Electron Rules

Project rules for Electron apps: isolated renderers, a narrow preload API, validated IPC, safe packaging and signed auto-updates.

npx workspacetemplates add electron-rules --tool claude-code

Writes 1 file to your project root

CLAUDE.mdadd to your file19 lines · 1.3 KBFile
# Project rules: Electron

## Process boundaries
- The renderer is untrusted. Keep `contextIsolation: true`, `nodeIntegration: false` and `sandbox: true` on every BrowserWindow. Never turn them off to fix a bug; fix the design.
- Main owns files, shell, network and native APIs. The renderer asks main through IPC.
- Set a strict Content-Security-Policy. Load only local files or known HTTPS origins, and deny `window.open` and navigation with `setWindowOpenHandler` and `will-navigate`.

## Preload and IPC
- Expose a small, named API with `contextBridge.exposeInMainWorld`. Never expose `ipcRenderer` itself or a generic "invoke any channel" function.
- Use `ipcMain.handle` with `ipcRenderer.invoke`. Validate every argument in main (a Zod schema) and check `event.senderFrame` origin before acting.
- Define channel names and payload types once in a shared TypeScript file.

## Packaging and updates
- Package with Electron Forge or electron-builder. Sign and notarize release builds; never ship unsigned.
- Use `electron-updater` or the built-in autoUpdater over HTTPS with signature checks. Keep devtools off in production.

## Quality
- Store settings with `app.getPath('userData')`. Log through one module.
- Run `tsc --noEmit`, lint, unit tests and a Playwright Electron smoke test before finishing.

What it does

Electron apps mix a web page with full system access, so the main risk is a compromised renderer. These rules keep that boundary tight and make every cross-process call explicit.

They also cover shipping: how to package, sign and update the app, so the agent does not leave debug flags or broad permissions in a release build.

Example

you › Let the user pick a folder and show its file names

agent › The agent adds a validated dialog:openFolder handler in main, exposes one preload method, and renders the list without enabling Node in the renderer.

Questions

Why not enable nodeIntegration for convenience?
Any script injected into the page would then run with full system access. The preload bridge avoids that.
Does it cover macOS signing?
It requires signing and notarization; the exact certificate setup depends on your CI.
  • .NET Blazor Rules

    Project rulescsharp

    Free
  • Angular Rules

    Project rulesangular

    Free
  • Astro Rules

    Project rulesastro

    Free
  • Next.js App Router Rules

    Project rulesnextjs

    Free