Skip to content

fix: normalize PATH env key casing to prevent tool detection failures on Windows#1966

Open
cpc5622 wants to merge 3 commits intoAndyMik90:developfrom
cpc5622:fix/windows-path-env-casing-detection
Open

fix: normalize PATH env key casing to prevent tool detection failures on Windows#1966
cpc5622 wants to merge 3 commits intoAndyMik90:developfrom
cpc5622:fix/windows-path-env-casing-detection

Conversation

@cpc5622
Copy link

@cpc5622 cpc5622 commented Mar 17, 2026

Summary

On some Windows versions (e.g. Windows 10), { ...process.env } produces the native key casing Path instead of PATH. Since getAugmentedEnv() accesses env.PATH, the value is undefined, causing the entire original system PATH to be silently dropped.

This leads to detection failures for any tools installed in non-standard locations. For example, when Node.js is installed on a non-C drive (e.g. D:\NodeJs\), detecting Claude Code fails with:

'node' is not recognized as an internal or external command

This happens because claude.cmd (the npm-generated wrapper) internally invokes node, which is no longer on the subprocess PATH. The same issue affects gh, python, and any other tool not in the hardcoded COMMON_BIN_PATHS.

Root Cause

const env = { ...process.env }; // On Win10: key is 'Path', not 'PATH'
let currentPath = env.PATH || ''; // undefined — entire system PATH lost!

Debug output confirming the bug:

PATH-like keys in process.env: [ 'Path' ]
env.PATH (after spread): undefined
env.Path (after spread): C:\Windows\system32;...;D:\NodeJs\;D:\NodeJs\node_global\;...

After getAugmentedEnv() runs, the env object contains dual keys (Path + PATH), where PATH only has hardcoded COMMON_BIN_PATHS (all C-drive) and the original Path with user-configured paths is ignored.

Fix

Reuse the existing normalizeEnvPathKey() from agent/env-utils.ts (which was already written to solve this exact casing issue for agent spawning) in both getAugmentedEnv() and getAugmentedEnvAsync(), right after spreading process.env.

Changes:

  • Import normalizeEnvPathKey from ./agent/env-utils
  • Call normalizeEnvPathKey(env) after { ...process.env } in both sync and async versions
  • This ensures the PATH key is consistently uppercase before any access

Test plan

  • On Windows 10 with Node.js installed on a non-C drive (e.g. D:\NodeJs\), verify Claude Code is detected successfully
  • On Windows 10, verify gh and python are detected when installed in non-standard locations
  • On Windows 11 / macOS / Linux, verify no regression in tool detection
  • Run npm run typecheck — passes
  • Run npm run lint — passes (no new errors)

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Bug Fixes
    • Resolved an issue on Windows where the system PATH could be lost or misrecognized during startup. This improves reliability when launching the app, ensures external commands and tools remain accessible, and increases compatibility across different Windows versions.

… on Windows

On some Windows versions (e.g. Windows 10), `{ ...process.env }` spreads
environment variables with the native key casing 'Path' instead of 'PATH'.
Since `getAugmentedEnv()` accesses `env.PATH`, this resulted in `undefined`,
silently dropping the entire original system PATH.

This caused detection failures for any tools installed in non-standard
locations. For example, when Node.js is installed on a non-C drive
(e.g. D:\NodeJs\), detecting Claude Code would fail with:

  'node' is not recognized as an internal or external command

because `claude.cmd` (npm-generated wrapper) internally invokes `node`,
which was no longer on the subprocess PATH. The same issue affected gh,
Python, and other tools not in COMMON_BIN_PATHS.

The fix reuses the existing `normalizeEnvPathKey()` from agent/env-utils.ts
to ensure the PATH key is consistently uppercase before any access, applied
to both `getAugmentedEnv()` and `getAugmentedEnvAsync()`.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request addresses a critical issue on Windows where the PATH environment variable's casing could lead to its value being dropped, consequently breaking tool detection. By consistently normalizing the PATH key to uppercase, the changes ensure that system-wide and user-defined paths are correctly recognized, significantly improving the robustness of tool discovery across various environments.

Highlights

  • Resolved Windows PATH casing issue: Fixed a bug where process.env on Windows 10 could return Path instead of PATH, causing the system PATH to be dropped and leading to tool detection failures.
  • Ensured consistent PATH key casing: Implemented the normalizeEnvPathKey utility function in both getAugmentedEnv and getAugmentedEnvAsync to standardize the PATH environment variable key to uppercase, preventing undefined values.
  • Improved tool detection reliability: Enhanced the reliability of tool detection, especially for applications like Node.js, gh, and Python installed in non-standard locations on Windows.
Changelog
  • apps/desktop/src/main/env-utils.ts
    • Imported normalizeEnvPathKey from ./agent/env-utils.
    • Added a call to normalizeEnvPathKey(env) within the getAugmentedEnv function to normalize the PATH key casing.
    • Added a call to normalizeEnvPathKey(env) within the getAugmentedEnvAsync function to normalize the PATH key casing.
Activity
  • No human activity has occurred on this pull request yet.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Mar 17, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro

Run ID: f51d833e-2bcf-41a3-9681-a474e0c8dac9

📥 Commits

Reviewing files that changed from the base of the PR and between 8cca49e and 7aa3694.

📒 Files selected for processing (1)
  • apps/desktop/src/main/env-utils.ts

📝 Walkthrough

Walkthrough

Adds normalization of the PATH-like environment key on Windows to env-utils.ts. The normalizeEnvPathKey function is imported and invoked at the start of both getAugmentedEnv and getAugmentedEnvAsync to ensure correct PATH availability across Windows versions and prevent data loss when spreading process.env.

Changes

Cohort / File(s) Summary
Windows PATH Normalization
apps/desktop/src/main/env-utils.ts
Adds import of normalizeEnvPathKey and invokes it at the start of getAugmentedEnv and getAugmentedEnvAsync to normalize PATH environment key on Windows and prevent PATH data loss.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

Poem

🐰 I hopped through envs both near and far,
Found PATH keys scattered like a jar,
I stitched them neat with gentle art,
So processes start with every part,
Happy trails for each PATH dart!

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and specifically describes the main change: normalizing PATH environment key casing to fix tool detection failures on Windows, which matches the core objective of the PR.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
📝 Coding Plan
  • Generate coding plan for human review comments

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request effectively addresses a critical bug on Windows where the system PATH was being dropped due to case-sensitivity issues with the PATH environment variable. The fix is clean and correctly utilizes the existing normalizeEnvPathKey utility. My feedback focuses on improving maintainability by making the new comments more concise and removing duplication, as the detailed context is already well-captured in the pull request description.

cpc5622 and others added 2 commits March 17, 2026 14:52
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
@AndyMik90 AndyMik90 self-assigned this Mar 18, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants