Fixes · Checked on 2026-10-07, with GNU sed 4.9
sed: can't read : No such file or directory
sed was given an empty file name, or a script where the file name goes.
The error
$ f=$(rg -l "retries" src | head -1)
$ sed -i 's/retries = 3/retries = 5/' "$f"
sed: can't read : No such file or directory
Nothing between can't read and the colon: the file name was empty.
Why it happens
An empty variable. The search before it found nothing, so $f is empty and sed is
asked to edit a file called "". Coding agents do this when they pick the file with rg -l … | head -1
and the pattern doesn't match anywhere.
macOS's sed -i '' on GNU sed, the sed on Linux and in Git Bash. GNU sed reads
the '' as the script, and the real script as a file name:
$ sed -i '' 's/red/blue/' config.txt
sed: can't read s/red/blue/: No such file or directory
The fix
Check the name before sed uses it:
f=$(rg -l "retries" src | head -1)
if [ -n "$f" ]; then sed -i 's/retries = 3/retries = 5/' "$f"; else echo "no file matched"; fi
For a script that runs on both kinds of sed, give -i a suffix, then remove the backup it leaves:
sed -i.bak 's/red/blue/' config.txt && rm config.txt.bak
A coding agent is safer with an edit tool, which changes exact text in a file it names. Slashes in the expression are the other common sed failure: unknown option to `s'.
How DMN learned it
It came up, and was fixed, in 2 of our own sessions. DMN kept the fix as one line:
When piping a search result into a variable (f=$(rg -l ... | head -1)) before sed, verify it is non-empty
with [ -n "$f" ] && sed ...; an empty match yields 'sed: can't read :'.
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.