nanocoder icon indicating copy to clipboard operation
nanocoder copied to clipboard

[Feature] Configurable Windows shell for execute_bash (PowerShell / pwsh)

Open Esquetta opened this issue 1 week ago • 2 comments

Description

Let Windows users choose which shell execute_bash runs commands in (cmd, Windows PowerShell or pwsh), and tell the model which one it is.

Use Case

On Windows execute_bash always runs %ComSpec% (cmd.exe): source/services/bash-executor.ts spawns process.env.ComSpec || 'cmd.exe'. The tool is called execute_bash and its parameter is described as "The bash command to execute", so models write bash, and when that fails they usually fall back to PowerShell, not to cmd syntax. Neither works in cmd.exe.

Several open Windows reports come from this one fixed choice:

  • #2341: the system prompt names the wrong shell when started from Git Bash
  • #2344: non-ASCII output is decoded with the wrong code page
  • #2239: a cd inside a command never reaches the file tools

PowerShell is the shell most Windows developers actually use, it ships with every supported Windows version, and it gives the model one consistent syntax for quoting, pipelines and environment variables.

Proposed Solution

A setting in the nanocoder block of agents.config.json, Windows only, for example:

{ "nanocoder": { "shell": { "windows": "pwsh" } } }
  • cmd stays the default, so nothing changes for existing users.
  • powershell runs powershell.exe -NoProfile -NonInteractive -Command <script>, pwsh the same with pwsh.exe.
  • If the chosen shell is not installed, fall back to cmd and say so once.
  • The "Default Shell" line in the system prompt reports the shell the tool really uses (this would also settle #2341 for the cmd case).
  • PowerShell is started with UTF-8 output encoding, so its output decodes correctly without touching the cmd path.

Alternatives Considered

  • Detect Git Bash and use it. Closest to what models write, but it is not installed everywhere and path translation between MSYS and Windows paths adds its own bugs.
  • Make PowerShell the default. Better results for most users, but it changes behaviour for everyone on Windows. Could be a later step once the option has been used for a while.
  • Fix each cmd.exe report on its own. Still worth doing, but it leaves models writing syntax cmd does not understand.

Additional Context

  • [x] I have searched existing issues to ensure this is not a duplicate
  • [x] This feature aligns with the project's goals (local-first AI assistance)

I work on Windows 11 and can test this against cmd, Windows PowerShell 5.1 and PowerShell 7. I'd be glad to take it if the direction looks right; I'd rather agree on scope here before writing code. Related: #2349.

Implementation Notes (optional)

  • source/utils/shell-args.ts already switches arguments on isWindowsCmd; it would gain a PowerShell branch.
  • The same shell choice exists in source/custom-tools/handler.ts and the lifecycle hooks, which build cmd.exe-specific quoting. I'd leave those on cmd in a first PR and only switch execute_bash, to keep the change small.
  • The permission and safety checks that parse commands (for example the rm guard) are written for sh/cmd syntax and would need a look for PowerShell equivalents (Remove-Item -Recurse). That is probably the part that needs the most discussion.

Esquetta avatar Nov 23 '26 08:11 Esquetta

Issue triage: possible duplicate of #1280

@Esquetta — this looks like it covers the same ground as #1280 (open): [Feature] Add configurable shell for executebash.

This is already tracked as issue #1280, which asks for the same thing: a user-selectable shell for execute_bash on Windows instead of the hardcoded cmd.exe, for the same reason (models write bash or PowerShell syntax that cmd.exe does not understand). The individual symptoms you link (wrong shell in the system prompt, non-ASCII output decoding, cd not reaching the file tools) are separate bug issues and are best tracked and fixed there.

If this is wrong, reply here saying why and a maintainer will take it from there. Otherwise it will be closed in 14 days.


Automated issue triage. It flags; it never closes on first sight. A maintainer can remove the label to dismiss this.

github-actions[bot] avatar Nov 23 '26 08:11 github-actions[bot]

The triage is right: this is the same request as #1280, which I missed when searching (I looked for "powershell" and "pwsh"). Closing in favour of that one; I'll add the PowerShell notes there.

Esquetta avatar Nov 23 '26 08:11 Esquetta