# Runtime and Lifecycle Codex++ loads a runtime from the user data directory. That runtime discovers tweaks, starts main-process tweaks, injects a renderer preload into Codex windows, and starts renderer tweaks from that preload. ## Processes | Process | What runs there | |---|---| | Main | Tweak discovery, main-scoped tweak loading, disk storage, MCP sync, tweak filesystem IPC, Codex window APIs, store install/update checks. | | Renderer preload | Settings injection, renderer-scoped tweak loading, DOM access, React fiber helpers, renderer storage, renderer IPC wrapper. | ## Scope Loading Rules | Manifest `scope` | Main host | Renderer host | |---|---:|---:| | `renderer` | no | yes | | `main` | yes | no | | `both` | yes | yes | | omitted | yes | yes | Set `scope` explicitly. Omitted scope is currently equivalent to `both`. ## Lifecycle ```js module.exports = { async start(api) { // Called when this process loads the tweak. }, async stop() { // Called during reload/disable/shutdown where possible. }, }; ``` Main lifecycle: - Discover tweaks under `/tweaks`. - Sync MCP servers for enabled tweaks. - Start enabled main-capable tweaks. - Stop all main tweaks on hot reload, disable/enable changes, and app shutdown. - Flush main storage during stop/shutdown. Renderer lifecycle: - Ask main for the discovered tweak list and user paths. - Skip disabled tweaks, missing entries, and `scope: "main"` tweaks. - Read tweak source through main IPC. - Evaluate the entry in the sandboxed preload context. - Call `start(api)`. - Call `stop()` during hot reload and before reloading renderer tweaks. ## Hot Reload The main process watches the tweaks directory. Changes are debounced, then the runtime: 1. Stops all main tweaks. 2. Clears cached tweak modules under the tweaks directory. 3. Re-discovers tweak manifests and entries. 4. Restarts main tweaks. 5. Broadcasts `codexpp:tweaks-changed` to renderers. 6. Renderers stop loaded renderer tweaks and start them again from fresh source. Make all mutations idempotent. Codex can also re-render its own DOM without a Codex++ hot reload. ## Cleanup Checklist Clean these in `stop()`: - DOM nodes you inserted outside Codex++ settings pages. - `