Tool-layer bytes
Between the text Claude writes and the bytes on disk sit layers that rewrite: the Bash tool's
own escaping, the shell's quoting and heredoc rules, MSYS path conversion on Git for Windows,
sed -i and Python's newline handling, and git's core.autocrlf. Each reports success. A
green run afterwards proves nothing about whether the edit applied, because the run tests the
bytes that landed, not the ones intended.
The rules
- Code through files, not the shell. Any script or payload carrying a backslash, a quote
of the kind enclosing it, or a
$'goes to disk with the Write tool and runs as a file. Not a heredoc, notnode -e, notpython -c. The Bash tool has dropped one level of backslashes, turned\band\xNNinto raw bytes, and split a heredoc at a$'. - No in-place stream edits on Windows checkouts.
sed -iandperl -pirewrite the whole file and turn CRLF line endings LF;git diffundercore.autocrlf=truecannot see it. Use the Edit tool. - Python and Node read and write with the newline mode stated. Python's default
open(p)turns CRLF into LF on read, so "read normally, write withnewline=''" still writes LF. Read and write withnewline='', or bytes. - One input per command. A heredoc and a later
< fileredirect on one command: the later redirect wins and the heredoc never reaches the program. - Paths and revisions through MSYS: an argument like
origin/main:pathor one starting//can be rewritten; prefixMSYS_NO_PATHCONV=1.
Prove the bytes after any scripted edit
git diff --stat: a whole-file count for a one-line edit is the tell.- Line endings:
tr -cd '\r' < f | wc -cagainstwc -l < f;git ls-files --eol f. - Control bytes:
tr -d '\011\012\015\040-\176\200-\377' < f | wc -cshould print 0. - Syntax:
node --check f, or the language's own. - A mutation test is proved by its red run, read in full; if the mutation script reports it made no change, the escape was eaten and the red run never happened.
The hook
hooks/byte-layer-warn.mjs (PreToolUse, Bash) warns, never blocks, on a heredoc or inline
code string carrying a backslash (a git commit message is exempt), on sed -i and
perl -pi, and on a heredoc with a later input redirect. It is the moment-of-use half; this
skill is the rest.
Provenance
Twelve misses in four repositories, August to October 2026, while the rule lived only in a
machine memory: ICC L-043, L-046, L-083, L-094, L-120 and the session of 22 October 2026
(fifty working-copy files turned LF by Python's default read; three heredocs that dropped
backslashes); AI domain L-122, L-144, L-146; passive income L-084; RimModManager L-011.
docs/SKILL_PROPOSALS_2026-10-22.md, Tier 1 item 1.
Additions from the misses-log sweep (2026-11-01)
Four more layers that rewrite bytes between the thing you typed and the thing that ran.
- A byte-exact test against a working-tree file needs a
.gitattributesbehind it. Git'stext=autonormalises to LF in the object store and may hand the working copy CRLF on checkout, so a test asserting exact bytes passes on the machine that wrote the file and fails on the next clone. Pin the path'seolin.gitattributesand let the test assert against that, or the test is measuring the checkout rather than the content. (PropOS 2026-07-27. Acted on here: this repository pinned*.json text eol=lfon 2026-11-05 after the three skill-count files warned on commit.) - PowerShell double-quoted strings turn backtick sequences into control bytes. In
PowerShell the backtick is the escape character, so
`nbecomes a newline,`ta tab and`0a null inside"...", before your program sees any of it. Use single quotes for a literal, or write the file with a tool rather than through a shell string. (Rimagent 2026-10-13.) - Git Bash drops
TZregion names on the way to a Windows program.TZ=Europe/Londonset in Git Bash does not reach a native Windows binary as that zone, so a time read through one is not the zone you asked for. Read Windows clock values with PowerShellGet-Dateinstead, and seelive-state-firstfor how the reading reaches the record. Rule 5 above covers the other half of this layer, the//andorigin/main:pathrewrite. (ASH 2026-10-08.) $'\r'inside a double-quoted substitution is the two letters, not a carriage return.grep -c "$'\r'" filesearches for a dollar sign, a quote and the letter r. Bash expands$'...'only when it is unquoted, so writegrep -c $'\r' file. The failure is silent and reports zero, which reads as a clean file. (Library 35.)


