[TERMINAL · SKILLS]
> mounting /skills...
> indexing skill manifests...
> linking agents: claude · codex · gemini · cursor
> ready.
[░░░░░░░░░░░░░░░░░░░░░░░░░░░░] 0%
Use Cases/Set Up Automated Dependency Vulnerability Remediation with AI

Set Up Automated Dependency Vulnerability Remediation with AI

Automatically detect, prioritize, and fix dependency vulnerabilities with AI-generated patches and upgrade paths.

Development#coding-agent#automation#sub-agent#background-process#orchestration
Works with:claude-codeopenai-codexgemini-clicursor

Skills stack · 3 skills

Avg quality 91/100·All SAFE
$

The Problem

Priya's 20-person SaaS startup has 340 npm dependencies across three services (./api, ./web, ./worker). Dependabot opens PRs dutifully, but nobody has time to review them. Right now 47 security PRs sit open, some for months. The team cannot tell which vulnerabilities matter in their code and which are buried in transitive dependencies they never call.

A recent penetration test made it worse: two high-severity findings had open Dependabot PRs unreviewed for 11 weeks. The last time someone merged a major dependency update it broke the build and took half a day to untangle, so now everyone is afraid to touch security PRs.

The Solution

Use the security-audit skill to list and rank findings, the coding-agent skill to hand each risky upgrade to a background agent on its own branch, and the github skill (the gh CLI) to work the PR and alert backlog and to automate the routine part. Three rules keep it honest: every finding is ranked by severity and by whether your code uses the package at all, only low-risk bumps merge automatically, and a human reads the advisory before anything is dismissed.

Step-by-Step Walkthrough

Step 1: Triage by Severity and Use

npm audit knows severity and whether a fix exists and is a semver-major change; it does not know whether you call the vulnerable code. Add the second half yourself with a short script that checks whether your source imports each flagged package:

python
import json, re, subprocess
from pathlib import Path

audit = json.loads(subprocess.run(["npm", "audit", "--omit=dev", "--json"],
                                  capture_output=True, text=True).stdout)  # exit code 1 is normal
src = [p for p in Path("src").rglob("*") if p.suffix in {".js", ".mjs", ".ts", ".tsx"}]

def imported_in(pkg):
    pat = re.compile(rf"""(from\s+|require\()\s*['"]{re.escape(pkg)}(/[^'"]*)?['"]""")
    return [str(p) for p in src if pat.search(p.read_text(errors="ignore"))]

rank = {"critical": 0, "high": 1, "moderate": 2, "low": 3}
rows = []
for name, v in audit["vulnerabilities"].items():
    fix = v["fixAvailable"]
    major = fix["isSemVerMajor"] if isinstance(fix, dict) else None
    rows.append((rank[v["severity"]], name, v["severity"], v["isDirect"], imported_in(name), major))
for _, name, sev, direct, files, major in sorted(rows):
    print(f"{sev:9} {name:22} direct={direct!s:5} imported_in={files or '-'} fix_is_major={major}")

Run it in each service directory. On a test project pinned to express@4.18.2, ws@8.13.0, tar@6.1.15 and pdfjs-dist@3.4.120, today's registry advisories give:

console
critical  tar                    direct=True  imported_in=- fix_is_major=True
high      express                direct=True  imported_in=['src/app.js'] fix_is_major=None
high      pdfjs-dist             direct=True  imported_in=- fix_is_major=True
high      ws                     direct=True  imported_in=['src/realtime.mjs'] fix_is_major=None
moderate  qs                     direct=False imported_in=- fix_is_major=None

Reading the output:

  • Direct, imported, non-major fix (express, ws): fix this week. npm audit fix applies it; the PR runs your tests.
  • Direct but imported nowhere (tar, pdfjs-dist above): the dependency is declared but unused. Remove it with npm uninstall <name> instead of upgrading it; that clears the finding with no migration.
  • Direct, imported, major fix: a migration. Give it to a coding agent on its own branch (Step 3).
  • Transitive only (qs): npm audit fix usually bumps it through its parent; if it cannot, npm ls qs --all shows the chain and an overrides entry in package.json is the stopgap.

