Electron Main Process
Relevant source files
The following files were used as context for generating this wiki page:
The Electron Main Process serves as the backbone of the Claude Cowork application, acting as the primary entry point and orchestrator for the system. It is responsible for lifecycle management, window creation, native system integration, and secure Inter-Process Communication (IPC) between the underlying OS and the React-based user interface.
Operating in a Node.js environment, the main process handles privileged operations that are restricted in the renderer process, such as system resource polling, directory selection through native dialogs, and managing AI agent sessions via the Anthropic SDK.
Sources: src/electron/main.ts, package.json:5-6
Architecture and Initialization
The main process initializes when the Electron application is ready. It configures the application environment, sets up global event listeners for termination signals, and creates the primary BrowserWindow.
Lifecycle Management
The process monitors system signals (SIGTERM, SIGINT, SIGHUP) and Electron-specific events (before-quit, window-all-closed) to ensure a clean teardown. This cleanup phase involves unregistering global shortcuts, stopping resource polling, and terminating any active AI sessions or development servers.
The diagram above illustrates the startup and shutdown sequence managed by the main process.
Sources: src/electron/main.ts:44-93
Window Configuration
The main window is configured with specific dimensions and security settings. Notably, it utilizes a preload script to bridge the main and renderer processes securely.
| Property | Value / Source | Description |
|---|---|---|
| Width / Height | 1200 / 800 | Default startup size. |
| Min Dimensions | 900 x 600 | Minimum allowable window size. |
| Preload Path | getPreloadPath() | Location of the IPC bridge script. |
| Title Style | hiddenInset | Native macOS-style traffic light integration. |
| Background | #FAF9F6 | Initial window background color. |
Sources: src/electron/main.ts:74-87, src/electron/pathResolver.ts:5-12
Inter-Process Communication (IPC)
The main process exposes several typesafe handles and listeners to the renderer via the ipcMain module. These handles allow the UI to request system information or trigger native actions.
IPC Security
To prevent malicious events, the main process validates the origin of every IPC call. It ensures that incoming requests originate from the expected local file or the authorized development port.
Sources: src/electron/util.ts:12-32
Key IPC Handlers
| Handler Key | Functionality | Return Type |
|---|---|---|
getStaticData | Retrieves system hardware info (CPU, RAM). | StaticData |
select-directory | Opens native folder picker dialog. | string | null |
generate-session-title | Uses AI to generate a title from user input. | string |
save-api-config | Persists API keys and settings to disk. | { success: boolean } |
client-event | Processes session actions (start, stop, etc.). | void |
Sources: src/electron/main.ts:98-150, types.d.ts:16-26
System Resource Monitoring
The main process includes a utility module for real-time resource tracking. It polls the operating system at a fixed interval (500ms) to provide the UI with performance metrics.
- CPU Usage: Calculated via
os-utils. - Memory: Tracks RAM usage percentage.
- Storage: Monitors disk usage for the root/system partition.
Sources: src/electron/test.ts:9-40
Environment and Path Resolution
The process manages paths dynamically to support both development (Vite) and production (packaged app) environments.
// src/electron/pathResolver.ts:14-16
export function getUIPath() {
return path.join(app.getAppPath(), '/dist-react/index.html');
}
The getEnhancedEnv function builds the system environment variables required for the Claude Agent SDK, merging standard process environment variables with stored API configurations (API keys, base URLs).
Sources: src/electron/pathResolver.ts, src/electron/libs/util.ts:7-22
Summary
The Electron Main Process in claude-cowork functions as a secure gateway between the AI SDK and the user interface. By managing session lifecycles, validating IPC frames, and handling native OS dialogs, it enables a robust desktop experience for AI-assisted coding and file management.