Skip to content
AI Skills Central

Type to search Agent Skills, workflows, tutorials, tools and the glossary.

Workflow recipe

Audit and upgrade risky dependencies with an agent

Audit project dependencies with Trail of Bits' supply-chain-risk-auditor skill, group upgrades by risk, update one batch on a branch and prove tests pass.

By Intermediate55 min5 steps
Bookmark

Bookmarks are kept in your free account, so you can find this page again on any device.

Sign in to bookmark
On this page

To audit and upgrade risky dependencies with an agent, run your package manager’s lockfile audit on a fresh branch, use Trail of Bits’ supply-chain-risk-auditor skill to surface advisories, install scripts and unmaintained packages, and group fixes into safe patch bumps versus major migrations. Apply one risk group at a time, inspect the lockfile and changelog diff, and merge only after your real build and test suite pass.

Running npm audit fix --force or asking an agent to “update all packages” usually produces a 4,000-line lockfile diff mixed with silent major-version breaks. Splitting audit triage from upgrades keeps every pull request small enough to review and prevents an agent from pulling in unvetted transitive packages with postinstall scripts.

TerminalAbout 10 min

1. Create a clean branch and capture baseline audit output

Start from a clean commit and record both the current test status and raw vulnerability report before changing any package:

git checkout -b chore/dependency-audit
npm audit --json > /tmp/audit-before.json || true
npm outdated --json > /tmp/outdated-before.json || true
npm test

If you use Trail of Bits’ supply-chain-risk-auditor, install it at the pinned commit we reviewed so the agent can also check abandoned upstreams and install scripts:

npx skills add trailofbits/skills@149d7b21f4067765b82e67029730b42d228ef4b4 --skill supply-chain-risk-auditor -a claude-code

Use -a codex or -a cursor for Codex or Cursor. Confirm your baseline npm test passes before touching package.json. Capturing raw JSON files first also ensures the agent cannot silently drop a moderate advisory or re-run an unpinned online scan with different flags halfway through the session.

Claude CodeAbout 15 min

2. Triage advisories and group upgrades by risk

Ask the agent to inspect the audit report and lockfile without editing anything yet. Separating analysis from edits prevents the model from rushing into a speculative major-version rewrite before you know whether an advisory even affects production code.

Dependency risk triage · Claude Code, Codex or Cursor
Read /tmp/audit-before.json, /tmp/outdated-before.json and our package.json / lockfile. If the supply-chain-risk-auditor skill is installed, use it to flag advisories, packages with install scripts and abandoned upstreams. Rules: - Do NOT edit package.json, the lockfile or source files yet. - Separate direct dependencies from transitive ones, and production dependencies from dev-only build tools. - Separate safe patch/minor security fixes from major-version upgrades that carry breaking changes. - Flag any package that runs postinstall or preinstall scripts. Output a Markdown table: Package | Current | Target | Risk group (patch-security / minor / major / replace) | Reason and affected code paths.

Read the table yourself before approving any edits. Check reachability on every high or critical item: a regex denial-of-service bug inside a dev-only linter has a very different urgency from a prototype-pollution flaw in an HTTP request parser. Move any major-version upgrade (such as a framework jump) out to its own branch so security patches are never held up by a refactor.

Claude CodeAbout 15 min

3. Apply the patch-security batch only

Have the agent upgrade only the approved patch and minor security group, keeping package.json changes minimal and lockfile churn easy to inspect.

Apply approved security upgrades · Claude Code, Codex or Cursor
Apply only the [APPROVED PATCH-SECURITY PACKAGES] from the triage table. Rules: - Do NOT run "npm audit fix --force" or bump major versions outside the approved list. - Prefer direct dependency bumps over lockfile overrides unless the parent package has no patched release yet. - After updating, inspect git diff package.json and check whether any newly added transitive package introduces a postinstall script or changes registry host. - Stop and ask if a transitive override is required.

Check git diff package.json as soon as the agent finishes. Every version change in package.json should match a row you approved in step 2. Then scan the lockfile diff for "hasInstallScript": true (in package-lock.json) or unexpected tarball hosts before running your test suite, so a freshly pulled transitive dependency cannot execute unreviewed code on your machine.

TerminalAbout 10 min

4. Prove the build, tests and audit delta

Run your build, type checks, test suite and a fresh audit yourself in the terminal rather than relying on the agent’s summary:

npm run build
npm test
npm audit --omit=dev

Compare npm audit --omit=dev against /tmp/audit-before.json. Confirm that every targeted high or critical production advisory is cleared, that git status shows only package.json and the lockfile (plus any intentional import fixes you approved), and that no new advisory appeared from a transitive bump. If your project has a smoke test or end-to-end check against a local dev server, run it now before opening the pull request. Remove the temporary /tmp/audit-before.json and /tmp/outdated-before.json files when you finish.

GitHubAbout 5 min

5. Open a scoped pull request with evidence

Keep the pull request description short and auditable so reviewers can approve it in five minutes instead of skimming thousands of lockfile lines:

  • List every upgraded package with old and new versions and links to the relevant advisory IDs or changelogs.
  • Paste the before/after npm audit --omit=dev summary counts.
  • Note whether any newly added transitive package includes a lifecycle install script and why it is expected.
  • Record any deferred major upgrades as separate linked follow-up issues, and state which local build and test commands passed.

Check it worked

Verification checklist

0 of 7 done

When it goes wrong

If a transitive vulnerability has no upstream fix yet, do not let the agent force a major version of an unrelated direct dependency. Check whether the vulnerable code path is actually reachable in your app (for example, a build-time-only CLI tool vs a production request handler). When a vulnerability is genuinely unreachable or awaits an upstream patch, record a short exception note with the advisory ID, why it does not apply to your runtime, and a calendar review date thirty days out so it never turns into permanent invisible debt.

If tests fail after a minor upgrade, revert that single package bump first (git checkout -- package.json package-lock.json and re-apply the rest) so one breaking minor release does not block the clean security patches. Keep the failing package in a separate branch with the exact stack trace so you can inspect its release notes calmly instead of rushing a workaround into a security pull request.

If the agent tries to run npm install with arbitrary registry flags or disables lockfile integrity checks, stop the session and check your permission rules in Permissions and sandboxing for coding agents.

Variations

For pnpm workspaces, swap npm audit for pnpm audit --json and use pnpm.onlyBuiltDependencies to keep install scripts blocked unless explicitly allowlisted in package.json.

For Python projects using uv or poetry, swap step 1 for uv pip check and pip-audit -f json (or Trail of Bits’ bundled Python advisory scripts inside supply-chain-risk-auditor), and apply the same patch-first grouping on pyproject.toml and uv.lock.

For scheduled hygiene across several repositories, run step 2 only in a read-only weekly CI job that posts the triage table to an issue, and let an engineer trigger steps 3 to 5 on a branch once the batch is approved.

For larger teams, combine this recipe with Security-review a pull request with an agent when a dependency bump also requires changing authentication, cryptography or request-parsing code.

Review the full capabilities of Supply chain risk auditor before installing it, pair it with Verification before completion so test evidence is never skipped, and read Reviewing AI-written code for checking agent-generated upgrade diffs.

Outcome and tools

Outcome
A reviewed dependency upgrade branch where high-risk advisories and install-script flags have been triaged, grouped by breaking-change risk and verified by tests.
For
Developers, Team leads
Variants for
Claude Code, Codex, Cursor
Back to top