A coding agent asked to "add caching" or "fix the date parsing" will often reach for a package. It reads the manifest, sees a name that looks right, and runs an install. What it usually does not do is open the resolved tree that the lockfile records and check what the install will actually pull in. That gap is where review gets expensive: the reviewer ends up reconstructing the dependency change from a diff of hundreds of lines.
The lockfile is the artifact that answers the question "what will actually be installed." npm ls lists the dependencies installed in node_modules and returns a non-zero exit code when the resolved tree does not match what package.json should produce, which is a ready-made consistency check for the agent to run the npm ls walkthrough. npm ls --all prints the full tree including transitive dependencies, and --depth caps how far it descends the Stack Overflow answer on npm ls. Those are the commands a prompt can name explicitly.
The second reason is supply chain. A model can generate an import for a package that does not exist, and an attacker can register that name; the defense is to look up every added name in its registry before anything installs it and to check that changes to the lockfile match the added packages the SpecStory review checklist. Dependency provenance is called out as a pre-screening standard for generated code: confirm the package exists on the canonical registry, matches the intended library, is needed at all, and is pinned through the lockfile, with watch for slopsquatting where attackers register names an assistant might hallucinate the Metacto checklist. Reading the lockfile first is how an agent can satisfy that standard on its own.
There is a live threat model here. One campaign deliberately engineered npm packages to be selected and installed by AI coding agents rather than by people, tracking more than 60 packages and over 300 versions across a seven-month operation, with a parallel effort distributing more than 1,700 malicious packages across npm, PyPI, Go and Rust the CSA research note. Agents that install with minimal vetting are the target. A prompt that forces the tree into the open before the install is a cheap control.
Decision rule: when the report is mandatory
Use the report as a hard precondition when any of these is true, and skip it when none are.
| Condition | Report required | Why |
|---|---|---|
| Manifest edit adds, removes or widens a dependency | Yes | The resolved tree changes |
| Only application code changes, no manifest edit | No | The tree is untouched |
| Lockfile diff touches a transitive entry the agent did not name | Yes | Someone else's dependency moved |
Lockfile diff appears after a plain npm install with no manifest edit | Yes | Installs can rewrite the lockfile |
| Overrides or resolutions block is added | Yes | Every match of that name is forced |
That last row matters more than it looks. npm install can rewrite package-lock.json even when the request did not ask for it, a behavior developers have documented repeatedly the Stack Overflow thread on lockfile rewrites. If the agent ran an install as a side effect, the report is the only place a reviewer will see it.



