Try the demo

UnicodeEncodeError: 'charmap' codec can't encode character

Python on Windows prints fine in your terminal, then fails as soon as a coding agent, a pipe or a log file captures its output.

The error

UnicodeEncodeError: 'charmap' codec can't encode character '→' in position 12: character maps to <undefined>

Why it happens

When Python writes to a console window, it writes UTF-8. When its output goes to a pipe or a file, which is how coding agents read it, Python falls back to the Windows code page, usually cp1252. cp1252 has no arrows, no box-drawing characters and few letters outside Western Europe, so the first one Python tries to print raises.

Files have the same problem: open() without an encoding uses the code page too.

The fix

Run Python in UTF-8 mode, for one command, or for every shell you open from now on:

python -X utf8 script.py
setx PYTHONUTF8 1

Or fix it inside the script, before the first print, and name the encoding when you open files:

import sys
sys.stdout.reconfigure(encoding="utf-8")

with open(path, "w", encoding="utf-8") as f:
    f.write(text)

PEP 686 makes UTF-8 mode the default from Python 3.15.

How DMN learned it

It came up, and was fixed, in 8 of our own sessions. DMN kept the fix as one line: On Windows, Python printing non-ASCII file text raises UnicodeEncodeError (cp1252); run python -X utf8 or call sys.stdout.reconfigure(encoding='utf-8') before printing.

DMN reads your agents' past sessions on your machine. When the same error is fixed the same way in two or more of them, it keeps the fix as a one-line lesson. When the error turns up again, Claude Code is told the fix straight away, and any agent can search what earlier sessions found. How DMN keeps what agents learn.

Stop fixing the same error twice