How to Reduce AI Coding Mistakes: A Practical Guide
Part of the AI Code Quality guide. Start with How to Prevent Duplicate Functions in AI Coding Workflows
A permission helper can be three lines long and still need a review across several packages. In cal.diy, checkAdminOrOwner connects to API services, web components, shared application code, and two HTTP endpoints in the captured three-hop result.
That changes what I'd ask an agent to do first.
Before it edits the helper, I want the affected callers and their assumptions, the behavior we're preserving, the failure paths to review, and the tests that will exercise the change. A clean implementation is only part of the task.
Give each change an investigation before implementation, keep its scope reviewable, write down the behavior you expect, and check it through an entry point afterward. That's the workflow I'd use to reduce AI coding mistakes.
Turn a vague task into something you can check
Write down the expected behavior before asking for code. For a permission change, specify who should retain access, who should lose it, what response a denied request should receive, and whether existing clients need to keep working.
I'd put the acceptance condition next to the task so the reviewer can compare it with the result. Ask the agent to name uncertainties before editing, especially when the request contradicts existing behavior, leaves an error path unspecified, or assumes an API the repository doesn't use.
Here is a prompt you can adapt:
Before editing, identify the module that owns this behavior.
Find existing helpers and the production entry point.
List callers whose assumptions this change could affect.
Propose the smallest patch and a behavior check.
Show source locations for your conclusions. Flag anything unverified.
Wait for the plan to be reviewed before implementing it.
This is also how I'd handle an agent changing its answer when challenged. Ask it to show the relevant source, identify what changed, rerun the check, and show the result. Reassurance adds nothing to the review.

