PkgDiet is a dependency policy tool for AI-assisted JavaScript and TypeScript development, and also a local MCP (Model Context Protocol) server. Its core goal is to prevent AI coding agents from introducing non-existent, deprecated, vulnerable, or typosquatted npm packages when generating code.
Purpose
AI coding agents (such as Claude Code, Codex, Cursor, Windsurf, Cline) may propose installing non-existent, deprecated, vulnerable, or typosquatted packages when generating code, and there is currently no built-in mechanism to stop them from performing the installation. PkgDiet intercepts the npm install / pnpm add / yarn add commands generated by AI agents, blocking unapproved installations before the commands execute.
Main Capabilities
- Agent-level enforcement interception: Uses each agent's native hook API (such as the PreToolUse hook of Claude Code and Codex) to intercept installation commands. When an agent generates a Bash tool call containing npm install, the registered hook script runs first; if PkgDiet returns a non-zero exit code, the agent sees the rejection reason and aborts the installation, and the command never executes.
- Three-stage policy loop:
- Repository policy: A single .pkgdietrc.json file specifies what the project allows, warns about, or blocks.
- Agent Hook (enforcement): The native PreToolUse hook of Claude Code and Codex intercepts installation commands before execution; MCP's check_dependency gives instructions before other agents write commands.
- CI gate (fallback): npx pkgdiet ci runs in GitHub Actions, diffs package.json against the base commit, and fails the PR if newly added packages violate policy.
- Shared core engine: All interfaces use the shared core engine @pkgdiet/core, applying the same evaluation logic.
- MCP integration: As a local MCP server, AI coding agents can connect to obtain:
- check_dependency: Evaluates npm packages according to the local .pkgdietrc.json policy, returning structured ALLOW, WARN, or BLOCK verdicts with evidence.
- suggest_alternative: Queries PkgDiet's curated dataset to find modern, lighter, and well-maintained alternatives for blocked packages.
- Built-in intelligence (all free, no paid services):
- OSV vulnerability database: Checks package versions for known CVEs.
- npm registry provenance verification: Verifies signed npm attestations.
- Typosquatting detection: Performs edit distance checks against more than 15 popular package names.
- Lockfile pinning validation: Requires exact version pinning in CI.
- Dependency confusion detection: Blocks internal-prefix packages found on the public registry.
Usage
- Provides a one-click installation command (the specific command content is not yet provided).
- Provides CLI commands (the specific command list is not yet provided).
- Configured via .pkgdietrc.json.
- Can be integrated with AI coding agents as an MCP server.
- Can be run in CI via npx pkgdiet ci.
Applicable Scenarios
- Teams or individuals using AI coding agents for JavaScript/TypeScript development who want to prevent agents from introducing risky dependencies.
- Projects that need to automatically check in the CI process whether newly added dependencies comply with policy.
- Scenarios where you want AI agents to obtain dependency evaluations and alternative suggestions via MCP before writing installation commands.
Limitations
- Primarily aimed at the JavaScript and TypeScript ecosystem (npm, pnpm, yarn).
- Agent-level enforcement interception depends on each agent's native hook API; it currently explicitly supports the PreToolUse hook of Claude Code and Codex; other agents receive instructions via MCP's check_dependency before writing commands.
- The specific installation command, CLI command list, and configuration item details are not yet fully provided in the supplied materials.local .pkgdietrc.json policy, returning structured ALLOW, WARN, or BLOCK verdicts with evidence.
- suggest_alternative: Queries PkgDiet's curated dataset to find modern, lighter, and well-maintained alternatives for blocked packages.
- Built-in intelligence (all free, no paid services):
- OSV vulnerability database: Checks package versions for known CVEs.
- npm registry provenance verification: Verifies signed npm attestations.
- Typosquatting detection: Performs edit distance checks against more than 15 popular package names.
- Lockfile pinning validation: Requires exact version pinning in CI.
- Dependency confusion detection: Blocks internal-prefix packages found on the public registry.
Usage
- Provides a one-click installation command (the specific command content is not yet provided).
- Provides CLI commands (the specific command list is not yet provided).
- Configured via .pkgdietrc.json.
- Can be integrated with AI coding agents as an MCP server.
- Can be run in CI via npx pkgdiet ci.
Applicable Scenarios
- Teams or individuals using AI coding agents for JavaScript/TypeScript development who want to prevent agents from introducing risky dependencies.
- Projects that need to automatically check in the CI process whether newly added dependencies comply with policy.
- Scenarios where you want AI agents to obtain dependency evaluations and alternative suggestions via MCP before writing installation commands.
Limitations
- Primarily aimed at the JavaScript and TypeScript ecosystem (npm, pnpm, yarn).
- Agent-level enforcement interception depends on each agent's native hook API; it currently explicitly supports the PreToolUse hook of Claude Code and Codex; other agents receive instructions via MCP's check_dependency before writing commands.
- The specific installation command, CLI command list, and configuration item details are not yet fully provided in the supplied materials.