Skip to content

fix: avoid word splitting by space for windows shell commands (#7781)#7810

Merged
DOsinga merged 1 commit intoblock:mainfrom
0xfk0:fk0/goose-7781
Mar 11, 2026
Merged

fix: avoid word splitting by space for windows shell commands (#7781)#7810
DOsinga merged 1 commit intoblock:mainfrom
0xfk0:fk0/goose-7781

Conversation

@0xfk0
Copy link
Contributor

@0xfk0 0xfk0 commented Mar 11, 2026

The problem: when running shell-commands on Windows, Goose splits command to words by spaces and when passes every word as a separate argument to command interpreter (cmd.exe).

For example, when model tries to call a command: find /I "word1 word2" *.txt this command passed to command interpreter as (each line is a separate argument):

  • cmd.exe
  • /C
  • find
  • /I
  • "word1
  • word2"
  • *.txt

Command interpreter (cmd.exe) just passes discrete arguments as is to find program. So instead of one argument find program accepts a string which is split into two argument. This causes following errors.

Generally, this bug prevents using Goose on Windows (majority of commmands issued by the model include double quotes). Due to this bug model cannot use PowerShell, cannot use quoted file names, etc...

The root cause of the issue is with how command line is constructed:

let mut command = tokio::process::Command::new("cmd");
command.arg("/C").arg(command_line);

Even though command_line is passed as a single argument, if it contains spaces and quotes, the way Windows processes command line arguments can still cause issues with quote parsing.

Solution:

here's a Windows-specific method in tokio:process::Command called raw_arg:

raw_arg Available on Windows only.
Append literal text to the command line without any quoting or escaping.
This is useful for passing arguments to cmd.exe /c, which doesn't follow
CommandLineToArgvW escaping rules.

Now command line arguments for example shown above looks as:

  • cmd.exe
  • /C
  • find /I "word1 word2" *.txt

Issue fixed.

Summary

Type of Change

  • Feature
  • Bug fix
  • Refactor / Code quality
  • Performance improvement
  • Documentation
  • Tests
  • Security fix
  • Build / Release
  • Other (specify below)

AI Assistance

  • This PR was created or reviewed with AI assistance

Testing

Related Issues

Relates to #ISSUE_ID
Discussion: LINK (if any)

Screenshots/Demos (for UX changes)

Before:

After:

…7781)

The problem: when running shell-commands on Windows, Goose splits
command to words by spaces and when passes every word as a separate
argument to command interpreter (cmd.exe).

For example, when model tries to call a command: `find /I "word1 word2" *.txt`
this command passed to command interpreter as (each line is a separate argument):

  - `cmd.exe`
  - `/C`
  - `find`
  - `/I`
  - `"word1`
  - `word2"`
  - `*.txt`

Command interpreter (cmd.exe) just passes discrete arguments as is to
`find` program. So instead of one argument `find` program accepts a
string which is split into two argument. This causes following errors.

Generally, this bug prevents using Goose on Windows (majority of
commmands issued by the model include double quotes). Due to this
bug model cannot use PowerShell, cannot use quoted file names, etc...

The root cause of the issue is with how command line is constructed:

```rust
let mut command = tokio::process::Command::new("cmd");
command.arg("/C").arg(command_line);
```

Even though `command_line` is passed as a single argument, if it contains spaces
and quotes, the way Windows processes command line arguments can still cause issues
with quote parsing.

Solution:

here's a Windows-specific method in tokio:process::Command called `raw_arg`:

> __raw_arg__ Available on Windows only.
> Append literal text to the command line without any quoting or escaping.
> This is useful for passing arguments to `cmd.exe /c`, which doesn't follow
> `CommandLineToArgvW` escaping rules.

Now command line arguments for example shown above looks as:

  - `cmd.exe`
  - `/C`
  - `find /I "word1 word2" *.txt`

Issue fixed.

Signed-off-by: Kirill Frolov <k.frolov@samsung.com>
@DOsinga DOsinga added this pull request to the merge queue Mar 11, 2026
@DOsinga
Copy link
Collaborator

DOsinga commented Mar 11, 2026

thanks!

Merged via the queue into block:main with commit c30b606 Mar 11, 2026
20 checks passed
lifeizhou-ap added a commit that referenced this pull request Mar 12, 2026
* main: (270 commits)
  test(acp): align provider and server test parity (#7822)
  fix(acp): register MCP extensions when resuming a session (#7806)
  fix(goose): load .gitignore in prompt_manager for hint file filtering (#7795)
  fix: remap max_completion_tokens to max_tokens for OpenAI-compatible providers (#7765)
  fix(openai): preserve Responses API tool call/output linkage (#7759)
  chore(deps): bump @hono/node-server from 1.19.9 to 1.19.11 in /evals/open-model-gym/mcp-harness (#7687)
  fix: return ContextLengthExceeded when prompt exceeds effective KV cache size (#7815)
  feat: MCP Roots support (#7790)
  fix(google): use `includeThoughts/part.thought` for thinking handling (#7593)
  refactor: simplify tokenizer initialization — remove unnecessary Result wrapper (#7744)
  Fix model selector showing wrong model in tabs (#7784)
  Stop collecting goosed stderr after startup (#7814)
  fix: avoid word splitting by space for windows shell commands (#7781) (#7810)
  Simplify and make it not break on linux (#7813)
  Add preferred microphone selection  (#7805)
  Remove dependency on posthog-rs (#7811)
  feat: load hints in nested subdirs (#7772)
  feat(acp): add read tool and delegate filesystem I/O to ACP clients (#7668)
  Support secret interpolation in streamable HTTP extension URLs (#7782)
  More logging for command injection classifier model training (#7779)
  ...
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