Skip to content

fix(auth): fix Gemini CLI path detection for global npm installs on Windows#6045

Closed
ehgamemo wants to merge 1 commit intoopenclaw:mainfrom
bambom:fix/windows-gemini-auth
Closed

fix(auth): fix Gemini CLI path detection for global npm installs on Windows#6045
ehgamemo wants to merge 1 commit intoopenclaw:mainfrom
bambom:fix/windows-gemini-auth

Conversation

@ehgamemo
Copy link

@ehgamemo ehgamemo commented Feb 1, 2026


Description

Problem:
OpenClaw fails to detect Gemini CLI on Windows because it cannot correctly resolve the global npm package path
structure. The relative path between the binary file and node_modules on Windows differs from Linux/macOS, which
prevents the system from reading oauth2.js to retrieve the OAuth configuration.

Changes:
I have modified extensions/google-gemini-cli-auth/oauth.ts to include specific search path logic for Windows
environments. This allows OpenClaw to correctly locate the Gemini CLI credentials file within the global npm
directory.


  • AI-assisted (Vibe-coded)
  • Fully tested on Windows 11

Greptile Overview

Greptile Summary

This PR updates extensions/google-gemini-cli-auth/oauth.ts to better locate the Gemini CLI’s bundled oauth2.js on Windows by adding additional Windows-only candidate paths derived from the resolved gemini executable path. The intent is to handle global npm install directory layouts that differ from macOS/Linux so OpenClaw can extract the OAuth client config automatically.

Confidence Score: 3/5

  • This PR is likely safe to merge, but Windows path resolution assumptions may still miss common global npm layouts.
  • Change is localized and gated on process.platform === "win32", but the new logic assumes dirname(resolvedPath) is a global npm prefix; when gemini resolves to a .cmd/.bat shim in %APPDATA%\npm, the actual node_modules root may be elsewhere, so the fix might not work for all users.
  • extensions/google-gemini-cli-auth/oauth.ts

(2/5) Greptile learns from your feedback when you react with thumbs up/down!

On Windows, the global npm node_modules structure differs from Linux/macOS. This adds the correct search paths to locate oauth2.js when installed globally via npm.
@openclaw-barnacle openclaw-barnacle bot added the extensions: google-gemini-cli-auth Extension: google-gemini-cli-auth label Feb 1, 2026
Copy link
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

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

1 file reviewed, 2 comments

Edit Code Review Agent Settings | Greptile

Comment on lines +97 to +100
if (process.platform === "win32") {
const npmBinDir = dirname(resolvedPath);
searchPaths.push(
join(
Copy link
Contributor

Choose a reason for hiding this comment

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

[P1] Windows path derivation assumes resolvedPath is the binary path

On Windows, findInPath("gemini") can resolve to gemini.cmd/gemini.bat, and realpathSync may return that wrapper path. Using dirname(resolvedPath) as npmBinDir then appending node_modules/... assumes the wrapper lives alongside a global node_modules directory (which isn't true for common npm layouts like %APPDATA%\npm\gemini.cmd with modules in %APPDATA%\npm\node_modules). This can make the added Windows search paths miss the real install location.

Consider deriving the global root via npm prefix -g / npm root -g (or walking up from resolvedPath until node_modules is found) rather than assuming dirname(resolvedPath) is the prefix.

Prompt To Fix With AI
This is a comment left during a code review.
Path: extensions/google-gemini-cli-auth/oauth.ts
Line: 97:100

Comment:
[P1] Windows path derivation assumes `resolvedPath` is the binary path

On Windows, `findInPath("gemini")` can resolve to `gemini.cmd`/`gemini.bat`, and `realpathSync` may return that wrapper path. Using `dirname(resolvedPath)` as `npmBinDir` then appending `node_modules/...` assumes the wrapper lives alongside a global `node_modules` directory (which isn't true for common npm layouts like `%APPDATA%\npm\gemini.cmd` with modules in `%APPDATA%\npm\node_modules`). This can make the added Windows search paths miss the real install location.

Consider deriving the global root via `npm prefix -g` / `npm root -g` (or walking up from `resolvedPath` until `node_modules` is found) rather than assuming `dirname(resolvedPath)` is the prefix.

How can I resolve this? If you propose a fix, please make it concise.

Comment on lines +97 to +99
if (process.platform === "win32") {
const npmBinDir = dirname(resolvedPath);
searchPaths.push(
Copy link
Contributor

Choose a reason for hiding this comment

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

[P3] Windows search paths add maintenance surface without documenting expected layout

This block hardcodes several deep package paths (@google/gemini-cli nested under another node_modules, plus dist/src/... vs dist/...). Given this is compensating for npm/global-install differences, a short comment describing the observed Windows global layout(s) being supported would make it easier to update when Gemini CLI changes packaging.

Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

Prompt To Fix With AI
This is a comment left during a code review.
Path: extensions/google-gemini-cli-auth/oauth.ts
Line: 97:99

Comment:
[P3] Windows search paths add maintenance surface without documenting expected layout

This block hardcodes several deep package paths (`@google/gemini-cli` nested under another `node_modules`, plus `dist/src/...` vs `dist/...`). Given this is compensating for npm/global-install differences, a short comment describing the observed Windows global layout(s) being supported would make it easier to update when Gemini CLI changes packaging.

<sub>Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!</sub>

How can I resolve this? If you propose a fix, please make it concise.

@openclaw-barnacle
Copy link

This pull request has been automatically marked as stale due to inactivity.
Please add updates or it will be closed.

@openclaw-barnacle openclaw-barnacle bot added the stale Marked as stale due to inactivity label Feb 15, 2026
@openclaw-barnacle openclaw-barnacle bot removed the stale Marked as stale due to inactivity label Feb 16, 2026
@vincentkoc
Copy link
Member

Thanks for opening the original fix path here.\n\nClosing this in favor of #27585, which is a clean/refactored continuation for the same root-cause family and includes expanded regression coverage for npm shim layouts.\n\nCredit to @ehgamemo for the foundational original work in this thread; #27585 explicitly carries that attribution forward.\n\nIf any scope here is missing from #27585, reply and we can reopen immediately.

@vincentkoc vincentkoc closed this Feb 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

extensions: google-gemini-cli-auth Extension: google-gemini-cli-auth

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants