Skip to content

Windows PowerShell 5.1 can mojibake BOM-less UTF-8 Markdown in tool calls #29085

Open

Description

@evrenonur

This is a focused follow-up to #13755 and the duplicate report #15422.

Summary

On Windows PowerShell 5.1, Codex shell tool calls can read BOM-less UTF-8 Markdown files as mojibake when the file contains non-ASCII text such as Turkish characters. This can make the agent context disagree with the actual file bytes and can cause generated patches to fail or edit the wrong text.

Root-cause hypothesis

The current PowerShell command prefix pins [Console]::OutputEncoding, but Windows PowerShell can still decode BOM-less UTF-8 files through the active ANSI code page unless the whole tool-call shell process is consistently forced to UTF-8.

In practice, commands such as Get-Content and Select-String can return corrupted text for Turkish characters on Windows PowerShell 5.1 even when the underlying file is valid UTF-8.

Reproduction shape

  1. Use Windows PowerShell 5.1.
  2. Create a BOM-less UTF-8 Markdown file containing Turkish characters, for example Hızlı Geçiş Sistemi — doğru çğışöü.
  3. Read it through shell commands used by Codex, especially Get-Content / Select-String.
  4. Observe mojibake in the agent-visible output, which can then cause patch mismatches.

PowerShell 7 appears to avoid this in the reported cases, but Windows users still commonly have PowerShell 5.1 as the default shell.

Patch outline

I prepared a focused branch with a potential fix here:

https://github.com/evrenonur/codex/tree/codex/powershell-utf8-text-io

The approach is to update the Windows PowerShell startup prefix used by codex-shell-command so that it:

  • runs chcp.com 65001
  • sets [Console]::InputEncoding, [Console]::OutputEncoding, and $OutputEncoding to UTF-8 without BOM
  • defaults Get-Content and Select-String to UTF-8 inside the tool-call shell process
  • adds a Windows-only regression test for BOM-less UTF-8 Markdown containing Turkish characters

Local validation

I ran:

cargo fmt --package codex-shell-command
cargo test -p codex-shell-command powershell --lib

Both passed locally.

Contribution note

The current contributing guide says external PRs are invitation-only, so I am sharing the analysis, reproduction details, and branch/patch outline here instead of relying on an unsolicited PR.

Activity

  1. added
    bugSomething isn't working
    CLIIssues related to the Codex CLI
    windows-osIssues related to Codex on Windows systems
    tool-callsIssues related to tool calling
    on Jun 19, 2026
  2. github-actions commented on Jun 19, 2026

    @github-actions
    Contributor

    Potential duplicates detected. Please review them and close your issue if it is a duplicate.

    Powered by Codex Action

  3. evrenonur commented on Jun 19, 2026

    @evrenonur
    Author

    The duplicate suggestion for #27390 is related, but I think this issue covers a narrower fallback case rather than the same request.

    #27390 proposes preferring pwsh when it is available. That would avoid this problem on machines with PowerShell 7 installed.

    This issue is about the remaining powershell.exe fallback path: when Codex does run through Windows PowerShell 5.1, the shell-command prefix should still make BOM-less UTF-8 file reads deterministic so Get-Content / Select-String do not expose mojibake to the agent.

    So the two fixes are complementary:

    • prefer pwsh by default when available
    • keep legacy powershell.exe fallback safe for machines where pwsh is not installed
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

    CLIIssues related to the Codex CLIbugSomething isn't workingtool-callsIssues related to tool callingwindows-osIssues related to Codex on Windows systems

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions