Skip to content

fix: add Windows npm global path resolution for Gemini CLI OAuth (closes #30403)#46368

Closed
Br1an67 wants to merge 1 commit intoopenclaw:mainfrom
Br1an67:fix/30403
Closed

fix: add Windows npm global path resolution for Gemini CLI OAuth (closes #30403)#46368
Br1an67 wants to merge 1 commit intoopenclaw:mainfrom
Br1an67:fix/30403

Conversation

@Br1an67
Copy link
Copy Markdown
Contributor

@Br1an67 Br1an67 commented Mar 14, 2026

Summary

  • Problem: Gemini CLI OAuth fails on Windows — can't find oauth2.js in npm global path
  • What changed: Added Windows-specific npm global path pattern to extractGeminiCliCredentials
  • What did NOT change: Mac/Linux path resolution

Change Type

  • Bug fix

Linked Issue/PR

Security Impact

All No

Evidence

  • pnpm build + pnpm check + pnpm test all passing

Compatibility / Migration

  • Backward compatible? Yes

Failure Recovery

  • How to revert: revert this commit

This PR was AI-assisted (fully tested with pnpm build/check/test).

@openclaw-barnacle openclaw-barnacle bot added extensions: google-gemini-cli-auth Extension: google-gemini-cli-auth size: S labels Mar 14, 2026
@greptile-apps
Copy link
Copy Markdown
Contributor

greptile-apps bot commented Mar 14, 2026

Greptile Summary

This PR adds a Windows-specific fallback to extractGeminiCliCredentials so that Gemini CLI OAuth works even when the gemini binary is absent from PATH. When running on Windows (process.platform === "win32") and APPDATA is set, the function now resolves the package directly from %APPDATA%\npm\node_modules\@google\gemini-cli — the standard location for npm global packages on Windows. The same path is also appended (with deduplication) in resolveGeminiCliDirs for Windows installs where the binary is found in PATH but the package root isn't derivable from the shim location.

Key changes:

  • oauth.ts: Restructured early-return logic in extractGeminiCliCredentials into a three-branch if/else if/else, adding the APPDATA fallback as the middle branch; also extended resolveGeminiCliDirs with the same Windows candidate.
  • oauth.test.ts: New test overrides process.platform to "win32", sets a fake APPDATA, and confirms the credential extraction succeeds via the APPDATA path.

One minor caveat worth noting: the APPDATA path (%APPDATA%\npm\node_modules) is the default npm global prefix on Windows but is not guaranteed to be correct if the user has customized their npm prefix. This is an acceptable best-effort fallback rather than a complete solution.

Confidence Score: 4/5

  • Safe to merge — a targeted, backward-compatible Windows fallback with no risk to Mac/Linux paths.
  • The change is well-scoped (two files, one new code path) and is fully guarded by both a process.platform === "win32" check and a truthy APPDATA check, so existing Mac/Linux behavior is completely unchanged. A matching test covers the new branch end-to-end. The one limitation (hardcoded default npm prefix) is inherent to the approach and noted in the PR description; it's a best-effort fallback, not a regression.
  • No files require special attention.

Last reviewed commit: 8699be4

 openclaw#30403)

On Windows, npm global packages live under %APPDATA%\npm\node_modules but the
bin shim (.cmd) may not be in PATH or may not resolve via realpathSync like
Unix symlinks do. This adds:

1. A fallback in extractGeminiCliCredentials() that checks %APPDATA%/npm/
   node_modules/@google/gemini-cli directly when findInPath() fails on Windows.
2. An additional candidate in resolveGeminiCliDirs() for the APPDATA npm global
   path, so even when the binary IS found, the oauth2.js lookup succeeds.

Co-authored-by: Copilot <[email protected]>
@Br1an67
Copy link
Copy Markdown
Contributor Author

Br1an67 commented Mar 17, 2026

Closing to manage active PR count. Will reopen when slot is available.

@Br1an67 Br1an67 closed this Mar 17, 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 size: S

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bug: google-gemini-cli-auth OAuth fails on Windows (client_secret missing + loadCodeAssist 400)

1 participant