# Add Persistent User Settings to an Electron App from a Linear Issue

Yes. An agent reads the Linear issue, adds a settings store in your Electron main process, a typed IPC bridge and a settings screen, and opens a tested pull request.

[Run this on Rush](https://cloud.getrush.ai/run/add-persistent-settings/electron/). Opens the console with this prompt ready to send, in a Project that has your repository.

## What the agent does

The agent starts from the issue and the repository in its own cloud sandbox and reads how the processes talk before it adds state. In an app like electron-react-boilerplate (Electron `^44.4.0`, electron-vite, React with `react-router-dom`, Jest `^30.5.1`, electron-builder), `src/main/main.ts` creates a 1024 by 728 `BrowserWindow` with `src/main/preload.ts` as its preload, builds the menu from `src/main/menu.ts`, starts `electron-updater` through `src/main/updates.ts` only when packaged, and has one IPC handler, an `ipc-example` ping that replies with pong. The preload exposes `window.electron.ipcRenderer` with `sendMessage`, `on` and `once` over a `Channels` type that allows only `'ipc-example'`, and `src/renderer/preload.d.ts` types `window.electron` from it. `src/renderer/App.tsx` is a `MemoryRouter` with a single `Hello` route. Nothing is persisted anywhere, which is the gap the issue describes.

Then it reads how the project tests main-process code, because the store has to be testable the same way. `src/__tests__/updates.test.ts` runs under `/** @jest-environment node */`, mocks `electron`, `electron-updater` and `electron-log` with `jest.mock`, and calls `jest.resetModules()` between tests; `src/__tests__/App.test.tsx` renders `App` with Testing Library under jsdom. `jest.config.js` maps assets and styles, pulls `ts-jest` from `.erb/tooling`, and runs `.erb/scripts/check-build-exists.ts` first. `.github/workflows/test.yml` runs on macOS, Windows and Ubuntu with Node 24: `npm ci`, `npm run package`, `npm run lint`, `npm exec tsc -- --noEmit`, `npm test`, and then the smoke test `.erb/scripts/smoke-test.cjs` under `xvfb-run` on Linux.

The change lands in the files that own it. `src/main/settings.ts` defines the settings type with the fields the issue names and their defaults, reads them from a JSON file under `app.getPath('userData')`, writes atomically through a temporary file and rename, and returns the defaults when the file is missing or unparseable, logging the parse error through `electron-log`. `main.ts` registers `ipcMain.handle('settings:get')` and `ipcMain.handle('settings:set')` and validates the incoming object against the type before writing. `preload.ts` gains a `settings` object with `get` and `set` built on `ipcRenderer.invoke`, and the `Channels` type grows to cover the new names, so `preload.d.ts` picks the API up without change. The renderer gets a `/settings` route in `App.tsx` with a form bound to those calls and a link to it from the home route.

Last, it tests and runs the full CI sequence. `src/__tests__/settings.test.ts` follows the `updates.test.ts` pattern: `electron` mocked so `app.getPath` returns a temporary directory, a round trip of `set` then `get`, a corrupt file falling back to defaults, and a write that fails leaving the previous file intact. `App.test.tsx` gains a case that navigates to the settings route and finds the form. The agent runs `npm run lint`, `npm exec tsc -- --noEmit`, `npm test`, `npm run build`, and `xvfb-run --auto-servernum npm run test:smoke` to show the app still starts, fixing what fails before it pushes.

## Start it with one API call

`POST https://api.phoenix.so/o/{org}/sessions`

```json
{
  "agent": "claude",
  "input": "A Linear issue labeled agent says: \"Settings are lost every time the app restarts. Persist user settings (the fields are listed in this issue) on disk, expose them to the renderer safely, and add a settings screen.\" Before changing anything, read src/main/main.ts, src/main/preload.ts, src/renderer/preload.d.ts, src/renderer/App.tsx, jest.config.js and the existing tests under src/__tests__, and note how IPC is exposed today and how main-process modules are tested. Add a settings module in the main process that stores a typed object as JSON under the app's userData path, writes atomically, and falls back to defaults on a missing or corrupt file; register invoke-style IPC handlers for get and set with validation; extend the preload bridge and its Channels type so the renderer gets a typed settings API without touching preload.d.ts; add a settings route and form in the renderer. Write node-environment tests for the module in the style of the updater test and a renderer test for the route. Run the lint script, the type check, the test suite, the build and the Linux smoke test under xvfb until they pass, then open a pull request that links back to the issue.",
  "resources": [
    {
      "url": "https://github.com/your-org/your-app"
    }
  ]
}
```

1. **Get an API key.** In the console, open Settings, then API keys, and create a key for your org. Send it in the Authorization header as a Bearer token.
2. **Send the request.** POST the body in request.json to https://api.phoenix.so/o/{org}/sessions, with your repository as the resources URL. The run starts in its own cloud sandbox.
3. **Read what came back.** Follow the run on its live stream or wait for the run.completed webhook, then read the result and its trajectory.

## What comes back

What comes back is a pull request on its own branch with a diff over `src/main/settings.ts`, `src/main/main.ts`, `src/main/preload.ts`, `src/renderer/App.tsx`, a new settings component, and two test files under `src/__tests__/`. The description names the file path under `userData` where settings are written, the fields and defaults, and the two IPC channels, and says that `preload.d.ts` did not need to change because it types the bridge from the preload itself.

The transcript carries the proof: the `npm run lint`, `npm exec tsc -- --noEmit` and `npm test` runs with their output, including any that failed before a fix, the `npm run build` output, and the smoke test under `xvfb-run` showing the window opened. If the repository's test workflow runs on pull requests, the same steps run there on all three operating systems.

Before merging, a reviewer checks that the renderer can only call the two settings channels and not arbitrary IPC, that the set handler rejects unknown keys and wrong types, that the write is atomic so a crash mid-write cannot leave a truncated file, and that defaults are sensible on a first launch.

## Run it on every Linear issue labelled agent

In the console, an automation with a `linear` trigger on `linear.issue.labeled` and the label `agent` starts one run per labelled issue in the Project's repository. The trigger adds the issue's text after the saved prompt, so the settings fields and their defaults come from the issue while the prompt stays fixed. Changes made by an app integration never fire it, and the automation's `max_runs_per_hour` bounds how many runs a burst of labelling can start.

From your own server, the same job is one `POST /o/{org}/sessions` per issue, with the repository in `resources` and the issue's `https://linear.app/<workspace>/issue/<ID>` URL beside it so Rush reads the issue through your Linear connection. A `webhook_url` on the API key receives `run.completed` or `run.failed` for every run that key starts, with the `session_url` to read the pull request link from.

## Why run it on Rush?

An Electron change crosses three processes, and the proof involves a type check, a Jest run in two environments, a packaging build and an app that actually opens, which on Linux means a virtual display. In a Rush sandbox the agent installs the native toolchain the boilerplate's `postinstall` needs, runs the whole sequence from `.github/workflows/test.yml` including the smoke test under `xvfb-run`, and keeps every attempt in the transcript.

A label in Linear becomes a reviewable pull request whose reasoning is on the record: the transcript shows the agent reading the preload bridge and the updater test before it writes, and every lint, type-check, test and build run with its output. Several labelled issues can run at once, each in its own sandbox on its own branch, and each pull request links back to the issue that asked for it.

## Frequently asked questions

### Does it add a dependency like electron-store?

Not by default. The store is a small module over `fs` and `app.getPath('userData')`, which keeps the main bundle free of a new package and is easy to test with the project's existing Jest mocks. If the issue asks for `electron-store`, the agent uses it and says so.

### Is the renderer able to read or write arbitrary files through this?

No. The preload exposes only `settings.get` and `settings.set` through `ipcRenderer.invoke` on two named channels, and the main-process handler validates the object before writing. The renderer never sees a path.

### Where is the settings file stored?

In the directory Electron returns for `app.getPath('userData')`, which differs per operating system and per app id (`org.erb.ElectronReact` in the boilerplate's `build` config). The pull request names the exact file name.

### How are the main-process tests run without a real Electron?

The same way `updates.test.ts` does it: a node Jest environment with `electron` mocked, so `app.getPath` points at a temporary directory. The round trip, the corrupt-file fallback and the atomic write are exercised against real files there.

## More Electron jobs

- [Add a Single-Instance Lock to an Electron App](https://getrush.ai/run/add-single-instance-lock/electron/)
- [Add a Splash Screen to an Electron App](https://getrush.ai/run/add-splash-screen/electron/)
- [Add a System Tray Icon to an Electron App](https://getrush.ai/run/add-tray-icon/electron/)

## The same job on other stacks

- [Persist User Settings in a Tauri App](https://getrush.ai/run/add-persistent-settings/tauri/)
- [Persist User Settings in a Textual App](https://getrush.ai/run/add-persistent-settings/textual/)

## More jobs like this: Turn a Linear label into a PR

- [Add PHPStan Static Analysis to a PHP Library](https://getrush.ai/run/add-phpstan/php/)

## Keep reading

- [How a Rush run works on your repository, from request to pull request](https://getrush.ai/cloud/)
- [Compare cloud agents, agent sandboxes and AI code review](https://getrush.ai/compare/)
- [Rush pricing: Free, Pro and Max](https://getrush.ai/pricing/)
