Skip to content

feat(cleaner): add Environment Variable & PATH cleaner#80

Merged
dbfx merged 5 commits intomainfrom
feat/environment-cleaner
Mar 26, 2026
Merged

feat(cleaner): add Environment Variable & PATH cleaner#80
dbfx merged 5 commits intomainfrom
feat/environment-cleaner

Conversation

@dbfx
Copy link
Contributor

@dbfx dbfx commented Mar 26, 2026

Summary

  • Adds a new Environment category to the System Cleaner that detects orphaned PATH entries and developer environment variables pointing to non-existent directories
  • Scans 40+ known dev-tool variables (JAVA_HOME, GOROOT, CARGO_HOME, ANDROID_HOME, CUDA_PATH, etc.) across user and system scopes
  • On Windows, cleans by modifying the registry and broadcasting WM_SETTINGCHANGE; on macOS/Linux, reports entries for manual removal (no auto-editing of shell configs)
  • Includes safety guards: refuses to write an empty PATH, re-reads registry before each write, proper error handling for permission-denied

Details

Scanning (all platforms):

  • Reads PATH entries from registry (Windows) or process environment (Unix) and checks each directory with existsSync
  • Expands %VAR% references before checking (Windows)
  • Checks only single-directory env vars — excludes path-lists (NODE_PATH, PERL5LIB) and URIs (DOCKER_HOST) to avoid false positives

Cleaning (Windows only):

  • Removes individual orphaned PATH entries via reg add with REG_EXPAND_SZ
  • Deletes orphaned env vars via reg delete
  • Broadcasts WM_SETTINGCHANGE so running applications pick up changes without restart
  • System-scope entries require admin elevation

Files changed:

  • src/shared/enums.ts — new Environment CleanerType
  • src/shared/channels.ts — new IPC channels
  • src/main/ipc/environment-cleaner.ipc.ts — scanner and cleaner logic (new file)
  • src/main/ipc/index.ts — register IPC handler
  • src/preload/index.ts — expose API to renderer
  • src/renderer/src/pages/CleanerPage.tsx — add category with Variable icon
  • src/renderer/src/pages/DashboardPage.tsx — include in dashboard quick-scan
  • src/renderer/src/locales/en/cleaner.json — locale strings
  • src/shared/channels.test.ts — update enum count assertion

Test plan

  • All 1892 existing tests pass
  • TypeScript compiles with no errors in changed files
  • Manual: run scan on Windows — verify orphaned PATH entries detected
  • Manual: run scan on Windows — verify orphaned env vars (e.g. old JAVA_HOME) detected
  • Manual: clean on Windows — verify entries removed from registry and WM_SETTINGCHANGE broadcast
  • Manual: verify system-scope entries show "needs elevation" when not admin
  • Manual: run scan on macOS/Linux — verify orphaned entries reported as scan-only

🤖 Generated with Claude Code

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>
Copy link

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 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".

dbfx and others added 3 commits March 26, 2026 09:18
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>
@dbfx dbfx merged commit 7ad17bd into main Mar 26, 2026
8 checks passed
@dbfx dbfx deleted the feat/environment-cleaner branch March 26, 2026 07:20
Copy link

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 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) => {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge 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 👍 / 👎.

Comment on lines +222 to +224
await execNativeUtf8('reg', [
'delete', key, '/v', entry.variable, '/f'
], { timeout: 10000 })

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge 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 👍 / 👎.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant