Cannot force UTF-8
Open 💬 24 comments Opened Sep 21, 2025 by Grimshad
💡 Likely answer: A maintainer (etraut-openai, contributor)
responded on this thread — see the highlighted reply below.
What version of Codex is running?
vscode extension 0.4.12
Which model were you using?
codex high, medium, and low
What platform is your computer?
Microsoft Windows NT 10.0.26100.0 x64
What steps can reproduce the bug?
Codex overwrites emoji's with unicode jibberish. This is what gpt 5 said about it:
Codex extension bug → It’s writing the file contents with the wrong encoding (double-encoding UTF-8 into CP1252/Latin-1), which produces mojibake like ðŸ....
Config.toml can’t fix it → There’s no supported config option today to change file encoding. Codex assumes UTF-8, but sometimes on Windows it falls back incorrectly when saving.
What is the expected behavior?
Don't automatically replace emoji with unicode when editing files
Expected to see: 🔴
What do you see instead?
Saw: 🟢
Additional information
_No response_
24 Comments
Oh, I forgot to mention it also does stuff like this all the time which causes problems instead of adding proper new lines, it add literal new lines:
if (pointIndex !== null) {\r\n hook.selectedIndex = pointIndex;\r\n hook._isDraggingPoint = true; // Start dragging the selected point\r\n // Clear other selections when selecting a point\r\n hook.selectedLine = null;\r\n hook.selectedShape = null;\r\n hook._hoverLightHandle = null;\r\n if (typeof hook._updateCursor === "function") {\r\n hook._updateCursor();\r\n }\r\n hook._renderPoints();same
Same here, it broke my whole project adding those ðà on every file
I often encounter this issue as well. Observation shows that it seems to be implemented by writing Python scripts to edit files, sometimes altering the UTF-8 file header to BOM.
Same here
same here, UTF-8 and /n issues
It's incredibly frustrating. Windows, Codex.
This should be fixed in the latest versions of codex.
Same problem here
Same problem
sam problem
same!!
constrant in agents.md helps
@etraut-openai this is definitely not fixed.
To reproduce, create a file with "→↑↓" in it and ask codex what it sees.
With version 0.77.0, on Windows, Codex tells me:
It also fails to create files or
apply_patchto files with non-ascii characters and can cause mayhem in some cases (deleting files and recreating them because the patch fails). It can also replace non-ascii unicode characters with control symbols and when reviewing it's easy to miss this, so can break an app in quite a subtle way.If using the VS Code extension, setting it to run in WSL works.
Also, running the same commands as Codex (
Get-Content, etc) works fine, it's something in the Codex codebase that doesn't preserve certain Unicode characters.Reopening
Maybe useful: if I tell Codex to read the file with
rginstead ofcatorGet-Contentit's able to see non-ascii characters (but it still can't useapply_patchbecause I guess that reads at some point and scrambles the non-ascii characters).FWIW, my
AGENTS.mdaddition for this issue:I might look into this if there's no objections. It'll be my first Codex PR and I don't know Rust so I might not be fast...
For others facing this, a workaround is to make your terminal use UTF-8 as the code page (assuming that doesn't break other things for you).
You can run
chcp 65001before starting Codex or put it in your PowerShell profile, or just tell Codex to do this for you (e.g. in the VS Code extension).@etraut-openai I see a few options to fix this issue:
chcp) and store this. Then when decoding text (bytes_to_string_smartintext_encoding.rs), use the active code page if known, else fall back to the existing heuristic logic indetect_encoding. Maybebytes_to_string_smartis too general, since this only applies to stdout/stderr bytes. Thoughts?read_filetool. Seems like that would ease a lot of these encoding issues and workarounds.Options 1-3 all have flaws (I'm pretty sure), my vote would be for a tool to read files and save a lot of OS-specific encoding logic. Maybe in the interim log a warning to users if their active code page isn't something that
bytes_to_string_smartcan handle.OK I've looked into this, it's quite interesting!
Summary of my findings (noting that I am not an expert in encodings, PowerShell or Rust):
Get-Content) write their text output as bytes tostdoutby encoding with a particular encodingchardetngto infer the encoding (seebytes_to_string_smart)chardetngwas written for browsers and focuses on web encodings, it can't detect common console encodings like CP850 and CP437chardetngto also detect these console encodings, but that's not simple.GetConsoleOutputCP()API orchcp, but only a subset of shell commands actually use these settings. E.g.rgcommands don't. So you'd need to actually look at the shell command to work out which setting it will use, which is probably too brittle.apply_patchfails is because the agent reads the file to change withGet-Contentand gets mojibake (wrongly-decoded non-ascii characters), and passes that toapply_patch, but that function reads the file with Rust and gets the correct contents. The two don't match, so the patch fails.It seems to me the best (least worst) solution is a two pronged approach:
read_filetool to replaceGet-Contentcalls which is probably the lion's share of cases).But detecting whether the user is likely to have trouble isn't simple because there are three settings that define the encoding, and different commands use different settings! I _think_ the best advice to the average user is to set this in their PowerShell profile:
I don't think it's possible to do this in the Codex codebase since they need to be set in the parent shell so they take effect when Codex spawns a shell to run individual commands.
BTW, even with all this fixed,
apply_patchcan still fail on multi-byte characters (kanji, emojis), because a loggingpreviewfunction can slice multi-byte characters in half, but that's another issue.So I'll park work on this now until I hear back...
P.S I now have a lot more sympathy for Windows not being a first class citizen from day one!
Thanks for your analysis and thoughtful summary.
@davidgilbertson thanks for the in-depth conversation here. We actually already merged an experimental fix for this in https://github.com/openai/codex/pull/7902, which you can test out by running
codex --enable powershell_utf8or addingfeatures.powershell_utf8 = trueto your config.toml.It is largely similar to (2) but with minimal changes to the user's shell environment. Please test it out and let us know if this works for you, and if there are specific commands that are still hitting unicode issues (reporting with
/feedbackis ideal).How did I miss that! Yep that works for me and should cover the majority of (my) cases.
I'm sure you know, but it will still have trouble with commands that use the
chcpencoding (if it's not UTF8), like running a.cmdfile with (some) non-ascii characters:Yep, thanks for flagging that edge case!
Codex just replaced all ≈ symbols of my codebase by ≈
It actually replaces any special character, whether it's accented letters, symbols, anything...