Skip to content

Shell tool broken on Windows: [WinError 2] powershell.exe not found #1702

@elis132

Description

@elis132

Bug Description

The Shell tool fails on every invocation on Windows with:

[WinError 2] Det går inte att hitta filen

("The system cannot find the file specified")

Root Cause

In kimi_cli/utils/environment.py, the Windows branch sets:

shell_path = KaosPath("powershell.exe")

This bare filename is passed to asyncio.create_subprocess_exec() (via kaos.exec), which calls CreateProcessW. The uv tool virtual environment does not include C:\Windows\System32\WindowsPowerShell\v1.0\ in its PATH, so the process creation fails with ERROR_FILE_NOT_FOUND.

Reproduction

import asyncio

async def test():
    # This fails in the uv venv:
    p = await asyncio.create_subprocess_exec(
        "powershell.exe", "-command", "echo hello",
        stdin=asyncio.subprocess.PIPE,
        stdout=asyncio.subprocess.PIPE,
        stderr=asyncio.subprocess.PIPE,
    )

asyncio.run(test())
# [WinError 2]

Suggested Fix

Resolve the full path using the SystemRoot environment variable, which is always set on Windows:

if os_kind == "Windows":
    shell_name = "Windows PowerShell"
    import os
    system_root = os.environ.get("SystemRoot", r"C:\Windows")
    shell_path = KaosPath(
        os.path.join(system_root, "System32", "WindowsPowerShell", "v1.0", "powershell.exe")
    )

This works on any standard Windows installation regardless of PATH configuration.

Environment

  • Windows 11 Pro
  • kimi-cli installed via uv tool install kimi-cli
  • Python 3.13

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions