goose icon indicating copy to clipboard operation
goose copied to clipboard

[Windows] Failed to spawn Gemini CLI: "batch file arguments are invalid"

Open iyang1016 opened this issue 1 month ago • 2 comments

Describe the bug

I am encountering an error when Goose attempts to spawn the Gemini CLI on Windows. The process fails immediately with a "batch file arguments are invalid" error.

It seems like Goose is trying to execute the .cmd shim for the Gemini CLI (installed via npm) but the arguments or the spawn method are not compatible with how Windows handles batch file execution.

To Reproduce

Steps to reproduce the behavior:

  1. Install the Gemini CLI via npm globally on Windows (npm install -g @google/gemini-cli or similar).
  2. Configure Goose to use the Gemini CLI provider.
  3. Run a command that triggers the Gemini CLI.
  4. See error.

Expected behavior

Goose should successfully spawn the Gemini CLI process and communicate with it.

Error Logs

Ran into this error: Request failed: Failed to spawn Gemini CLI command '"C:\Users\yano\AppData\Roaming\npm\gemini.cmd"': batch file arguments are invalid. Make sure the Gemini CLI is installed and available in the configured search paths..

Desktop Information

  • OS: Windows
  • Goose Version: [Insert version if known]
  • Gemini CLI Path: C:\Users\yano\AppData\Roaming\npm\gemini.cmd

iyang1016 avatar Nov 28 '25 14:11 iyang1016

same problem here

mogomaa2025 avatar Nov 28 '25 21:11 mogomaa2025

Apologies for not submitting a PR.

The root cause is that cmd does not handle multiline correctly in parameters. And since gemini.cmd is receiving a multiline prompt, everything crashes (hint - batch file arguments are invalid)

The fix is sanitizing the "\n"s from the multiline prompts (probably, since my rust environment is not up and I have not tested it thoroughly, therefore something along the lines of this diff)

diff --git a/crates/goose/src/providers/gemini_cli.rs b/crates/goose/src/providers/gemini_cli.rs
index 4c2fa9ebd07..daf0966e886 100644
--- a/crates/goose/src/providers/gemini_cli.rs
+++ b/crates/goose/src/providers/gemini_cli.rs
@@ -98,7 +98,15 @@ impl GeminiCliProvider {
             cmd.arg("-m").arg(&self.model.model_name);
         }

-        cmd.arg("-p").arg(&full_prompt).arg("--yolo");
+        if cfg!(windows) {
+            let sanitized_prompt = full_prompt
+                .replace("\r\n", "\\n")
+                .replace('\n', "\\n");
+
+            cmd.arg("-p").arg(&sanitized_prompt).arg("--yolo");
+        } else {
+            cmd.arg("-p").arg(&full_prompt).arg("--yolo");
+        }

         cmd.stdout(Stdio::piped()).stderr(Stdio::piped());

tko39 avatar Dec 03 '25 15:12 tko39