[Windows] Failed to spawn Gemini CLI: "batch file arguments are invalid"
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:
- Install the Gemini CLI via npm globally on Windows (
npm install -g @google/gemini-clior similar). - Configure Goose to use the Gemini CLI provider.
- Run a command that triggers the Gemini CLI.
- 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
same problem here
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());