← seriesmaclulich.com

Check whether your duplicate-code warning changes what your agent ships

24-second silent illustration of the original trial plan, not a measured outcome.

Four checks before you trust a duplicate-code warning

  1. Record what the final code calls after each warningOf 39 duplicate-name warnings from my edit hook, 34 were false alarms and 5 pointed at real copies.
  2. Test it on same-name decoys and different-name copiesThe same name can describe different jobs, and two names for the same behaviour could slip past a name matcher.
  3. Fix the cases and their labels before you run itThen you can report which pairs it missed as well as the ones it caught.
  4. Keep it as advice until it earns a blockUse new, independently verifiable failures for any blocking check, and compare them with the starting commit.
The counts come from my own edit hook, recovered from transcripts, and the other rows are my trial plan.

Record what the final code calls after each warning

If your coding agents get a duplicate-code warning while they edit, this chapter of Fewer tokens to ship is for you.

Chapter 1 ended on a brief that can still miss an owner, so this one asks whether a warning catches it in time.

A duplicate-code warning tells you the tool found something to check. The final code tells you whether the agent used it.

In one possible outcome, the agent checks the warning and switches to the existing API.
In one possible outcome, the agent checks the warning and switches to the existing API.

My edit hook, a script that runs whenever an agent changes a file, pointed to existing code when it spotted a matching name, route or table write.

A reader asked how often that changes what the agent ships. Original write-up · Reader discussion

The hook was deleted on 11 November. It kept no durable warning log, but the messages survived in transcripts. The five that weren’t false alarms pointed at real copies, and none of those copies reached main.

34 of 39 warnings were false alarms

False alarms34
Real copies5none reached main
Every duplicate-name warning from the hook I deleted, recovered from transcripts.

Test it on same-name decoys and different-name copies

The same name can describe different jobs. Two names for the same behaviour could slip past that hook. A route kept on purpose for older callers can also draw a warning. I’ll include all three cases. Reader discussion

For the different-name cases, I’ll use pairs from real code where I can. For examples I make up, I’ll ask someone who hasn’t seen the matcher to choose names from the behaviour spec. I’ll check both implementations against that spec. Reader discussion

Fix the cases and their labels before you run it

I’ll lock in the cases and their labels before I run the hook. That way I can report which pairs it missed as well as the ones it caught. Reader follow-up

How far to trust it

The count is recovered from transcripts and the tests here are a plan

  1. Recovered, not loggedThe hook kept no durable warning log, so the 39 warnings come from transcripts.
  2. Plan, not resultsThe video and pictures show the original trial plan, not a measured outcome.
The trial results are in chapter 5.

Try it on your rig

  1. Run warnings as advice on one repository.
  2. Record the candidate owner, the reason it matched and what the delivered code actually calls.
  3. Put an identical function in two files to check whether the tool can see across files, and include same-name decoys and different-name matches.
  4. Have a reviewer label the outcomes. Keep the warning if it helps agents reuse the right code often enough to justify the extra work.
  5. Use new, independently verifiable failures for any blocking check, and compare them with the starting commit so old findings cannot mask new ones.

To follow along on your own setup, start with the shared work record in the series setup guide.

Some repeat work shows up across several commits. Next, can a failing test spot the loop?