feat: add configurable default shell for Windows users#1498
feat: add configurable default shell for Windows users#1498Br1an67 wants to merge 1 commit intoMoonshotAI:mainfrom
Conversation
Currently, kimi-cli hardcodes Windows PowerShell as the only shell on Windows. This adds a 'default_shell' config field so users can choose their preferred shell (pwsh, cmd.exe, git-bash, WSL bash, etc.). Changes: - Add 'default_shell' field to Config (empty = auto-detect as before) - Update Environment.detect() to accept a shell override - Add _resolve_shell() helper with shutil.which() lookup and friendly name mapping for common shells - Update Shell tool to handle cmd.exe argument syntax (/c vs -c) - Widen shell_name type from Literal to str for extensibility - Pass config.default_shell through Runtime.create() - Add tests for custom shell detection Resolve MoonshotAI#1274 Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
There was a problem hiding this comment.
🔴 Background tasks for cmd.exe use wrong shell_name and get incorrect -c flag instead of /c
In _run_in_background, the shell_name passed to create_bash_task is a binary choice: "Windows PowerShell" if powershell, else "bash". When the user configures cmd.exe as their default shell (self._is_cmd = True, self._is_powershell = False), shell_name is set to "bash". The background worker at src/kimi_cli/background/worker.py:136-140 then constructs args as (spec.shell_path, "-c", spec.command) since shell_name != "Windows PowerShell". But cmd.exe requires /c, not -c, so all background tasks will fail to execute when cmd.exe is the shell. The foreground path correctly handles this in _shell_args (line 230-231), but the background path was not updated to account for the new _is_cmd case.
(Refers to line 153)
Prompt for agents
The shell_name passed to create_bash_task at src/kimi_cli/tools/shell/__init__.py:153 needs to propagate the actual shell type (including cmd) rather than a binary PowerShell-or-bash choice. Change line 153 to pass the actual shell_name, e.g. using environment.shell_name stored as self._shell_name, or a computed value that accounts for self._is_cmd. For example:
shell_name = "Windows PowerShell" if self._is_powershell else ("cmd" if self._is_cmd else "bash")
Additionally, the background worker at src/kimi_cli/background/worker.py:136-140 only handles two cases (PowerShell and everything else with -c). It needs a third branch for cmd that uses /c:
if spec.shell_name == "Windows PowerShell":
args = (spec.shell_path, "-command", spec.command)
elif spec.shell_name == "cmd":
args = (spec.shell_path, "/c", spec.command)
else:
args = (spec.shell_path, "-c", spec.command)
Was this helpful? React with 👍 or 👎 to provide feedback.
Related Issue
Resolve #1274
Description
Currently, kimi-cli hardcodes
powershell.exeas the only shell on Windows (inenvironment.pylines 33-35). Users who preferpwsh(PowerShell 7),cmd.exe, Git Bash, or WSL bash have no way to override this.This PR adds a
default_shellconfiguration option so Windows users can choose their preferred shell.Changes
config.py: Addeddefault_shell: strfield (empty string = auto-detect, preserving current behavior)environment.py:Environment.detect()now accepts an optionaldefault_shellkeyword argument_resolve_shell()helper that usesshutil.which()to locate the binary and maps common shell names to friendly display namesshell_nametype fromLiteral["bash", "sh", "Windows PowerShell"]tostrto support arbitrary shellsagent.py: Passesconfig.default_shelltoEnvironment.detect()inRuntime.create()tools/shell/__init__.py:_is_cmdflag to handlecmd.exeargument syntax (/cinstead of-c)Windows PowerShellandPowerShell(pwsh) as PowerShell variantsUsage
When
default_shellis empty (default), behavior is unchanged — PowerShell on Windows, bash/sh on Unix.Checklist
make gen-changelogto update the changelog.make gen-docsto update the user documentation.