Skip to content
This repository was archived by the owner on Sep 23, 2026. It is now read-only.
This repository was archived by the owner on Sep 23, 2026. It is now read-only.

[Windows] Agent generates PowerShell 7.x syntax incompatible with default PowerShell 5.x #2194

Description

@lNeverl

What version of Kimi Code CLI is running?

kimi, version 1.41

Which open platform/subscription were you using?

Kimi Code

Which model were you using?

Kimi-k2.6

What platform is your computer?

Windows 64位

What issue are you seeing?

The Agent frequently generates PowerShell code using syntax only available in PowerShell 7.x, but Windows systems still default to PowerShell 5.1 (which Kimi CLI hardcodes as the shell). This causes script execution failures that are difficult for users to diagnose.

Case 1: Out-File -Encoding utf8NoBOM

"content" | Out-File -Encoding utf8NoBOM file.txt

Fails on PowerShell 5.1:

Out-File : Cannot validate argument on parameter 'Encoding'. The argument "utf8NoBOM" does not belong to the set
"unknown,string,unicode,bigendianunicode,utf8,utf7,utf32,ascii,default,oem" specified by the ValidateSet attribute.

Case 2: Join-Path with 3 arguments

$tmp = Join-Path $PWD ".git" "tmp-file-name"

Fails on PowerShell 5.1:

Join-Path : A positional parameter cannot be found that accepts argument 'tmp-file-name'.

(PowerShell 5.1 Join-Path only accepts 2 positional parameters; 3-parameter support was added in PowerShell 6.0)

Case 3: Pipeline chain operators

git pull && git merge ...  # fails in PS 5.1

What steps can reproduce the bug?

  1. Use Kimi CLI on Windows (PowerShell 5.1 is the default shell)
  2. Ask the Agent to write a PowerShell script or one-liner that involves:
    • File output with specific encoding
    • Path joining with more than 2 segments
    • Chaining multiple commands with && or ||
  3. Observe that the generated code fails when executed

What is the expected behavior?

The Agent should default to generating PowerShell 5.1-compatible code on Windows, since that is still the system default shell that Kimi CLI hardcodes (powershell.exe at C:\Windows\System32\WindowsPowerShell\v1.0\).

Compatible alternatives:

PS 7.x syntax PS 5.1 compatible equivalent
Out-File -Encoding utf8NoBOM Out-File -Encoding utf8 (then strip BOM if needed) or use .NET [IO.File]::WriteAllText()
Join-Path $PWD ".git" "file" Join-Path (Join-Path $PWD ".git") "file"
cmd1 && cmd2 cmd1; if ($?) { cmd2 }
cmd1 || cmd2 cmd1; if (-not $?) { cmd2 }

Additional information

Environment:

  • OS: Windows 10/11
  • Shell: Windows PowerShell 5.1 (hardcoded default)

Related Issues:

Suggested Fixes:

  1. Short-term: Update the system prompt to explicitly constrain the Agent: "On Windows, generate PowerShell 5.1 compatible code only"
  2. Medium-term: Maintain a PS 5.1 compatibility checklist in the system prompt or AGENTS.md for commonly used cmdlets
  3. Long-term: Detect the actual PowerShell version being used and communicate it to the Agent

Activity

  1. lNeverl commented on May 17, 2026

    @lNeverl
    Author

    This issue has been resolved by kimi-cli 1.42.0.

    Changelog reference:

    Shell: Switch the Windows shell backend from PowerShell to Git Bash, so the Shell tool now runs commands through bash.exe (POSIX semantics) instead of powershell.exe.

    What changed:

    • The Shell tool no longer uses PowerShell 5.1 / 7.x as the execution backend
    • It now runs all commands through bash.exe (Git Bash)
    • Agent-generated commands now use Bash syntax by default, eliminating the PowerShell version compatibility problem entirely

    The specific failures mentioned in this issue are no longer applicable:

    • Out-File -Encoding utf8NoBOM → no longer generated (Bash uses > or tee)
    • Join-Path with 3 arguments → no longer generated (Bash uses standard path strings)
    • cmd1 && cmd2 → now works natively in Bash
    • cmd1 || cmd2 → now works natively in Bash

    Closing as fixed in 1.42.0.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions