Find duplicated logic and propose where to consolidate it
Category: Cleanup · Updated 2026-09-22 · Tools: Codex
Use this when the same validation, formatting, or business-rule logic seems to show up in multiple places with small variations, and bugs keep getting fixed in one copy but not the others. Best as a report-first pass, since merging duplicated logic can be riskier than it looks if the copies have quietly diverged. Small to medium usage.
Full prompt
Search this codebase for duplicated or near-duplicated logic — not just identical code, but blocks that do the same conceptual thing (validation, formatting, a business rule) with minor variations that may or may not be intentional. For each cluster you find, list every location it appears, note any differences between the copies, and flag whether those differences look like an intentional variation or accidental drift. Propose one consolidated home for each cluster (a shared function/module) with a name that reflects what it does. Do not merge anything yet — hand back the report and wait for me to pick which clusters to actually consolidate before making any changes.
Tips
- Pay close attention to the "differences between copies" column — that's usually where the real risk is, since a merge that ignores a deliberate difference introduces a bug
- Start with the cluster that has the most copies; it has the best ratio of risk-reduction to effort
- Ask for a specific proposed function name and location, not just "consolidate this" — it forces the agent to think through where the logic actually belongs
Still waiting on a reset? See what to do when you hit the limit, or check Codex / Claude time since last reset.
Back to the prompt library · Subscribe: all-products feed