DEV Community

Cover image for The 1-day-thrown-away rule: read the code before letting your AI write new code
Michel Faure
Michel Faure

Posted on • Originally published at dev.to

The 1-day-thrown-away rule: read the code before letting your AI write new code

Six in the morning, looking at the output

April twenty-ninth, six in the morning. The rendering hits the screen. A A A A A across the entire document matrix, unreadable by construction. I ask my agent why the output is incoherent. It re-reads the code, drops into the neighboring directory, and finds an existing component I had never asked it to inventory. The component renders the expected format cleanly — signatures, header, legend, identification block. What my agent had coded the day before was a partial duplicate of a file neither of us had ever opened.

The format my agent had invented the night before already existed in the repo. Better done. In a nameable file, that neither of us had read before writing.

Why an agent invents next to the existing code

The root of the problem isn't the agent. It's me. When I open a project on a domain already covered by code, I describe the target and let the agent generate. It has no idea what the neighborhood of the file it's about to create looks like, because I never asked it to map it. It codes a plausible solution to a poorly framed problem, and the plausibility of the result hides the duplication as long as nobody opens the other files in the same directory.

The absence of a Phase 0 grep is not a flaw of the agent. It's a flaw of the pilot who skipped the least expensive step in the whole chain.

Phase 0 — two minutes, one file

# Phase 0 — before any new component in an existing domain
DOMAIN="invoices"   # the keyword of the project

find app/api/$DOMAIN/ lib/$DOMAIN/ \
  -type f \( -name "*.ts" -o -name "*.tsx" \) | head -20

# If an expected pattern is nameable, check that it doesn't already exist
grep -rl "ExistingPattern\|RenderPdf\|exportPdf" app/ lib/
Enter fullscreen mode Exit fullscreen mode

Two minutes, tops. The output fits on a screen. If an existing component handles the need, read it before proposing anything new. If nothing exists, you have proof you looked.

The measured cost of the shortcut is one dev-day. The component that should have been read fit in a single file with a telling name, in the directory right next door. Two minutes of find would have sufficed. The reverted day is what blind trust in the plausibility of a draft nobody connected to its neighborhood actually costs.

The metacognitive signal

When the agent re-read its own work in light of the existing component, it proposed to revert, not defend. That's a good signal — an agent that locks itself into its invented design would be far costlier than one that admits it missed existing code. But the good signal comes too late. The rule is to not get there in the first place.

The rule

Before any new format, template, or component in a domain already covered, Phase 0 grep, neighborhood read, verbalization of the existing. Otherwise, the next day, you revert.


Phase 0 grep checklist and audit script, pseudonymized:
github.com/michelfaure/rembrandt-samples/tree/main/one-day-thrown-away-rule

Top comments (0)