feat(cleaner): add Environment Variable & PATH cleaner#80
Conversation
Detect orphaned PATH entries and developer environment variables that point to non-existent directories after tool uninstallation. Scanning: - Windows: reads PATH and env vars from both HKCU and HKLM registry - macOS/Linux: checks process environment (scan-only, no auto-edits) - Checks 40+ known dev-tool vars (JAVA_HOME, GOROOT, CARGO_HOME, etc.) Cleaning (Windows only): - Removes orphaned PATH entries via reg.exe with re-read before write - Deletes orphaned env vars from registry - Broadcasts WM_SETTINGCHANGE so running apps pick up changes - Safety: refuses to write an empty PATH Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 499fc383f6
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
expandWinVars now receives a merged map of user+system registry variables so it can resolve cross-scope %VAR% references (e.g. a user PATH entry referencing %SystemRoot% from the system scope). Previously it only checked process.env, which could miss registry vars not yet loaded into the current process — causing valid entries to be misclassified as orphaned. Also removes GOPATH from DEV_ENV_VARS since it can legally be a path-list (semicolon/colon-separated), which would false-positive with the single-path existsSync check. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 4d1d925722
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| * references). | ||
| */ | ||
| function expandWinVars(value: string, registryVars: Map<string, string>): string { | ||
| return value.replace(/%([^%]+)%/gi, (_match, varName: string) => { |
There was a problem hiding this comment.
Expand nested Windows env references before orphan checks
expandWinVars performs only a single replace pass, so values that resolve to another %VAR% (for example JAVA_HOME=%DEVTOOLS%\jdk with DEVTOOLS=%USERPROFILE%\devtools) remain partially unexpanded. Both scanWindowsPathEntries and scanWindowsEnvVars then call existsSync on a string that still contains %...%, which marks valid entries as orphaned and can lead to deleting working PATH/env configuration.
Useful? React with 👍 / 👎.
| await execNativeUtf8('reg', [ | ||
| 'delete', key, '/v', entry.variable, '/f' | ||
| ], { timeout: 10000 }) |
There was a problem hiding this comment.
Revalidate env var state before deleting registry entries
removeWindowsEnvVar deletes by variable name without re-reading or confirming the current value still matches what was scanned. If the variable is corrected between scan and clean (e.g., user updates JAVA_HOME), this code will still remove the now-valid setting. removeWindowsPathEntry already guards against stale data by re-reading PATH, and env-var deletion needs the same safeguard.
Useful? React with 👍 / 👎.
Summary
WM_SETTINGCHANGE; on macOS/Linux, reports entries for manual removal (no auto-editing of shell configs)Details
Scanning (all platforms):
existsSync%VAR%references before checking (Windows)NODE_PATH,PERL5LIB) and URIs (DOCKER_HOST) to avoid false positivesCleaning (Windows only):
reg addwithREG_EXPAND_SZreg deleteWM_SETTINGCHANGEso running applications pick up changes without restartFiles changed:
src/shared/enums.ts— newEnvironmentCleanerTypesrc/shared/channels.ts— new IPC channelssrc/main/ipc/environment-cleaner.ipc.ts— scanner and cleaner logic (new file)src/main/ipc/index.ts— register IPC handlersrc/preload/index.ts— expose API to renderersrc/renderer/src/pages/CleanerPage.tsx— add category with Variable iconsrc/renderer/src/pages/DashboardPage.tsx— include in dashboard quick-scansrc/renderer/src/locales/en/cleaner.json— locale stringssrc/shared/channels.test.ts— update enum count assertionTest plan
🤖 Generated with Claude Code