Match the failure to the check
Use this table when deciding what a task needs. The linked guides go deeper, while the checks here give you somewhere to start without turning every edit into a repository audit.
| Failure to look for | Check to request | Further reading |
|---|---|---|
| Partial or stale context, including a task that has outgrown the session | Identify the owning module and refresh the relevant source before continuing. | Repository context |
| Duplicate helpers, including copies in another service | Search for the behavior before adding it; inspect other repositories separately when the task crosses services. | Prevent duplicate functions |
| A shared change affects indirect callers | Trace callers back to the features they serve, then inspect the affected contracts. | Check what reaches a function before an AI refactor |
| A feature passes unit tests but has no production wiring | Exercise it through its route, UI action, job, or other entry point. | Passing tests and missing feature wiring |
| The implementation and the requested behavior disagree | Tie each acceptance condition to an implementation path and a behavior check. | Check the spec against what got built |
| New coupling or repeated maintenance work | Inspect imports across module boundaries and record follow-up work with an owner. | Prevent AI technical debt |
| Unverified packages or APIs, dependency updates, or unresolved license requirements | Check the actual package and API documentation; review dependency changes and your team's license policy separately. | Open-source AI code quality tools |
| An agent's confident answer has no supporting evidence | Require source locations and a reproducible check before accepting the conclusion. | Audit code AI already wrote |
| A proposed tool action exceeds the task's scope | Review the command and its permissions before authorizing it. | Security checks in a codebase audit |
| Repeated orientation work consumes the session | Record what was checked and keep the next question specific to the change. | Choose focused codebase context |
Search before adding another helper
Start with the behavior you need and a few likely names. For a currency formatter, I'd search for formatting and currency terms, open the candidate implementations, inspect their callers, and compare the rounding behavior before deciding to reuse one.
ripgrep supports recursive pattern searches and file globs. Run this first pass from a TypeScript repository's root.
rg -n --glob '*.ts' --glob '*.tsx' 'formatPrice|formatCurrency|currency' .
ripgrep's guide covers patterns, file filtering, quoting, and glob rules.
ripgrep output is where I'd start the investigation. An empty result for formatPrice leaves other names, ignored files, generated code, and other services to investigate.
I build Pharaoh, which maps TypeScript, JavaScript, Python, C and C++ repositories, answers questions through MCP, and runs as a hosted service. Its search_functions tool returns matching functions with their locations and signatures. get_module_context adds the module's exports, dependencies, endpoints, and callers from other modules.
Use those results to choose the source to inspect. A candidate with the right name still needs a behavior comparison.
Work one real change backward from its callers
For this example, use the public Pharaoh-so/cal.diy repository, revision 54343aa6, and the captured get_blast_radius result for checkAdminOrOwner at depth three.
Here is the API subsection, quoted unchanged from that captured output:
### api/v2
- apps/api/v2/src/modules/atoms/controllers/atoms.conferencing-apps.controller.ts: AtomsConferencingAppsController.listUserInstalledConferencingApps (3 hops)
- apps/api/v2/src/modules/atoms/controllers/atoms.event-types.controller.ts: AtomsEventTypesController.getAtomEventTypeApp (2 hops)
- apps/api/v2/src/modules/atoms/services/conferencing-atom.service.ts: ConferencingAtomsService.getUserConferencingApps (2 hops)
- apps/api/v2/src/modules/atoms/services/event-types-atom.service.ts: EventTypesAtomService.getEventTypesAppIntegration
For a proposed permission change, I'd open the listed service and controller files, check which roles they pass into the helper, read how they handle its answer, and choose a request-level test for the behavior being changed. The output gives the review a concrete starting point.
Work forward from the request, exercise an allowed role, repeat with a denied role, and compare both responses with the acceptance condition written before implementation.
This is a suggested review exercise. The captured output doesn't demonstrate a completed refactor or a passing test.
The full change-impact investigation records the prompt, source paths, measurements, and a grading correction.
Use the blast-radius guide for a broader dependency review.
The scope needs care. Pharaoh's interactive graph covers the mapped default branch, excludes test-file callers from blast-radius results, and bounds this query at three hops, so compare the result with your branch and inspect tests separately. It doesn't describe your uncommitted patch.
Test through the entry point after the edit
For a new feature, trace from the route registration or UI action to the new function, check the arguments along the way, and run the acceptance condition through that path. A test that imports a helper directly leaves its production wiring unchecked.
Pharaoh's get_unused_code can show entry-point paths for named functions on the mapped default branch, so check the revision, inspect your branch's new wiring locally, and test it before merge.
For unused-code findings, Pharaoh reports Dead when no entry point reaches the function, no other file names it, and no production file imports its file. Every signal must agree.
Possibly unused means no entry point reaches it, but another file names it or its file is imported. Inspect those references before deleting it.
For handlers and jobs, use the feature-wiring guide alongside local tests, inspect the registrations, follow execution into the new code, and read its synthetic fixture as an example rather than a customer result.
Keep small-team guardrails small enough to use
I'd make the pull request carry the evidence a reviewer needs, especially when the author is also the person deploying it:
- State the behavior change and link the acceptance condition.
- Keep unrelated cleanup in a separate patch.
- Name the affected callers, list the checks that ran, identify gaps, and attach the evidence.
- For a risky release, write down the rollback action and who will take it.
Give permissions and shared contracts a deliberate review, even when the diff is short. Ask a reviewer to examine the behavior being preserved, the new failure paths, the configuration assumptions, and the callers that need to keep working.

Use the package's own scripts. npm run lists them when called without a script name, so check the npm documentation, read the available commands, identify any required setup, and choose the checks your repository actually defines.
npm run
npm can run the existing lint and test scripts.
tsc is another option if it's available in your shell with an appropriate project configuration. Prefer the existing type-check script.
tsc --noEmit
TypeScript documents --noEmit as disabling output files. Keep a request-level behavior check alongside type checking.
If you use Pharaoh PR Guard, it runs on Pro workspaces and checks new unreachable exports, breaking signature changes with existing callers, exact function duplicates, and change blast radius. Its findings are advisory by default, published as a neutral GitHub check.
After an escaped bug, record the failed behavior, identify the missing check, and put that check into the relevant workflow. Use the audit guide when you're reviewing accumulated changes rather than one patch.
Try the loop on the next shared function you change
Pick the function, find its callers, choose the behavior check, and keep the source revision with your notes before asking the agent to edit.
To try this on your repository, connect Pharaoh, install the GitHub App on the owning account, connect your client, and sign in with GitHub.
During the trial and on Pro, every repository stays live, answers questions, and is re-mapped when a push reaches its default branch.
Your next pull request should show how the changed behavior is reached and how you checked it.