Odel
pkgdiet

pkgdiet

Local
@om-tajne3JavaScriptMITUpdated 5 days ago

Put your node_modules on a diet - find unused dependencies, analyze health, and reduce size

๐Ÿฅ— PkgDiet

npm version npm downloads License: MIT Node.js >=18

Put your node_modules on a diet.

PkgDiet is a proactive dependency governance tool that helps you find unused dependencies, analyze package health, and reduce node_modules size. It doesn't just ask "is it safe?" โ€” it asks "is it optimal?"

Our Vision: PkgDiet's mission is to become an open standard for dependency intelligence in AI-assisted software development. Our goal is simple: whenever a developer, CI pipeline, or compatible AI agent needs to evaluate, install, replace, or audit a dependency, PkgDiet should provide trusted, machine-readable insights through transparent, opt-in integrations.


Quick Start

Run it instantly in any Node.js project (no installation required):

npx pkgdiet

To clean up unused dependencies automatically:

npx pkgdiet --fix

What You Get

PkgDiet scans your codebase's AST and NPM registry data in seconds to give you a pristine, actionable report:

- Scanning imports...
โœ“ Scanned 141 files, found 54 imports
- Checking health of 44 packages...
โœ“ Health check complete: 10 issues found
- Analyzing dependency sizes...
โœ“ Size analysis complete: 40.5 MB total

โ•ญโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ•ฎ
โ”‚ ๐Ÿฅ— PkgDiet v1.2.0                                    โ”‚
โ”‚ Put your node_modules on a diet...                   โ”‚
โ”‚ Project: express                                     โ”‚
โ”‚ Dependencies: 44 direct โ”‚ 141 files scanned          โ”‚
โ”‚ node_modules: 40.5 MB                                โ”‚
โ”‚    Overall Score:  67/100  โš ๏ธ                        โ”‚
โ”‚    โ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘                    โ”‚
โ•ฐโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ•ฏ

๐Ÿ—‘๏ธ  UNUSED DEPENDENCIES (1 found โ€” saves ~21.2 KB)
โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€
   โšซ hbs                      dev      21.2 KB      โ†’ npm uninstall hbs

๐Ÿฅ  HEALTH WARNINGS (10 issues)
โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€
   Package                    Score    Issue
   โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€
   ๐Ÿ”ด pbkdf2-password          29       Unmaintained (4yr) ยท Single maintainer ยท Low downloads
   ๐Ÿ”ด encodeurl                57       Unmaintained (2yr)
   ๐ŸŸก once                     70       Single maintainer

๐Ÿ“ฆ  SIZE ANALYSIS
โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€
   Package                      Install Size    % of node_modules
   โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€
   ๐ŸŸง eslint                     2.77 MB         6.8%
   ๐ŸŸง mocha                      2.22 MB         5.5%
   โœ“  42 other packages under 5% โ€” no action needed

๐Ÿ’ก  BETTER ALTERNATIVES (1 suggestion)
โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€
   ๐Ÿ”Œ body-parser โ†’ express.json() built into Express 4.16+, no separate install needed

โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€
  Action summary: 1 to remove ยท 10 to investigate ยท 1 to swap
  Run pkgdiet --fix to remove unused ยท --json for full machine-readable output

Features

  • AST-Based Unused Detection: Safely flags installed packages that are never imported (handles TypeScript, JSX, dynamic imports, and NPM scripts).
  • Health & Rot Scoring: Detects the "Bus Factor" (single maintainer) and abandoned packages before they become technical debt.
  • Smart Alternatives: Recommends modern, lightweight replacements for legacy bloat (e.g., dayjs instead of moment, picocolors instead of chalk).
  • Pre-Install Gate: Run pkgdiet check <package> to evaluate a library before adding it to your project.
  • MCP Server for AI Agents: Give compatible AI coding assistants the ability to evaluate dependency health using PkgDiet's machine-readable data before recommending or installing packages. Install globally in one click: npx pkgdiet mcp-install
  • CI/CD Ready: Use pkgdiet ci to parse package-lock.json diffs in GitHub Actions and block PRs that introduce unhealthy dependencies.

Configuration

PkgDiet works out of the box with zero configuration. However, teams can enforce custom policies by running npx pkgdiet init to generate a .pkgdietrc.json:

{
  "minHealthScore": 60,
  "maxNodeModulesSizeMB": 300,
  "ignoreRules": ["chalk"],
  "telemetry": false
}

Telemetry (Local Only)

By default, PkgDiet writes anonymous, purely local usage metrics to a .pkgdiet-metrics.json file in your repository to track the amount of time and disk space saved. No data is ever sent off your machine. You can disable this local logging entirely by adding "telemetry": false to your .pkgdietrc.json or by setting the PKGDIET_TELEMETRY_DISABLED=1 environment variable.


Commands

CommandDescription
npx pkgdietRun full repository audit
npx pkgdiet --fixPreview unused dependencies and apply approved removals
npx pkgdiet check <pkg>Check health/size of a single package
npx pkgdiet initGenerate config and GitHub Actions workflows
npx pkgdiet ciRun PR gate checks based on lockfile diffs
npx pkgdiet mcpStart the JSON-RPC server for AI agents
npx pkgdiet mcp-installAuto-configure MCP for Claude Desktop

License

MIT ยฉ Om Tajne