AGENTS.md templates / Electron

AGENTS.md template for Electron

A ready AGENTS.md for an Electron desktop app in TypeScript. It separates main, preload and renderer for the agent, lists the commands, and blocks the security shortcuts agents take to make an error disappear.

Updated 3 December 2026 · 60 lines · 2.7 KB
AGENTS.md
# AGENTS.md

An Electron desktop app written in TypeScript, with separate main, preload and renderer code.

## Commands

- `npm start`: launch the app in development
- `npm run lint`: ESLint
- `npx tsc --noEmit`: type-check
- `npm test`: run the tests
- `npm run make`: build installers. Ask before running

## Project structure

- `src/main/`: main process: windows, menus, file system, native APIs
- `src/preload/`: preload scripts. The only bridge between the two sides
- `src/renderer/`: the UI. Plain web code, no Node access
- `src/shared/`: IPC channel names and payload types used by both sides

## Rules for agents

- Never change `contextIsolation`, `nodeIntegration` or `sandbox` in `webPreferences`.
- The preload script exposes named functions through `contextBridge`. Never expose `ipcRenderer` itself.
- No Node.js or Electron imports in `src/renderer/`. Add an IPC call instead.
- No synchronous file or IPC calls in the main process. Use `ipcMain.handle` with `ipcRenderer.invoke`.

## Conventions

### Electron

- Main process and renderer process are different worlds. Never import renderer code in main or vice versa.
- Keep `contextIsolation: true` and `nodeIntegration: false`. Expose APIs to the renderer via a `preload.js` contextBridge, nothing else.
- All IPC is typed — define channel names and payload types once, share between main and preload.
- File system, shell, and native APIs belong in main. Renderer calls them via IPC, never directly.
- Ship with auto-updates (electron-updater) from day one — retrofitting is painful.
- Sign and notarize for macOS; without notarization your app is blocked by Gatekeeper.

### TypeScript

- Prefer `type` for object shapes, `interface` only when extending third-party types.
- Never use `any` — use `unknown` and narrow, or write a proper type.
- No non-null assertions (`!`) except in tests or when a type guard just ran.
- Use `readonly` for props, return types, and array params that don't mutate.
- Prefer discriminated unions over enums. Enums only for stable public APIs.
- Import types with `import type { ... }` to avoid runtime import cost.

## Avoid

- Enabling `nodeIntegration` in the renderer — huge security hole.
- Loading remote URLs with `nodeIntegration` or without `sandbox`.
- Declaration-merging global namespaces.
- Using `Function`, `Object`, or `{}` as types.

## Guardrails

- Never commit secrets, API keys, or credentials. If you spot one in a diff, stop and flag it.
- Do not invent dependencies. If a package is not already in the manifest, confirm before adding it.
- When a command fails, read the actual error. Do not retry blindly or bypass with `--force`.
- Prefer editing existing files over creating new ones.
- Run the tests and the linter before saying a task is done, and say what you ran.

The commands and folders are the common defaults for Electron. Change them to match your project before you commit the file: an agent will run exactly what is written here.

Make it yours in the generator Add your database, test runner and other tools, pick your coding style, and get matching CLAUDE.md, Cursor and Copilot files. Free, runs in your browser. Already have instruction files? Context Doctor scans your repo and shows which files each coding tool is silently not loading. $19.

How to use it

Save the file as AGENTS.md in the root of your repository and commit it. Then check each tool you use:

ToolWhat to do
Claude CodeReads AGENTS.md only when no CLAUDE.md exists in or above the folder. If you have a CLAUDE.md, put @AGENTS.md on its first line.
CursorReads AGENTS.md from the project root, in the desktop app and the terminal. In the app, rules in .cursor/rules must be .mdc files. The terminal reads only plain .md files there.
CodexReads AGENTS.md from the root down to the folder you are in, with a shared 32 KiB limit across all of them.
GitHub CopilotReads AGENTS.md on some surfaces only. Keep a .github/copilot-instructions.md as well if your team relies on Copilot.

Details and sources: the AGENTS.md compatibility matrix.

What agents get wrong in Electron projects

These are the reasons the “Rules for agents” section says what it says.

Turning on nodeIntegration

When require fails in the renderer, the quick fix agents choose is nodeIntegration: true and contextIsolation: false. That gives any script on the page full access to the computer.

Exposing all of ipcRenderer

Agents pass the whole ipcRenderer object through the preload script. The page can then send any message on any channel.

Node code in the renderer

Agents import fs or path in UI code because it is all TypeScript in one repo. It fails at runtime, and the usual fix is the first mistake above.

Blocking the main process

Synchronous file calls and ipcRenderer.sendSync freeze every window while they run.

Questions

Where does AGENTS.md go in a Electron project?

In the root of the repository, next to your manifest file. Tools read it from the folder you start them in and, for most tools, from parent folders too.

Does Claude Code read AGENTS.md?

Only when there is no CLAUDE.md in or above the working folder. If you already have a CLAUDE.md, keep it and make its first line @AGENTS.md so both tools read the same rules.

How long should the file be?

Short enough that every line is something the agent would get wrong without it. Codex shares a 32 KiB budget across all the AGENTS.md files it loads, and long files get followed less closely by every tool.

Which build tool does this assume?

The commands match Electron Forge. If you use electron-vite or electron-builder, replace the Commands section with the scripts from your package.json. The process and security rules are the same for all of them.

Templates for other stacks

Next.jsReactNode.js and TypeScriptExpressPythonFastAPIDjangoGoRuby on RailsLaravelVueSvelteKitAstroNestJSFastifyHonoFlaskRustSupabase