Using AI to Audit and Reduce Project Dependencies
How to use AI to identify bloated, redundant, and unnecessary packages in your project — and decide what's safe to remove.
Dependency bloat is one of those problems that accumulates silently. You add a package to solve one problem, another to solve the next, and six months later your package.json has 80 direct dependencies you can barely explain. Each one is a surface area for security vulnerabilities, a potential breaking change in the next upgrade cycle, and maintenance overhead that grows without you noticing.
AI coding assistants are surprisingly effective at untangling this. They’ve seen a large cross-section of the ecosystem, so they can identify candidates for removal, spot redundant functionality, and suggest built-in replacements much faster than manual investigation. This post covers how to run a practical dependency audit with AI.
Why audits fail without AI
The traditional approach to dependency audits is tedious: open package.json, look up each package, check its last release date, grep your codebase for imports, make a judgment call. For a 60-package project this is a half-day job even if you’re disciplined about it. Most developers don’t finish it.
AI changes the economics. The analysis work — identifying what a package does, checking whether the standard library covers it now, finding all the places it’s used in context — is exactly the kind of research task where AI is fast. What takes you an hour of documentation archaeology takes the model a few seconds.
The judgment call still belongs to you. The AI can tell you that lodash.clonedeep has a native equivalent in structuredClone(). Whether your project still supports environments where structuredClone isn’t available is a decision only you can make.
Start with the full picture
Before anything else, dump your full direct-dependency list into the conversation. For npm:
npm list --depth=0 --json | jq '.dependencies | keys'
For Python projects with pip:
pip list --not-required --format=columns
Paste the output into your AI context along with a brief description of your runtime:
This is a TypeScript Node.js API server (Node 20+) using Express. It runs in
our own infrastructure; we don't ship to browsers. Here are our direct
dependencies:
[paste list]
For each dependency:
1. What does it do in one sentence?
2. Does a modern Node.js built-in or a simpler alternative now cover it?
3. Could it be a transitive dependency of something else we already have?
The last question matters. If lodash only appears because some-other-lib depends on it, removing the direct reference in your package.json won’t reduce your install size — some-other-lib will still pull it in. The AI can usually spot this if you give it enough context about your stack.
Identify redundant packages
Redundancy in dependencies usually falls into three patterns.
Two packages that do the same thing. A codebase that has both axios and node-fetch for HTTP requests, or both dayjs and date-fns for date manipulation. This often happens when different engineers add packages independently, or when a migration started but wasn’t finished.
A package whose functionality landed in something you already have. You added uuid before your database library added its own UUID helpers. You have qs from before URLSearchParams was widely available.
A package superseded by a language or platform feature. Node 18+ ships native fetch. Node 22+ ships native --env-file support. TypeScript’s satisfies operator eliminated some validation patterns that previously needed library support.
A single prompt that surfaces all three patterns:
Review this dependency list for a Node 20+ TypeScript project. Identify:
1. Pairs of packages with overlapping functionality
2. Packages whose features are now covered by Node.js 18–22 built-ins
3. Packages whose features are now covered by TypeScript 5.x itself
For each candidate, list the import paths I should grep for to understand
how much it's actually used.
The import paths give you a focused starting point for the next step, rather than grepping your whole codebase blind.
Run a usage analysis per candidate
Once you have a shortlist, do a targeted usage check for each package. The pattern is consistent: grep for imports, paste the results, and ask for a migration assessment.
# Find all files that import a package
grep -r "from 'lodash'" src/ --include="*.ts" -l
# Find all specific symbols imported
grep -rh "from 'lodash'" src/ --include="*.ts" | sort -u
Paste this into the conversation:
We're considering removing lodash. Here are all the lodash symbols we import:
_.debounce — used in 3 files
_.omit — used in 1 file
_.isEqual — used in 2 files
For each symbol: what's the simplest native or tiny-library replacement,
and roughly how many lines of migration work would it involve?
This gives you an effort estimate, not just a list of candidates. Some packages look trivial to remove until you discover the migration touches 15 files and has three edge cases.
Watch out for invisible usage
Some packages are consumed without explicit import statements — in configuration files, as CLI tools, or through plugins that call their APIs internally. AI is unreliable here because it cannot see your build toolchain or test setup.
Before removing any package, check these manually:
- Build tool config (
vite.config.ts,webpack.config.js,esbuild.config.js) - Test runner config (
vitest.config.ts,jest.config.js) - Scripts in
package.json’s"scripts"section - CI configuration (
.github/workflows/*.yml) - Any files in a root-level
scripts/ortools/directory
These files are worth pasting directly into the conversation:
I'm about to remove 'glob' from my dependencies. Here are my config files
and npm scripts. Does any of them depend on 'glob' directly, or use a plugin
that requires it?
[paste relevant file contents]
This one check has prevented me from accidentally breaking build pipelines more than once.
Validate one removal at a time
The safest workflow for each removal:
- Remove the package from
package.json - Run
npm installto update the lock file - Run
npx tsc --noEmitto catch type errors - Run your full test suite
- If you have a build step, run it and verify the output
Do this one package at a time. Removing five packages in one commit makes it substantially harder to identify which removal broke the build.
For the removal commits themselves, let AI draft the message:
I removed the 'ms' package and replaced its one usage in src/lib/timeouts.ts
with a plain multiplication. Write a conventional commit message for this.
What works in practice: The most reliable workflow is to use the AI analysis pass to build a shortlist of candidates, then validate each one manually before touching
package.json. AI occasionally hallucinates that a native equivalent exists when it doesn’t, or proposes a migration that works in simple cases but breaks on edge cases your code hits. The AI gets you 80% of the way in 20% of the time — the remaining 20% requires your judgment and your tests. Trust the shortlist; verify the migrations.
What a realistic audit produces
A solid audit of a mature Node.js or TypeScript project typically surfaces 5–15 packages worth removing: a few redundancies, a few packages superseded by platform features, and a few packages kept out of inertia from migrations that never fully finished.
Each removal shrinks node_modules, reduces your npm audit surface, and makes the dependencies you keep easier to reason about. That matters most during dependency upgrades — a leaner graph has fewer cross-version conflicts and fewer packages where a breaking change requires coordinated updates.
None of this is glamorous work. But it compounds: a codebase that gets audited every six months drifts far less than one that gets audited only when something breaks. With AI doing the analysis pass, the whole process takes under an hour rather than a full afternoon.
For the packages you decide to keep and update, Upgrading Dependencies with AI covers how to handle the ones you’re not ready to remove.

