Electron Desktop App Development with Claude Code: Cross-Platform Guide
Electron desktop app development using Claude Code. Cross-platform guide. Includes practical code examples.
Building Electron Desktop Apps With Claude Code
Electron lets you build desktop apps for Windows, macOS, and Linux using web technologies. With Claude Code, you can efficiently design the main and renderer processes and configure security settings.
Project Structure
Electron Forge + React + TypeScript
> Create an Electron Forge + React + TypeScript project structure.
> Use the Vite bundler.
// src/main.ts
import { app, BrowserWindow, ipcMain } from 'electron';
import path from 'path';
const createWindow = () => {
const mainWindow = new BrowserWindow({
width: 1200,
height: 800,
webPreferences: {
preload: path.join(__dirname, 'preload.js'),
contextIsolation: true,
nodeIntegration: false,
sandbox: true,
},
});
if (MAIN_WINDOW_VITE_DEV_SERVER_URL) {
mainWindow.loadURL(MAIN_WINDOW_VITE_DEV_SERVER_URL);
} else {
mainWindow.loadFile(
path.join(__dirname, `../renderer/${MAIN_WINDOW_VITE_NAME}/index.html`)
);
}
};
app.whenReady().then(createWindow);
Designing IPC Communication
Secure Inter-Process Communication
> Design IPC communication for file operations.
> Use contextBridge for a secure implementation.
// src/preload.ts
import { contextBridge, ipcRenderer } from 'electron';
contextBridge.exposeInMainWorld('fileAPI', {
readFile: (filePath: string) =>
ipcRenderer.invoke('file:read', filePath),
writeFile: (filePath: string, content: string) =>
ipcRenderer.invoke('file:write', filePath, content),
selectFile: () =>
ipcRenderer.invoke('dialog:openFile'),
});
// src/main.ts (register handlers)
import { ipcMain, dialog } from 'electron';
import fs from 'fs/promises';
ipcMain.handle('file:read', async (_, filePath: string) => {
return fs.readFile(filePath, 'utf-8');
});
ipcMain.handle('file:write', async (_, filePath: string, content: string) => {
await fs.writeFile(filePath, content, 'utf-8');
return { success: true };
});
ipcMain.handle('dialog:openFile', async () => {
const result = await dialog.showOpenDialog({
properties: ['openFile'],
filters: [
{ name: 'Text files', extensions: ['txt', 'md', 'json'] },
],
});
return result.canceled ? null : result.filePaths[0];
});
Security Settings
Security settings are especially important in Electron apps. Ask Claude Code to “configure this following security best practices,” and it will properly set up things like Content Security Policy and sandbox configuration.
// Set CSP headers
session.defaultSession.webRequest.onHeadersReceived((details, callback) => {
callback({
responseHeaders: {
...details.responseHeaders,
'Content-Security-Policy': [
"default-src 'self'; script-src 'self'; style-src 'self' 'unsafe-inline'"
],
},
});
});
Auto Update
You can also implement auto-updates with electron-updater. From GitHub Releases integration to the update UI, Claude Code can handle the whole thing.
Summary
With Claude Code, you can efficiently implement Electron’s secure IPC design and cross-platform build configuration. For a comparison with Tauri, see the Tauri development guide, and for TypeScript techniques, see TypeScript tips.
For more on Electron, see the official Electron documentation.
Free PDF: Claude Code Cheatsheet in 5 Minutes
Just enter your email and we'll send you the single-page A4 cheatsheet right away.
We handle your data with care and never send spam.
Level up your Claude Code workflow
50 battle-tested prompt templates you can copy-paste into Claude Code right now.
About the Author
Masa
Engineer obsessed with Claude Code. Runs claudecode-lab.com, a 10-language tech media with 2,000+ pages.
Related Posts
7 Deployment Checks Before You Publish a Multilingual Claude Code Article Every Day
A practical checklist for publishing daily multilingual Claude Code articles without missing locales, breaking CTAs, or shipping stale pages.
Codex Automations for Content Ops: A Daily Revenue Workflow for Claude Code Sites
Use Codex Automations to turn analytics, article updates, CTA improvements, deployment, and verification into a daily revenue workflow.
Claude Code × GCP Cloud Functions Complete Guide | Rapid Serverless Function Development
Streamline GCP Cloud Functions with Claude Code. Implement HTTP/Pub/Sub/Firestore triggers, local testing, and deployment automation with real-world code examples from Masa's experience.
Related Products
50 Battle-Tested Claude Code Prompt Templates
Copy, paste, ship. 50 production-ready prompts.
Use proven prompts for code review, refactoring, testing, documentation, debugging, architecture, and incident response.
The Complete Claude Code Setup & Configuration Guide
From install to team-ready workflow.
A practical guide to installation, CLAUDE.md, hooks, MCP servers, permissions, IDE setup, and CI/CD workflows.