Skip to content

feat: add configurable default shell for Windows users#1498

Closed
Br1an67 wants to merge 1 commit intoMoonshotAI:mainfrom
Br1an67:feat/configurable-windows-shell
Closed

feat: add configurable default shell for Windows users#1498
Br1an67 wants to merge 1 commit intoMoonshotAI:mainfrom
Br1an67:feat/configurable-windows-shell

Conversation

@Br1an67
Copy link

@Br1an67 Br1an67 commented Mar 19, 2026

Related Issue

Resolve #1274

Description

Currently, kimi-cli hardcodes powershell.exe as the only shell on Windows (in environment.py lines 33-35). Users who prefer pwsh (PowerShell 7), cmd.exe, Git Bash, or WSL bash have no way to override this.

This PR adds a default_shell configuration option so Windows users can choose their preferred shell.

Changes

  • config.py: Added default_shell: str field (empty string = auto-detect, preserving current behavior)
  • environment.py:
    • Environment.detect() now accepts an optional default_shell keyword argument
    • Added _resolve_shell() helper that uses shutil.which() to locate the binary and maps common shell names to friendly display names
    • Widened shell_name type from Literal["bash", "sh", "Windows PowerShell"] to str to support arbitrary shells
  • agent.py: Passes config.default_shell to Environment.detect() in Runtime.create()
  • tools/shell/__init__.py:
    • Added _is_cmd flag to handle cmd.exe argument syntax (/c instead of -c)
    • Recognizes both Windows PowerShell and PowerShell (pwsh) as PowerShell variants
  • Tests: Added test cases for custom shell override and empty fallback

Usage

# ~/.config/kimi-cli/config.toml
default_shell = "pwsh"        # PowerShell 7
# default_shell = "cmd.exe"   # Command Prompt
# default_shell = "bash"      # Git Bash / WSL

When default_shell is empty (default), behavior is unchanged — PowerShell on Windows, bash/sh on Unix.

Checklist

  • I have read the CONTRIBUTING document.
  • I have linked the related issue, if any.
  • I have added tests that prove my fix is effective or that my feature works.
  • I have run make gen-changelog to update the changelog.
  • I have run make gen-docs to update the user documentation.

Open with Devin

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>
Copy link
Contributor

@devin-ai-integration devin-ai-integration bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Devin Review found 1 potential issue.

View 4 additional findings in Devin Review.

Open in Devin Review

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔴 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)
Open in Devin Review

Was this helpful? React with 👍 or 👎 to provide feedback.

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.

Feature Request: Configurable Default Shell on Windows

2 participants