Try the demo

SyntaxError: (unicode error) 'unicodeescape' codec can't decode bytes

A Windows path in a Python string, where \U starts an escape.

The error

$ python notes.py
  File "notes.py", line 1
    path = "C:\Users\you\notes.txt"
           ^^^^^^^^^^^^^^^^^^^^^^^^
SyntaxError: (unicode error) 'unicodeescape' codec can't decode bytes in position 2-3: truncated \UXXXXXXXX escape

With a lower-case "C:\users\you" the message ends in truncated \uXXXX escape instead.

Why it happens

In an ordinary Python string a backslash starts an escape. \U must be followed by eight hex digits and \u by four, to name a Unicode character. sers isn't hex, so Python can't compile the file, and none of it runs, not even the lines above.

Coding agents hit it when they write a script into a Bash heredoc or python -c with a path copied from Windows.

The quiet version

A path without \U or \u compiles, but its other escapes still turn into characters:

$ python data.py
Traceback (most recent call last):
  File "data.py", line 1, in <module>
    f = open("C:\temp\new.csv")
OSError: [Errno 22] Invalid argument: 'C:\temp\new.csv'

\t became a tab and \n a newline. The message prints them back as \t and \n, so the path in it looks right. Escapes Python doesn't know, such as \d, give a SyntaxWarning: invalid escape sequence instead.

The fix

Any one of these keeps the backslashes, or does without them:

path = r"C:\Users\you\notes.txt"     # a raw string: backslashes stay as they are
path = "C:/Users/you/notes.txt"      # Windows takes forward slashes
path = "C:\\Users\\you\\notes.txt"   # each backslash doubled

Or build the path, and skip the question:

from pathlib import Path
path = Path.home() / "notes.txt"

A raw string can't end in a single backslash: r"C:\Users\you\" is SyntaxError: unterminated string literal. Leave the last backslash off, or use forward slashes.

When an agent writes the script, have it write a .py file and run that, rather than pass the code through a shell, which can mangle it on the way (unterminated string literal).

How DMN learned it

It came up, and was fixed, in 8 of our own sessions. DMN kept the fix as one line: When running Python from Bash heredocs on Windows, never embed backslash paths like 'C:\Users'; use forward slashes (C:/Users/...) or write the script with the Write tool and run python file.py.

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