Prevent Claude Code from Installing Random Dependencies

Claude Code can run npm install, pip install, and other package managers freely. When it encounters a missing module, its natural behavior is to install it — without asking. This creates supply chain risks and dependency bloat.

The Problem

Unauthorized npm install adds 300MB to node_modules

Claude encountered a missing module during refactoring and ran npm install lodash without permission. The lockfile changed, node_modules grew by 300MB, and the CI pipeline broke because the new dependency wasn't in the approved list.

Supply chain risk from unknown packages

AI models can be manipulated into installing malicious packages through typosquatting or hallucinated package names. A pip install of a non-existent package name could install a malicious lookalike.

What Gets Blocked

The dependency-install-guard hook intercepts package manager commands:

What's Allowed

Quick Fix

Option 1: Install the full safety suite (includes dependency guard):

npx cc-safe-setup

Option 2: Install just the dependency guard:

npx cc-safe-setup --install-example dependency-install-guard

Check your setup

npx cc-health-check

20-point diagnostic. Score 80+ means production-ready.

Full production setup →

Related Pages

Prevent rm -rf · Prevent force push · Prevent secret leaks · Prevent git reset --hard · Prevent syntax errors · Prevent temp file accumulation

cc-safe-setup · 667 hooks · 9,200+ tests · GitHub

New: Hook if field — reduce overhead (v2.1.85)

Learn more: Production Guide · All Tools