Preventing Technical Debt in AI Development Guide
Part of the AI Code Quality guide. Start with How to Reduce AI Coding Mistakes: A Practical Guide
Suppose an agent adds a currency formatter. Its tests pass, the output looks right, and the feature ships, but the repository already has a formatter with different rounding rules. Now a rounding change means finding and updating both implementations.
I'd want to catch that before asking the agent to write the second one. For this workflow, technical debt means extra maintenance work you've accepted or accidentally introduced, such as repeated behavior or code that never gets connected to the feature it was meant to implement, leaving someone else to work out whether it can be removed.
The useful place to start is the next task. Give it a discovery step before editing, make the caller check part of the plan, and require evidence from the feature's entry point before calling it finished, even when the helper's own tests already pass.
What the research supports
GitClear's 2025 code-quality report found duplicated blocks in 1.80% of sampled commits in 2023 and 6.66% in 2024. Its measure looks for repeated runs of at least five lines, excluding blank and keyword-only lines, so this is a particular duplication measure, not the percentage of a codebase that is duplicated.
That trend is a reason to search before the agent writes. It doesn't tell you who wrote a particular duplicate, whether an assistant was involved, or whether the duplication was justified, and I'd avoid using it to assign blame to an individual developer.
The DORA 2024 report estimated that a 25% increase in AI adoption was associated with 1.5% lower delivery throughput and 7.2% lower delivery stability. Those are historical survey associations, not a controlled experiment, and they don't predict your team's results, but they do give us reason to measure what happens after code is written.
My recommendation is to keep changes small enough to inspect and attach a check to the decision that could create debt. Start with reuse.


