CLAUDE.md
CLAUDE.mdCLAUDE.mdroot
Quality
96/100
Scores the file, not the repository.Length
1,454 words
34 headings · 9 code blocksRepository
122k
— · pushed 0 days agoLast changed
3 days ago
First indexed 3 days ago.1# Electron Development Guide23## Running node_modules binaries45**Never use `npx`.** It is considered dangerous because it can silently fetch and execute arbitrary packages from the registry. Always run binaries through one of these safer mechanisms instead:671. **Preferred** — spawn the executable directly from `node_modules/.bin/<tool>` (or the platform equivalent on Windows). This is what `script/lint.js` does for `oxlint`.82. **Acceptable** — invoke via `yarn <tool>` or `yarn run <tool>`, which resolves to the locally installed version without the registry fallback that `npx` performs.910This rule applies to shell commands you run yourself and to any scripts you author or modify in this repo.1112## Project Overview1314Electron is a framework for building cross-platform desktop applications using web technologies. It embeds Chromium for rendering and Node.js for backend functionality.1516## Directory Structure1718```text19electron/ # This repo (run `e` commands here)20├── shell/ # Core C++ application code21│ ├── browser/ # Main process implementation (107+ API modules)22│ ├── renderer/ # Renderer process code23│ ├── common/ # Shared code between processes24│ ├── app/ # Application entry points25│ └── services/ # Node.js service integration26├── lib/ # TypeScript/JavaScript library code27│ ├── browser/ # Main process JS (47 API implementations)28│ ├── renderer/ # Renderer process JS29│ └── common/ # Shared JS modules30├── patches/ # Patches for upstream dependencies31│ ├── chromium/ # ~159 patches to Chromium32│ ├── node/ # ~48 patches to Node.js33│ └── ... # Other targets (v8, boringssl, etc.)34├── spec/ # Test suite (1189+ TypeScript test files)35├── docs/ # API documentation and guides36├── build/ # Build configuration37├── script/ # Build and automation scripts38└── chromium_src/ # Chromium source overrides39../ # Parent directory is Chromium source40```4142## Build Tools Setup4344Electron uses `@electron/build-tools` for development. The `e` command is the primary CLI.4546**Installation:**4748```bash49npm i -g @electron/build-tools50```5152**Configuration location:** `~/.electron_build_tools/configs/`5354## Essential Commands5556### Configuration Management5758| Command | Purpose |59|---------|---------|60| `e init <name> --root=<path> --bootstrap testing` | Create new build config and sync |61| `e use <name>` | Switch to a different build configuration |62| `e show current` | Display active configuration name |63| `e show configs` | List all available configurations |6465### Build & Development Loop6667| Command | Purpose |68|---------|---------|69| `e sync` | Fetch/update all source code and apply patches |70| `e sync --3` | Sync with 3-way merge (required for Chromium upgrades) |71| `e build` | Build Electron (runs GN + Ninja) |72| `e build -k 999` | Build and continue on errors (up to 999) |73| `e build -t <target>` | Build specific target (e.g., `electron:node_headers`) |74| `e start` | Run the built Electron executable |75| `e start --version` | Verify Electron launches and print version |76| `e test` | Run the test suite |77| `e debug` | Run Electron in debugger (lldb on macOS, gdb on Linux) |7879### Patch Management8081| Command | Purpose |82|---------|---------|83| `e patches <target>` | Export patches for a target (chromium, node, v8, etc.) |84| `e patches all` | Export all patches from all targets |85| `e patches --list-targets` | List available patch targets |8687## Typical Development Workflow8889```bash90# 1. Ensure you're on the right config91e show current9293# 2. Sync to get latest code94e sync9596# 3. Make your changes in shell/ or lib/ or ../9798# 4. Build99e build100101# 5. Test your changes (Leave the user to do this, don't run these commands unless asked)102e start103e test104105# 6. If you modified patched files in Chromium:106cd .. # Go to Chromium repo107git add <files>108git commit -m "description of change"109cd electron110e patches chromium # Export the patch111```112113## Patches System114115Electron patches upstream dependencies (Chromium, Node.js, V8, etc.) to add features or modify behavior.116117**How patches work:**118119```text120patches/{target}/*.patch → [e sync --3] → target repo commits121 ← [e patches] ←122```123124**Patch configuration:** `patches/config.json` maps patch directories to target repos.125126**Key rules:**127128- Fix existing patches 99% of the time rather than creating new ones129- Preserve original authorship in TODO comments130- Never change TODO assignees (`TODO(name)` must retain original name)131- Each patch file includes commit message explaining its purpose132133**Creating/modifying patches:**1341351. Make changes in the target repo (e.g., `../` for Chromium)1362. Create a git commit1373. Run `e patches <target>` to export138139**Fixing patch conflicts on an existing PR:**140141If asked to fix a patch conflict on a branch that already has an open PR, check the PR's failed **Apply Patches** CI run for an `update-patches` artifact before running `e sync` locally. CI has already performed the 3-way merge and exported the resolved patch diff — applying it is much faster than a full local sync.142143```bash144# Find the failed Apply Patches run for the PR and download the artifact145gh run list --repo electron/electron --branch <pr-branch> --workflow "Apply Patches" --limit 1146gh run download <run-id> --repo electron/electron --name update-patches147148# Apply the CI-generated fix, then push149git am update-patches.patch150git push151```152153If no artifact exists (e.g. the 3-way merge itself failed), fall back to `e sync --3` and resolve manually.154155## Testing156157**Test location:** `spec/` directory158159**Running tests:**160161```bash162e test # Run full test suite163```164165**Test frameworks:** Mocha, Chai, Sinon166167## Build Configuration168169**GN build arguments:** Located in `build/args/`:170171- `testing.gn` - Debug/testing builds172- `release.gn` - Release builds173- `all.gn` - Common arguments for all builds174175**Main build file:** `BUILD.gn`176177**Feature flags:** `buildflags/buildflags.gni`178179## Chromium Upgrade Workflow180181When working on the `roller/chromium/main` branch to upgrade Chromium activate the "Electron Chromium Upgrade" skill.182183## Node.js Upgrade Workflow184185When working on the `roller/node/main` branch to upgrade Node.js activate the "Electron Node.js Upgrade" skill.186187## Pull Requests188189PR bodies must always include a `Notes:` section as the **last line** of the body. This is a consumer-facing release note for Electron app developers — describe the user-visible fix or change, not internal implementation details. Use `Notes: none` if there is no user-facing change.190191### PR Labeling (write-access only)192193When the user has write access to `electron/electron`, add these labels when creating PRs:194195**Semver label** — one of:196197- `semver/none` — build changes, refactors, CI, or anything with no end-user impact198- `semver/patch` — backwards-compatible bug fixes199- `semver/minor` — backwards-compatible new functionality200- `semver/major` — incompatible API changes201202**Backport target labels** — add `target/{N}-x-y` for each supported release branch the change should land on. Default policy:203204- **Bug fixes** — backport to all active release lines _except the oldest_205- **Security fixes** — backport to all active release lines _including the oldest_206- **Features (semver/minor) and breaking changes (semver/major)** — no backport labels; main-only by default207208To find which release branches are active, check label colors — active `target/*` labels use color `#ad244f`, older/EOL ones use `#ededed`:209210```bash211gh label list --repo electron/electron --search target/ --json name,color --jq '.[] | select(.color == "ad244f") | .name'212```213214## Code Style215216**C++:** Follows Chromium style, enforced by clang-format217**TypeScript/JavaScript:** [oxlint](https://oxc.rs/docs/guide/usage/linter) configuration in `.oxlintrc.json`218219**Linting:**220221```bash222npm run lint # Run all linters223npm run lint:js # Run oxlint over all JS/TS/MJS sources224npm run lint:clang-format # C++ formatting225npm run lint:api-history # Validate API history YAML blocks in docs226```227228## Key Files229230| File | Purpose |231|------|---------|232| `BUILD.gn` | Main GN build configuration |233| `DEPS` | Dependency versions and checkout paths |234| `patches/config.json` | Patch target configuration |235| `filenames.gni` | Source file lists by platform |236| `package.json` | Node.js dependencies and scripts |237238## Environment Variables239240| Variable | Purpose |241|----------|---------|242| `GN_EXTRA_ARGS` | Additional GN arguments (useful in CI) |243| `ELECTRON_RUN_AS_NODE=1` | Run Electron as Node.js |244245## Useful Git Commands for Chromium246247```bash248# Find CL that changed a file249cd ..250git log --oneline -10 -- {file}251git blame -L {start},{end} -- {file}252253# Look for Chromium CL reference in commit254git log -1 {commit_sha} # Find "Reviewed-on:" line255256# Find which patch affects a file257grep -l "filename.cc" patches/chromium/*.patch258```259260## CI/CD261262GitHub Actions workflows in `.github/workflows/`:263264- `build.yml` - Main build workflow265- `pipeline-electron-lint.yml` - Linting266- `pipeline-segment-electron-test.yml` - Testing267268## Common Issues269270**Patch conflict during sync:**271272- Use `e sync --3` for 3-way merge273- Check if file was renamed/moved upstream274- Verify patch is still needed275276**Build error in patched file:**277278- Find the patch: `grep -l "filename" patches/chromium/*.patch`279- Match existing patch style (#if 0 guards, BUILDFLAG conditionals, etc.)280281**Remote build issues:**282283- Try `e build --no-remote` to build locally284- Check reclient/siso configuration in your build config285
Also in electron/electron
Diff this repo’s formatsOne repository carrying more than one format is the comparison this product exists for: does anyone actually write different content in each file, or is one a copy of the other?
| Repository | Format | Stack | Covers | Score | Changed |
|---|---|---|---|---|---|
| electron/electron.github/copilot-instructions.md · 122k | Copilot instructions | buildteststyletypes+3 | 86/100 | 3 days ago |
Similar configs
Same format, overlapping stack, ranked by quality.
| Repository | Format | Stack | Covers | Score | Changed |
|---|---|---|---|---|---|
| livewire/livewireCLAUDE.md · 24k | CLAUDE.md | setupbuildteststyle+4 | 100/100 | 3 days ago | |
| bagisto/bagistoCLAUDE.md · 28k | CLAUDE.md | setupbuildteststyle+5 | 100/100 | 3 days ago | |
| microsoft/playwrightCLAUDE.md · 94k | CLAUDE.md | buildtestlint-formatstyle+7 | 100/100 | 3 days ago | |
| Adit-Jain-srm/NightmareNetCLAUDE.md · 45 | CLAUDE.md | buildtestlint-formatstyle+6 | 100/100 | 3 days ago | |
| nimbalyst/nimbalystpackages/android/CLAUDE.md · 1.4k | CLAUDE.md | setupbuildstylearch+2 | 100/100 | 3 days ago | |
| filamentphp/filamentCLAUDE.md · 32k | CLAUDE.md | buildtestlint-formatstyle+7 | 100/100 | 3 days ago | |
| dotCMS/corecore-web/CLAUDE.md · 950 | CLAUDE.md | teststylearchtesting-strategy+3 | 100/100 | 3 days ago | |
| dotCMS/coreCLAUDE.md · 950 | CLAUDE.md | setupbuildteststyle+7 | 99/100 | 3 days ago |
