GuidesUpdated

Why did my coding agent change the lockfile for a small fix?

Trace an unexpected package-lock or pnpm-lock diff to the command and dependency decision behind it, then review and reproduce the PR safely.

On this page

A one-line UI fix arrives with hundreds of lockfile lines. That could be a real dependency change, a stale manifest being reconciled, or a package-manager mismatch; size alone can't tell you. Pause the agent, keep the patch, compare manifest and lockfile, and ask which install command ran. The example here: an agent added an icon package for a settings button.

Canopy Git diff view showing changed project files
Canopy Git diff view showing changed project files

Keep the diff and find the cause

Record the PR head, changed files and the agent's install or audit commands. Read package.json beside the lockfile, plus any packageManager field or second lockfile. A new direct dependency, like the icon package, explains a large transitive diff.

A lockfile change with no manifest edit may come from a stale lockfile, a different package-manager version or an unintended command. Don't delete the lockfile to shrink the PR; that hides a reproducibility problem. Don't accept every generated line without naming the dependency decision either.

  • Ask whether an existing component or dependency already provides the icon.
  • Keep the original diff while you investigate.

Check the repository's package manager

Find the committed lockfile and documented install command. In a pnpm repo, npm install can add package-lock.json or rewrite unrelated state. In an npm repo, npm install can update the lockfile when ranges disagree with package.json; npm ci requires them to match and writes neither.

Use the project's pinned tooling; don't mix managers to repair a strange diff. Record versions too: different npm or pnpm versions serialize metadata differently.

Questions that separate a needed update from install noise.
EvidencePossible interpretationDecision
New manifest dependency and matching lock entriesAgent added a package for the featureReview need, source, version and transitive changes
Lockfile edits without manifest changeStale lockfile, resolver/config change or accidental rewriteReproduce with the documented manager before keeping it
Second lockfile from another managerAgent used an inconsistent install routeConfirm the team convention; remove after a clean reproducibility check
Many unrelated version upgradesBroad install, audit fix or range driftSeparate the upgrade decision from the feature

Review the real dependency change

GitHub's dependency review lists added, updated and removed packages with known vulnerability and license data, but warns some changes won't appear there, so read the source diff too. For the icon package, check the resolved version, new transitives, runtime or dev placement and any install scripts.

A clean scan doesn't prove a package is needed. If it isn't, ask for a fix with existing assets, then regenerate the lockfile with the repo's tool instead of hand-editing it.

  • Check that shipped code imports the package.
  • Don't run an automatic audit fix inside this review.

Reproduce from a clean checkout

Use a disposable clean checkout at the PR head with the documented runtime and package-manager version. Install with the frozen command, such as npm ci, which fails if package.json and the lockfile disagree instead of rewriting them. Then run the build and feature check.

The agent's long-lived worktree may lean on existing node_modules or untracked files. Record the command, versions, result and commit.

  • Check that the install leaves tracked files unchanged.
  • Run the settings-button interaction and a relevant test after the clean install.

Close with one explicit PR decision

Keep the lockfile when it records an approved dependency or needed reconciliation. Remove a second manager's output or unrelated upgrades in a reviewed edit and rerun the clean install. Split a broad upgrade from the UI fix where you can.

In Canopy, read the final diff at the same commit as the app preview. A green build doesn't tell you what will be installed. The PR description states which package changed, why, the locked version and the clean-install result.

  • Recheck the latest PR head after the agent's final edit.
  • Let the designated reviewer accept the install and supply-chain implications.

Copyable resources

Unexpected lockfile diff review

Use a disposable checkout for clean installs. Don't paste private registry tokens or full environment files.

Task / PR / latest head commit: [ ]
Manifest, lockfile, packageManager field and install command: [ ]
Agent command that changed dependencies: [ ]
Direct packages added/removed/updated and why: [ ]
Transitive changes, install scripts, vulnerability/license signals: [ ]
Could existing code or assets do the job? [ ]
Unrelated second lockfile or broad upgrade: [ ]
Clean checkout runtime and manager versions: [ ]
Frozen/clean install command and result: [ ]
Tracked files unchanged after install? [ ]
Feature check and tests at the same commit: [ ]
Reviewer decision: keep / regenerate / separate / reject, with owner: [ ]

Frequently asked questions

Should I revert a lockfile change if the code change is tiny?

Not blindly. Identify the dependency decision and reproduce the project install first. A small source change can need a real lock update, and reverting it can break clean installs.

Why did package-lock.json appear in a pnpm repository?

A second package manager probably ran. Confirm the documented manager and packageManager field, then remove the stray file once the expected install and build reproduce.

Does GitHub dependency review show every relevant change?

No. GitHub warns that some manifest or lockfile changes may not appear. Read the source diff and run the repo's clean install too.

Does a green npm audit settle the review?

No. It reports known advisories, not whether the package is needed, how it behaves or whether the feature works.

More questions and answers →

Sources and further reading