What Is npm install? Why Your AI Agent Keeps Running It
npm install reads your project's package list and downloads everything into a folder. Here is what that folder and lock file are, and what is safe to ignore.
What is npm install? It is the command that reads your project's shopping list of code libraries, downloads them from a public registry, and puts them in a folder named node_modules so the project can run. Your AI coding agent runs it constantly: when it starts a project, when it adds a feature that needs a new library, and whenever something fails with a "module not found" error. Seeing it scroll past is normal. Knowing what it just did to your project is the part most people skip.
The shopping list and the shelf
Three things are involved, and the vocabulary is simpler than it sounds.
A package is a bundle of someone else's code. The npm documentation defines it as a file or directory described by a package.json file.
package.json is your project's shopping list. It names the packages your app needs and which versions are acceptable.
node_modules is the shelf where the downloaded packages end up. npm's documentation describes a module as any file or directory in the node_modules directory.
When you run npm install with no arguments, npm's own documentation says it installs the dependencies listed in package.json into the local node_modules folder. When you run npm install some-package, it adds that package to the list as well.
What the files are, and which ones matter
File or folder | What it is | Commit it to git? | Safe to delete? |
|---|---|---|---|
| Your project's list of packages | Yes | No, the project stops working |
| The exact versions that were installed | Yes | Only if you accept versions may shift |
| The downloaded code itself, often thousands of files | No | Yes, |
| Settings, sometimes including registry tokens | Check first, never commit tokens | Only if you know what it holds |
The lock file is the one people misunderstand. npm's install documentation says that when a lock file is present, the installation is driven by it. That is what makes your teammate, your hosting service, and your own laptop all end up with identical packages. If your AI agent deletes the lock file to "fix" an error, you have lost that guarantee, and the next install may pull newer versions that behave differently.
The node_modules folder is large and rebuilt on demand, so it should not be in your repository. A .gitignore file lists things git should leave out. If your agent commits node_modules, ask it to remove the folder from tracking and add it to .gitignore.
Why the agent keeps running it
First run on a new copy. A fresh download of a project has no node_modules until someone installs.
After editing the package list. Any new or changed dependency needs an install before it exists on disk.
To fix missing-module errors. The commonest cause is that packages were never installed, or were installed in a different folder.
To rebuild a broken state. Deleting node_modules and installing again is the classic reset.
A related command is npm ci. It does a clean install strictly from the lock file and removes any existing node_modules first, which makes it the usual choice for automated builds and hosting. If an install works on your laptop but fails on your host, a difference between the two environments is the usual cause. For a deeper look at the lock file and why agents rewrite it, see what a lockfile is and why AI agents change it.
The risk nobody mentions: install runs other people's code
Packages can include scripts that run automatically during installation. That is how legitimate tools compile native components, and it is also how malicious packages run code on your machine the moment they are installed. Two specific risks show up with AI agents.
A package that does not exist, or looks like one that does. Models sometimes invent a plausible package name, and attackers register names like that. An AI hallucinated a package that does not exist describes the pattern and how to check.
An agent with terminal access installing without asking. Letting it run commands unchecked is a decision, not a default. Read whether it is safe to let an AI agent run shell commands before you grant that.
A short checklist before you accept a new package
Ask the agent what the package does and why a built-in alternative is not enough.
Look the package up on the npm website and check the name is spelled exactly as the project documentation spells it.
Check that it is actively maintained, has a real repository link, and is used by other projects.
Look at how many packages it pulls in. The install output and the lock file show it, and a long tail is a bigger surface to trust.
Run the project afterwards and confirm only the intended change happened. Then review the diff of package.json and the lock file before you save the work.
An agent that adds libraries casually is a habit you can change with instructions, as stopping AI coding agents from adding dependencies explains. For the bigger picture of how these tools fit together, see the guide to AI coding tools.
Reading the output without panic
After an install you will often see notices about funding, deprecated packages, or vulnerabilities. A deprecation notice means a library has been superseded, which is worth noting but rarely urgent. A vulnerability count means npm compared your installed versions with a database of known problems. The number alone does not tell you whether any of them can be reached from your app, so auditing your dependencies with AI is a better next step than running a forced fix that upgrades everything at once.
FAQ
Is npm the same as Node?
No. Node runs JavaScript outside a browser. npm is the package manager that comes with it and fetches libraries from the registry.
Why is node_modules so big?
Each package brings its own dependencies, and those bring theirs. A project with a handful of direct packages can end up with hundreds of folders.
Can I delete node_modules?
Yes. It can be recreated by running the install command again, as long as your package.json and lock file are intact.
Is it safe to run npm install on a project I downloaded?
Only if you trust where it came from. Installing runs scripts from every package in the tree, so treat an unknown project like an unknown program.
How did this land?
About the author

Developer Advocate
Steve builds something with Swarmz every week and writes up what worked, what broke, and what he'd do differently. Tutorials and hands-on guides are his lane.


