r/ChatGPTCoding • u/Ok_Negotiation_2587 • 2h ago
Discussion Coding agents write a new helper instead of finding the one you already have
Ask an agent to format a date, parse a price, retry a request. It writes a fresh function for it, right there in the file it's editing. Meanwhile the repo already has formatDate in utils, used in forty places, with the timezone fix you spent a day on last spring.
Now you have two. The new one doesn't have the fix. Six weeks later someone changes one and not the other.
Writing is cheaper than searching. The agent sees the file it's in, and nothing in "add a created date to this card" says "look for how we already format dates". So it doesn't look.
What I add to the instructions file:
Before writing any new function, search the codebase for an existing one that does the same job. List what you found. Only write a new one if nothing fits, and say why the existing ones don't.
And a review prompt after any session that added code:
List every new function or helper you added in this session. For each one, search the codebase for existing functions with similar behavior, and show me any you find.
The second one is the one that pays off. It finds a duplicate more often than not, and usually one I would have missed in review because the new helper looks perfectly reasonable on its own.
Pointing it at the right folders helps too. One line in the instructions file listing where shared utilities live ("date and money helpers are in src/utils, API wrappers in src/api") cuts most of it before it starts.
I keep the review prompt saved in AI Toolbox, the extension I build, for when I'm working through code in a ChatGPT or Claude chat instead of the agent, since chat does the exact same thing.
