Skip to content

Conversation

@cj-elevate
Copy link

@cj-elevate cj-elevate commented Dec 1, 2025

Summary

  • Set shell: true in spawn() to support Windows .cmd executables
  • Replace deprecated -p/--prompt flag with positional prompt
  • Add -y flag for non-interactive YOLO mode
  • NEW: Add workingDirectory parameter for cross-drive access on Windows

Problem

Issue 1: Windows spawn fails
On Windows, gemini is installed as gemini.cmd which requires shell: true to execute properly via Node's spawn(). Without this, the MCP fails with:

Error executing ask-gemini: Failed to spawn command: spawn gemini ENOENT

Issue 2: Deprecated flag conflict
The -p flag is deprecated and causes conflicts when used with positional prompts in newer Gemini CLI versions (v0.18+):

Cannot use both a positional prompt and the --prompt (-p) flag together

Issue 3: Windows multi-drive limitation
Gemini CLI locks workspace to the launch directory. On Windows with multiple drives (C:/, D:/, E:/), users couldn't access files across drives.

Solution

  1. Changed shell: false to shell: true in commandExecutor.ts
  2. Replaced -p flag usage with positional prompt argument
  3. Added -y flag for YOLO mode (required for non-interactive use)
  4. Added workingDirectory parameter that sets cwd in spawn, allowing users to specify which drive to access

Usage

// Access C: drive
ask-gemini({ prompt: "List files in C:/Users", workingDirectory: "C:/" })

// Access D: drive  
ask-gemini({ prompt: "Analyze D:/project/code.ts", workingDirectory: "D:/" })

Testing

Tested on Windows 11 with Gemini CLI v0.18.4 via Claude Code MCP integration.

- Set shell: true in spawn() to support Windows .cmd executables
- Replace deprecated -p/--prompt flag with positional prompt
- Add -y flag for non-interactive YOLO mode

On Windows, gemini is installed as gemini.cmd which requires shell: true
to execute properly. The -p flag is deprecated and causes conflicts when
used with positional prompts in newer Gemini CLI versions.

Tested on Windows 11 with Gemini CLI v0.18.4
@gemini-code-assist
Copy link

Summary of Changes

Hello @cj-elevate, 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 significantly improves the robustness and cross-platform compatibility of the Gemini CLI integration. It addresses critical issues for Windows users by enabling proper execution of .cmd files and updates the command argument handling to accommodate changes in the Gemini CLI, specifically replacing a deprecated prompt flag with a positional argument. Additionally, it ensures non-interactive operation by including the -y flag, making the integration more reliable across different environments and CLI versions.

Highlights

  • Windows Compatibility: The spawn() function now uses shell: true to correctly execute .cmd executables on Windows, resolving ENOENT errors that previously prevented the Gemini CLI from running.
  • Deprecated Flag Replacement: The -p/--prompt flag has been replaced with a positional prompt argument to align with changes in newer Gemini CLI versions (v0.18+) and avoid conflicts.
  • Non-interactive Mode: The -y flag (YOLO mode) is now consistently added to command arguments to support non-interactive use of the Gemini CLI.
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.

Copy link

@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 correctly addresses Windows compatibility issues by enabling a shell for command execution and updates the code to use a positional prompt instead of the deprecated -p flag, which is a good improvement. My review includes a critical security suggestion to limit the use of shell: true to Windows only, reducing the risk of command injection on other platforms. I've also pointed out an opportunity to refactor some duplicated code to improve the long-term maintainability of the geminiExecutor.

const childProcess = spawn(command, args, {
env: process.env,
shell: false,
shell: true,

Choose a reason for hiding this comment

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

high

Enabling shell: true unconditionally can introduce security vulnerabilities if the command or arguments are not properly sanitized, especially on non-Windows platforms where it might not be necessary. Since this change is intended for Windows compatibility, it's safer to enable the shell only when running on Windows. This minimizes the potential attack surface of command injection.

Suggested change
shell: true,
shell: process.platform === "win32",

Comment on lines +90 to +95
const args = ['-y']; // YOLO mode for non-interactive
if (model) { args.push(CLI.FLAGS.MODEL, model); }
if (sandbox) { args.push(CLI.FLAGS.SANDBOX); }

// Ensure @ symbols work cross-platform by wrapping in quotes if needed
const finalPrompt = prompt_processed.includes('@') && !prompt_processed.startsWith('"')
? `"${prompt_processed}"`
: prompt_processed;

args.push(CLI.FLAGS.PROMPT, finalPrompt);

// Use positional prompt (not -p flag which is deprecated)
args.push(prompt_processed);

Choose a reason for hiding this comment

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

medium

The logic for constructing the arguments array is nearly identical here and in the catch block (lines 104-111). This duplication can lead to maintenance issues, where a change in one place might not be reflected in the other. To improve maintainability and reduce redundancy, consider extracting this logic into a single helper function.

- Add workingDirectory parameter to ask-gemini tool
- Pass cwd to spawn() to control Gemini's workspace directory
- Enables accessing files on any Windows drive (C:/, D:/, E:/, etc.)

This solves the Windows multi-drive limitation where Gemini workspace is
locked to the launch directory. Users can now specify which drive root
to use as the working directory, giving full read access to that drive.

Example:
  workingDirectory: "C:/" → access C: drive files
  workingDirectory: "D:/" → access D: drive files
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