An import match means "your code uses this package", not "your code reaches the vulnerable function". For anything critical or high, have the agent open the advisory (https://github.com/advisories/<GHSA-id>), name the vulnerable function or condition, and show the call site or the reason it cannot be hit. Static import checks do not cover dynamic require, plugins loaded by name or build tooling, so treat "not imported" as a lead to confirm, not proof.

Step 2: Fix the Routine Findings

Check what Dependabot has open, oldest first:

bash
gh pr list --author "app/dependabot" --state open --json number,title,createdAt \
  --jq 'sort_by(.createdAt) | .[] | "\(.number)\t\(.createdAt[:10])\t\(.title)"'

Merge the patch and minor security PRs whose CI is green and close the rest as superseded. Advisory details matter for what you promise: for example ws 8.13.0 is affected by CVE-2024-37890 (a DoS from requests with many HTTP headers, fixed in 8.17.1), and a newer advisory (CVE-2026-48779, memory exhaustion from tiny fragments) puts the fixed version at 8.21.0, so the target version is whatever npm audit reports as fixed today, not the version in an old advisory. Likewise CVE-2024-29041 is an Express open redirect (fixed in 4.19.2), not path traversal, and CVE-2024-28863 is a DoS in tar from unbounded folder counts; the severity labels in your own tracker may differ from the vendors', so read the advisory text.

Step 3: Delegate Major Upgrades to a Coding Agent

For each major-version fix, start a coding agent on its own branch with a narrow brief:

In ./worker, upgrade pdfjs-dist to the version `npm audit` reports as fixed.
First read the release notes between the current and target versions and list
breaking changes that affect our imports. Make the minimal code changes, add
tests for the call sites we use, run `npm test`, and leave the result on branch
fix/pdfjs-dist. Do not touch other dependencies.

The coding-agent skill covers launching Claude Code or Codex CLI as a background process and checking on it. A reviewer still reads the diff and the agent's list of breaking changes before merge. If the advisory offers a mitigation that needs no upgrade (for pdfjs-dist, the advisory recommends setting isEvalSupported: false in getDocument as a workaround), that can buy time but is not a substitute for the fix.

Step 4: Record Decisions on Findings You Will Not Fix Now

When the advisory describes a path your code cannot reach, dismiss the alert with a reason and a dated note so the decision is auditable. The Dependabot REST API accepts dismissed_reason of fix_started, inaccurate, no_bandwidth, not_used or tolerable_risk, and a comment up to 280 characters:

bash
gh api -X PATCH repos/OWNER/REPO/dependabot/alerts/ALERT_NUMBER \
  -f state=dismissed -f dismissed_reason=not_used \
  -f dismissed_comment="Advisory affects xml parsing; we only parse JSON. Revisit 2027-01-29."

List open alerts first with gh api "repos/OWNER/REPO/dependabot/alerts?state=open&per_page=100" --paginate. Dismissal needs a human sign-off; the agent drafts the comment, the reviewer runs the command.

Step 5: Keep the Backlog from Returning

Group Dependabot's version updates so one weekly PR replaces many, and cover all three services. Security updates can be grouped too with applies-to: security-updates:

yaml
version: 2
updates:
  - package-ecosystem: npm
    directories: ["/api", "/web", "/worker"]
    schedule:
      interval: weekly
      day: monday
    groups:
      minor-and-patch:
        update-types: [minor, patch]
      security:
        applies-to: security-updates
        patterns: ["*"]

Then auto-merge only patch updates once required status checks pass. This follows the fetch-metadata README's pattern. It uses pull_request_target because Dependabot-triggered pull_request runs get a read-only token; the job never checks out the PR's code, which is what keeps that safe. Branch protection must require your CI checks, otherwise auto-merge has nothing to wait for:

yaml
name: Dependabot auto-merge
on: pull_request_target
permissions:
  contents: write
  pull-requests: write
jobs:
  dependabot:
    runs-on: ubuntu-latest
    if: github.event.pull_request.user.login == 'dependabot[bot]'
    steps:
      - id: metadata
        uses: dependabot/fetch-metadata@25dd0e34f4fe68f24cc83900b1fe3fe149efef98 # v3.1.0
        with:
          github-token: "${{ secrets.GITHUB_TOKEN }}"
      - if: steps.metadata.outputs.update-type == 'version-update:semver-patch'
        run: gh pr merge --auto --merge "$PR_URL"
        env:
          PR_URL: ${{ github.event.pull_request.html_url }}
          GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}

Minor and major updates, and anything the weekly npm audit script flags as imported-and-high, stay as PRs for a person. These configurations come from the GitHub docs and were not run against a live repository.

Real-World Example

Priya runs the triage script in the three services on a Tuesday. Of the 47 open PRs, 9 are patch bumps with green CI, which she merges. Four direct dependencies are declared but never imported; removing them closes 11 alerts and 6 of the PRs. Two findings are in packages the API uses on a hot path; one is a patch, and the other is a major upgrade that goes to a coding agent on its own branch. The agent lists the breaking changes, adjusts three call sites and adds tests, and Priya reviews that diff in an afternoon instead of avoiding it.

The remaining alerts are triaged against their advisories: those with an unreachable code path are dismissed with not_used and a revisit date, the rest get tickets. With weekly grouped PRs and patch auto-merge in place, the penetration testers' re-check two weeks later finds both earlier high-severity items closed, and the team tracks time-to-fix for security PRs in the same dashboard as its other engineering metrics.

Related Skills

  • coding-agent - run each major-version migration on its own branch in a background agent
  • security-audit - dependency scanning with npm audit, osv-scanner and Trivy
  • github - gh for PR lists, alert dismissal and auto-merge

Related use cases