Before editing, find the owner and the existing behavior
Pick the module responsible for the behavior you're changing. Read its public exports, inspect one existing consumer, look at the tests around that consumer, and identify where the new behavior belongs before the agent creates another utility directory.
With ripgrep installed, run this concept search from the repository root.
rg -n -i 'formatPrice|currency|money' .
rg prints matching lines with their numbers here, and -i ignores case. Replace the search terms with the behavior you're adding.
Open the candidates. Compare their contracts, check who imports them, read the edge cases they handle, and explain why an existing implementation can or cannot be reused before adding another one.
ripgrep skips ignored files, hidden paths and binaries by default. A quiet search isn't proof that the behavior doesn't exist.
For a TypeScript project, inspect the package manifests before choosing an import, check how the package exposes the implementation, and read the configured verification commands instead of guessing their names. package.json can declare package exports and scripts.
Ask the agent for this short plan before it edits:
Behavior to change:
Existing implementation considered, with file path:
Owning module:
Production caller that will use the change:
Verification command and expected behavior:
Reason for adding a new implementation, if needed:
The last field can say that reuse doesn't fit, and if different rounding contracts need separate functions, record the distinction in the plan, so the next person doesn't have to rediscover it.
Before a shared refactor, list the consumers
A signature change needs a caller checklist. Include the direct users, follow their callers toward routes or jobs, inspect package re-exports, and mark anything you haven't traced so the plan doesn't quietly turn an assumption into a fact.
rg can help locate names, but it doesn't determine which function a matching identifier refers to. Use symbol references and source inspection to resolve aliases and follow the chain.
For each affected path, choose the test that exercises the changed contract. If the helper serves a worker and an endpoint, verify both, and include a failure case such as a rejected input, so the checklist covers more than the successful response.
Keep this beside the proposed change. If the caller list expands into another subsystem, shrink the refactor or expand the verification plan before editing, while you can still choose a smaller change, instead of bundling unrelated fixes into the same patch. The separate guides to change blast radius and code knowledge graphs go deeper into tracing these relationships.
Before merge, exercise the path that invokes the feature
Consider a hypothetical sendDigest helper. A test can call it directly, assert that it formats a message, and pass even when the scheduled handler never invokes it, because that test starts after the missing connection.
Run a second search using the actual function name from your change.
rg -n 'sendDigest' .
rg gives you places to inspect. It doesn't prove that the scheduled job is registered or runs in your deployment.
Trace the production entry point to the helper, check any registration or configuration involved, and write an integration test that starts at that entry point, with an assertion on the behavior the user requested. Then remove the new connection temporarily and confirm the test fails.
For a route, start at the request handler; for a job, start at the registered job handler. Keep deployment configuration in the review when registration happens outside the source path you've tested.
That's the distinction behind passing tests with missing feature wiring. Keep the unit test, but add evidence that something actually invokes the new behavior, and describe any part of the deployment path the test doesn't cover, so reviewers know what remains unchecked.
Where Pharaoh fits in this workflow
I build Pharaoh, a hosted MCP server that maps TypeScript, JavaScript, Python, C and C++ repositories into a graph. It gives an agent module context and caller relationships, alongside function search, so the discovery work above can use structural results, with source inspection still needed for the behavior you're changing.
Start with get_codebase_map and the owning module's get_module_context, use search_functions before adding a helper, then open the candidates, starting with the ones in the module responsible for the behavior. This unchanged excerpt comes from the captured formatPrice search on the Pharaoh-so fork of cal.diy at revision 54343aa6:
- const formatPrice = (price: number, currency: string | undefined, locale = "en") => ... [exported, complexity: 3]
packages/lib/currencyConversions.ts:60-71 (lib)
Read that implementation before importing it. A matching name gives you a candidate, not proof that its rounding behavior fits your task.
Use get_blast_radius before changing shared code, then check specific functions with get_unused_code, which can show their entry-point paths, if the graph finds a route to them, as in this excerpt (header line trimmed) from the captured result for the same repo and revision:
- checkAdminOrOwner (packages/features/auth/lib/checkAdminOrOwner.ts): reachable: getAtomEventTypeApp → getEventTypesAppIntegration → checkAdminOrOwner
For cleanup, its Dead classification requires all signals to agree, including no entry-point reachability, no mention in another file, and no production import of the containing file. Possibly unused means unreached but with references or imports that need inspection; Used only by tests is reported separately.
There is a boundary here. The graph covers the default branch, not your working tree or feature branch, and a live repo is re-mapped after pushes to its default branch, so use local checks on the code you're about to merge.
For pull requests, PR Guard is a Pro feature with four checks: new dead code, breaking signature changes with existing callers, exact function duplicates, and changed-function blast radius. Findings produce a neutral, advisory check by default; use the PR Guard documentation to understand the check before making it part of your merge policy.
Keep the rule small enough to use on the next task
Put the plan and its verification evidence in the pull request. Record which implementation you considered reusing, list the affected production paths, name the test that fails when the connection is removed, and give any intentional shortcut an owner and a concrete revisit condition.
For example, if an agent adds currency formatting to a checkout summary, the pull request should make the decision visible:
Reuse considered: packages/lib/currencyConversions.ts
Affected paths: checkout route, invoice worker
Contract checked: display formatting only; invoice rounding remains separate
Verification: checkout integration test and invoice worker test
Connection check: remove the formatter call and confirm the integration test fails
Shortcut owner: checkout team
Revisit condition: consolidate only after both paths share the same rounding contractReview the exceptions as work continues. If a second formatter was necessary, document why, and when that distinction disappears, remove the extra implementation rather than carrying both indefinitely.
For the broader setup, read an AI code quality framework, and if you're choosing checks for a new project, our ai-codebase-boilerplate repository has a FRAMEWORK.md that walks you through creating the Biome, Knip, Lefthook, CI and Stryker configuration, and a template/ directory with the package.json scripts for those tools, but keep the workflow here focused on the current change and audit what has already shipped separately, so an ordinary feature doesn't become a whole-repository cleanup.
The companion guide to reducing AI coding mistakes covers the wider coding workflow.
If you want the graph available to your agent, set up Pharaoh on a repository. Start with one real task, keep the discovery evidence beside the change, and make the next maintainer's job explicit before you merge, while the reason for each decision is still fresh.
Article Record
ReferencesPrimary sources used for this article
Update HistoryMeaningful revisions to this article
- Added a practical example to show how to keep development rules small enough to use on the next task.