11. Dependencies
codeknife deps reads the manifests and lockfiles in your repository and compares the declared dependencies with the external imports in your source code. It reports dependencies nothing imports, imports nothing declares, single-use JavaScript packages, packages locked at more than one major version, and npm packages with install scripts. With --verify-registry it also asks crates.io, npm, PyPI and the Go module proxy whether each declared package exists and looks established.
Quick example
Section titled “Quick example”This demo repository has a Rust crate at the root, a JavaScript package in web/, a Python app in py/ and a Go module in goapp/.
# Cargo.toml (dependency sections)[dependencies]serde = "1"anyhow = "1"regex.workspace = truelocal-helper = { path = "../local-helper" }
[dev-dependencies]tempfile = "3"
[target.'cfg(unix)'.dependencies]nix = "0.29"{ "name": "web", "dependencies": { "left-pad": "^1.3.0", "lodash": "^4.17.21", "unused-widget": "^2.0.0" }, "devDependencies": { "vitest": "^1.0.0", "@types/node": "^20.0.0" }}# runtimerequests>=2.31PyYAML==6.0.1flask[async]>=3-r other.txtsrc/main.rs imports serde and phantom_crate and uses regex::Regex. web/src/a.ts imports left-pad, lodash, node:fs, path and ghost-lib; web/src/b.ts imports lodash again. py/app.py imports os, yaml, requests and numpy. goapp/main.go imports fmt, its own example.com/goapp/internal/util and github.com/google/uuid. Cargo.lock locks syn 1.x and 2.x, and web/package-lock.json locks chalk 4.x and 5.x and marks esbuild with hasInstallScript: true.
codeknife deps --no-cache --format humanwarning[CK_DEP_UNUSED]: declared dependency `anyhow` has no observed imports in source files --> Cargo.toml:8 (anyhow) = fix: Remove unused dependencies from the manifest to reduce build time and supply-chain surface.
warning[CK_DEP_UNUSED]: declared dependency `flask` has no observed imports in source files --> py/requirements.txt:4 (flask) = fix: Remove unused dependencies from the manifest to reduce build time and supply-chain surface.
info[CK_DEP_TRIVIAL_USE]: dependency `left-pad` is imported at a single call site --> web/package.json:4 (left-pad) = fix: Evaluate inlining a tiny helper rather than carrying a third-party dependency.
warning[CK_DEP_UNUSED]: declared dependency `unused-widget` has no observed imports in source files --> web/package.json:6 (unused-widget) = fix: Remove unused dependencies from the manifest to reduce build time and supply-chain surface.
warning[CK_DEP_PHANTOM]: imported external package `phantom_crate` is missing from project manifests --> src/main.rs:1 (phantom_crate) = fix: Add the dependency to your manifest or verify this isn't an AI-hallucinated import.
warning[CK_DEP_PHANTOM]: imported external package `ghost_lib` is missing from project manifests --> web/src/a.ts:1 (ghost_lib) = fix: Add the dependency to your manifest or verify this isn't an AI-hallucinated import.
warning[CK_DEP_PHANTOM]: imported external package `numpy` is missing from project manifests --> py/app.py:1 (numpy) = fix: Add the dependency to your manifest or verify this isn't an AI-hallucinated import.
warning[CK_DEP_PHANTOM]: imported external package `github.com/google/uuid` is missing from project manifests --> goapp/main.go:1 (github.com/google/uuid) = fix: Add the dependency to your manifest or verify this isn't an AI-hallucinated import.
info[CK_DEP_DUPLICATE_VERSION]: package `syn` appears with 2 major versions in lockfile (1, 2) --> Cargo.lock:1 (syn) = fix: Deduplicate dependency major versions where feasible to trim binary size and install footprint.
info[CK_DEP_DUPLICATE_VERSION]: package `chalk` appears with 2 major versions in lockfile (4, 5) --> web/package-lock.json:1 (chalk) = fix: Deduplicate dependency major versions where feasible to trim binary size and install footprint.
warning[CK_DEP_SLOPSQUAT_RISK]: npm package `esbuild` runs an install lifecycle script (`hasInstallScript: true`) --> web/package-lock.json:1 (esbuild) = fix: Audit install scripts for unexpected network/filesystem access.
codeknife deps: FAIL (5 files, 0 errors, 8 warnings, 3 info, 3ms)Things to notice in this run:
PyYAMLcounts as used becauseyamlis a known alias for it.tempfile,nix,vitestand@types/nodeare never reported: dev dependencies are never flagged as unused,target.*tables count as dev, and@types/*packages are not recorded at all.local-helperis skipped because it haspath =.regex.workspace = trueis not recorded (see the dotted-key caution below).regexis only used asregex::Regex, never imported withuse, so nothing is reported for it.lodashis imported twice, so it is not a single-use dependency.- The Go module’s own path and the standard library import
fmtare not phantom imports. github.com/pkg/errorswould never be reported as unused: Go dependencies are excluded from that rule.
Without --verify-registry, codeknife deps makes no network requests. The only network code in the blade is the registry checker, and it is called only when --verify-registry is set.
| Rule ID | Severity | Impact | Trigger | Fixer |
|---|---|---|---|---|
CK_DEP_UNUSED |
warning | 45 | A runtime dependency (not Go) that no source file imports | Yes, with codeknife fix --aggressive, for Cargo.toml [dependencies] and package.json only |
CK_DEP_PHANTOM |
warning | 70 | An external import that no manifest declares and that is not a built-in or local package | No |
CK_DEP_TRIVIAL_USE |
info | 25 | A runtime JS/TS dependency imported exactly once, in one file | No |
CK_DEP_DUPLICATE_VERSION |
info | 20 | One lockfile holds more than one major version of a package | No |
CK_DEP_SLOPSQUAT_RISK |
warning | 55 | package-lock.json entry with hasInstallScript: true (no network) |
No |
CK_DEP_SLOPSQUAT_RISK |
error | 90 | --verify-registry returned a risk verdict |
No |
No rule here has a threshold or codeknife.toml key. --strict changes none of them. The full catalogue is on Rule Catalogue. Fixers are described on Autofix Engine.
Manifests and lockfiles
Section titled “Manifests and lockfiles”CodeKnife walks the whole repository and handles every file with one of the exact names below, at any depth. The walk skips hidden files and folders, respects .gitignore, and skips folders named target, node_modules, .git, vendor, dist, build, .venv and .codeknife. It does not read exclude from codeknife.toml.
All manifests are merged into one inventory per ecosystem. A dependency declared in any package.json counts as declared for a JavaScript import anywhere in the repository. Imports are not matched to their nearest manifest.
Manifests (declared dependencies)
Section titled “Manifests (declared dependencies)”| File | Parsed how | Runtime | Dev |
|---|---|---|---|
Cargo.toml |
Line by line, not a TOML parser | [dependencies], [workspace.dependencies], [dependencies.NAME], [workspace.dependencies.NAME] |
[dev-dependencies], [build-dependencies], their .NAME table forms, and every [target.*.dependencies], [target.*.dev-dependencies] and [target.*.build-dependencies] table |
package.json |
JSON | dependencies |
devDependencies, peerDependencies, optionalDependencies |
pyproject.toml |
TOML | [project] dependencies, [tool.poetry.dependencies] (except python) |
every group in [project.optional-dependencies], every group in [dependency-groups], [tool.poetry.dev-dependencies], [tool.poetry.group.*.dependencies] |
requirements.txt |
Line by line | every entry | none |
go.mod |
Line by line | require x v lines and require ( ... ) blocks |
none |
Details per file:
Cargo.toml: an entry is skipped when its value containspath =(inline) or its table body has apath =line. In table form, apackage = "..."line replaces the key with the real package name.[package] nameis recorded as a local crate, so imports of it are not phantom. Keys containing a.are skipped (see the caution below).package.json: names starting with@types/are skipped. The top-levelnameis recorded as a local package. The reported line is the first line containing the quoted name.pyproject.toml:[project] nameis recorded as a local package. Each requirement name is the text before the first=,<,>,!,;,[or space. Every finding for apyproject.tomldependency points at line 1.requirements.txt: only files named exactlyrequirements.txt, sorequirements-dev.txtis not read. Blank lines,#comments and lines starting with-(such as-r other.txt) are skipped. The name is extracted the same way as forpyproject.toml.go.mod:modulelines are recorded as local modules. Lines with// indirectare skipped. A module path must contain a.to be recorded.
Lockfiles (duplicates and install scripts)
Section titled “Lockfiles (duplicates and install scripts)”Lockfiles are used only for CK_DEP_DUPLICATE_VERSION and the install-script warning. They are not compared with the manifests, so there is no check for a lockfile that is out of date.
| File | What is read |
|---|---|
Cargo.lock, uv.lock, poetry.lock |
[[package]] blocks with name = and version = lines (same line-based reader for all three) |
package-lock.json |
the packages map. The name is the text after the last node_modules/ in the key. hasInstallScript: true adds an install-script warning. |
pnpm-lock.yaml |
keys indented by exactly two spaces under a top-level packages: line, in the form name@version. A leading / and any (...) peer suffix are removed. The version must start with a digit. |
yarn.lock |
unindented header lines ending in : (comma-separated specs, __metadata skipped), then the next version "x" or version: x line |
bun.lock |
JSON after trailing commas are removed. Each packages value is an array whose first element is name@version. |
The major version is the text before the first . of the version. A package is a duplicate when it has more than one distinct major in the same lockfile. All 0.x versions share major 0, so 0.20 and 0.21 are not duplicates.
CODEKNIFE deps status=pass files=0 errors=0 warnings=0 infos=5 elapsed_ms=2[1] INFO CK_DEP_DUPLICATE_VERSION bun.lock:1-1 sym=react impact=20 | package `react` appears with 2 major versions in lockfile (18, 19) | fix: Deduplicate dependency major versions where feasible to trim binary size and install footprint.[2] INFO CK_DEP_DUPLICATE_VERSION pnpm-lock.yaml:1-1 sym=lodash impact=20 | package `lodash` appears with 2 major versions in lockfile (3, 4) | fix: Deduplicate dependency major versions where feasible to trim binary size and install footprint.[3] INFO CK_DEP_DUPLICATE_VERSION poetry.lock:1-1 sym=urllib3 impact=20 | package `urllib3` appears with 2 major versions in lockfile (1, 2) | fix: Deduplicate dependency major versions where feasible to trim binary size and install footprint.[4] INFO CK_DEP_DUPLICATE_VERSION uv.lock:1-1 sym=urllib3 impact=20 | package `urllib3` appears with 2 major versions in lockfile (1, 2) | fix: Deduplicate dependency major versions where feasible to trim binary size and install footprint.[5] INFO CK_DEP_DUPLICATE_VERSION yarn.lock:1-1 sym=chalk impact=20 | package `chalk` appears with 2 major versions in lockfile (4, 5) | fix: Deduplicate dependency major versions where feasible to trim binary size and install footprint.This repository held only lockfiles, so every finding was info and the run passed with exit code 0.
How imports are matched
Section titled “How imports are matched”Imports come from the code model: each source file’s external imports, as decided by the language extractor. See Import Resolution for what counts as external. Imports from test files count too.
Both import names and declared names are lower-cased and - is replaced with _ before comparing. Comparisons happen inside one ecosystem group: Rust, JavaScript and TypeScript together, Python, and Go.
| Language | Import name used |
|---|---|
| Rust | text before the first :: |
| TypeScript, JavaScript | @scope/name for scoped packages, otherwise the first path segment |
| Python | the first dotted segment |
| Go | the full import path |
Extra matching rules:
- Rust qualified paths. A declared Rust dependency also counts as used when
name::appears anywhere in any Rust source file. This is a plain substring search over all Rust files joined together. - Python aliases. These distribution names also match the listed import names:
pyyamltoyaml,pillowtopil,beautifulsoup4tobs4,scikit_learntosklearn,python_dotenvtodotenv,python_dateutiltodateutil,psycopg2_binarytopsycopg2,pyjwttojwt,opencv_pythonandopencv_python_headlesstocv2,pycryptodomeandpycryptodomextocrypto,typing_extensionstotyping_extensions.
When each rule fires
Section titled “When each rule fires”CK_DEP_UNUSED: the dependency is runtime (not dev), it is not a Go module, and no source file imports it (including through an alias or a Rust qualified path). When the same name is declared in several manifests of one ecosystem, only the first one in path order is checked and reported.
CK_DEP_TRIVIAL_USE: the dependency is runtime, JavaScript or TypeScript, imported by exactly one file, and that file imports it exactly once.
CK_DEP_PHANTOM: the repository declares at least one dependency in any manifest (otherwise this rule is off), and an external import matches no declared name and none of these:
| Group | Also accepted |
|---|---|
| Rust | local crate names from [package] name, and std, core, alloc, proc_macro, test |
| JavaScript, TypeScript | names starting with node:, bun:, deno:, cloudflare:, jsr:, npm: or virtual:; a fixed list of 40 Node built-in module names (such as fs, path, crypto, child_process); local package names from package.json name |
| Python | a fixed list of 172 standard library module names; local package names from pyproject.toml [project] name |
| Go | any path without a . (treated as standard library); paths equal to or under any module path from a go.mod; paths equal to or under any declared require path |
One finding is raised per missing package. It points at line 1 of the first importing file in path order, with the normalised package name as the symbol.
CK_DEP_DUPLICATE_VERSION: see Lockfiles. One finding per package per lockfile, at line 1.
CK_DEP_SLOPSQUAT_RISK (install script): one warning per package-lock.json entry with hasInstallScript: true, at line 1 of the lockfile.
Registry verification
Section titled “Registry verification”codeknife deps --no-cache --verify-registry --format human--verify-registry checks every declared dependency once per ecosystem and name, including dev dependencies and Go modules. Imports that no manifest declares are not checked. Requests run one after another.
Requests
Section titled “Requests”Each check is one HTTP GET with the header User-Agent: codeknife-deps/0.1 (slopsquat-verifier) and a 3 second overall timeout. The name is inserted as declared, without escaping.
| Ecosystem | URL |
|---|---|
| Rust | https://crates.io/api/v1/crates/NAME |
| JavaScript, TypeScript | https://registry.npmjs.org/NAME |
| Python | https://pypi.org/pypi/NAME/json |
| Go | https://proxy.golang.org/MODULE/@v/list |
These URLs are fixed. There is no flag or config key to point them at a mirror.
Verdicts
Section titled “Verdicts”| Response | Result |
|---|---|
| HTTP 404 | Risk: package does not exist |
| Any other error status, timeout or connection failure | Skipped, with a note |
| Body cannot be read | Skipped, with a note |
| Go: empty body | Risk: empty version list |
| Go: non-empty body | Healthy |
| Rust, npm, Python: body is not JSON | Skipped, with a note |
Rust: crate.created_at is less than 14 days ago |
Risk |
Rust: crate.downloads is below 50 |
Risk |
npm: time.created is less than 14 days ago |
Risk |
Python: releases is an empty object |
Risk |
| Otherwise | Healthy |
Each risk becomes a CK_DEP_SLOPSQUAT_RISK error at the manifest line of the dependency. There is no check for name similarity to popular packages, and no download check for npm or PyPI.
This demo declares real and made-up packages in each ecosystem (serde and codeknife-demo-made-up-crate-zz9 in Cargo.toml, left-pad, @babel/core and codeknife-demo-made-up-npm-zz9 in package.json, requests and codeknife-demo-made-up-pypi-zz9 in py/requirements.txt, github.com/pkg/errors and github.com/BurntSushi/toml in goapp/go.mod). Running the command above printed:
info[CK_DEP_TRIVIAL_USE]: dependency `@babel/core` is imported at a single call site --> package.json:5 (@babel/core) = fix: Evaluate inlining a tiny helper rather than carrying a third-party dependency.
info[CK_DEP_TRIVIAL_USE]: dependency `codeknife-demo-made-up-npm-zz9` is imported at a single call site --> package.json:6 (codeknife-demo-made-up-npm-zz9) = fix: Evaluate inlining a tiny helper rather than carrying a third-party dependency.
error[CK_DEP_SLOPSQUAT_RISK]: package `codeknife-demo-made-up-crate-zz9` does not exist on registry (404 — possible AI hallucination / slopsquatting target) --> Cargo.toml:7 (codeknife-demo-made-up-crate-zz9) = fix: Verify package name spelling and provenance before installing or merging.
error[CK_DEP_SLOPSQUAT_RISK]: package `github.com/BurntSushi/toml` does not exist on registry (404 — possible AI hallucination / slopsquatting target) --> goapp/go.mod:6 (github.com/BurntSushi/toml) = fix: Verify package name spelling and provenance before installing or merging.
error[CK_DEP_SLOPSQUAT_RISK]: package `codeknife-demo-made-up-npm-zz9` does not exist on registry (404 — possible AI hallucination / slopsquatting target) --> package.json:6 (codeknife-demo-made-up-npm-zz9) = fix: Verify package name spelling and provenance before installing or merging.
error[CK_DEP_SLOPSQUAT_RISK]: package `codeknife-demo-made-up-pypi-zz9` does not exist on registry (404 — possible AI hallucination / slopsquatting target) --> py/requirements.txt:2 (codeknife-demo-made-up-pypi-zz9) = fix: Verify package name spelling and provenance before installing or merging.
codeknife deps: FAIL (4 files, 4 errors, 0 warnings, 2 info, 996ms)serde, left-pad, @babel/core, requests and github.com/pkg/errors passed. The three made-up names were reported.
Offline behaviour
Section titled “Offline behaviour”A failed request never fails the run on its own. It adds a note and the dependency is skipped. In this run every request was refused, so the run passed:
info[CK_DEP_TRIVIAL_USE]: dependency `@babel/core` is imported at a single call site --> package.json:5 (@babel/core) = fix: Evaluate inlining a tiny helper rather than carrying a third-party dependency....note: registry check skipped for `serde`: registry request failed: io: Connection refused (os error 111)note: registry check skipped for `codeknife-demo-made-up-crate-zz9`: registry request failed: io: Connection refused (os error 111)...note: registry check skipped for `codeknife-demo-made-up-pypi-zz9`: registry request failed: io: Connection refused (os error 111)codeknife deps: PASS (4 files, 0 errors, 0 warnings, 2 info, 3ms)In --format json these appear in the notes array. In --format agent each one is a NOTE line.
codeknife check and the MCP codeknife_check tool never verify registries. Only codeknife deps --verify-registry does.
Flags and configuration
Section titled “Flags and configuration”| Flag | Effect on deps |
|---|---|
--verify-registry |
Query crates.io, npm, PyPI and the Go proxy for every declared dependency. Off by default. |
--path <PATH> |
Repository root. Default .. |
--format <FORMAT> |
auto, human, agent, json, sarif or markdown. See Output Formats & Exit Codes. |
--changed |
Unused, single-use and registry checks only cover manifests in the changed set. Phantom checks only cover imports from changed files. Duplicate checks only cover changed lockfiles. Install-script warnings are not filtered. See Paths, Excludes & Changed Scope. |
--since <REF> |
Base ref for --changed. |
--no-cache |
Do not write .codeknife/. |
--max-items <N> |
Limit items in --format agent output. |
--strict |
No effect on this blade. |
codeknife.toml key |
Effect |
|---|---|
[blades] deps |
Default true. When false, codeknife check (and anything that runs the static suite) skips this blade. codeknife deps still runs. |
exclude |
Removes source files, and so their imports, from the model. Manifests and lockfiles under excluded paths are still read. |
With --changed and no changed files, the demo still failed because of the unfiltered install-script warning:
CODEKNIFE deps status=fail files=5 errors=0 warnings=1 infos=0 elapsed_ms=4[1] WARNING CK_DEP_SLOPSQUAT_RISK web/package-lock.json:1-1 sym=esbuild impact=55 | npm package `esbuild` runs an install lifecycle script (`hasInstallScript: true`) | fix: Audit install scripts for unexpected network/filesystem access.Findings that match codeknife.baseline are suppressed. See Ratchet Baseline.
Removing unused dependencies
Section titled “Removing unused dependencies”codeknife fix --aggressive plans a patch for each CK_DEP_UNUSED finding it can remove safely:
Cargo.toml: only when the nearest section header above the line is exactly[dependencies], the line’s key equals the package name, and its{and}are balanced on that line.package.json: only when the reported line starts with the quoted package name. A dangling comma on the previous line is removed too.
Other manifests (pyproject.toml, requirements.txt, go.mod) get no patch. Without --aggressive, no dependency patches are planned.
codeknife fix --aggressive --no-cache --format humancodeknife fix (dry-run): planned 2 patch(es) across 2 file(s), 0 reverted (1 pass(es)) [FIX] CK_DEP_UNUSED | Remove unused dependency `anyhow` from Cargo.toml [FIX] CK_DEP_UNUSED | Remove unused dependency `unused-widget` from web/package.jsonflask in requirements.txt was not patched. See Autofix Engine for --write and verification.
Exit codes
Section titled “Exit codes”| Code | When |
|---|---|
0 |
No error or warning findings. Info findings and skipped registry checks do not fail the run. |
1 |
At least one error or warning finding remains after baseline filtering. |
Also available via
Section titled “Also available via”codeknife checkruns this blade (without registry checks) when[blades] depsistrue. See The Check Gate.- The MCP tool
codeknife_checkruns the same static suite. The MCP toolcodeknife_fixwithaggressiveset plans the same unused-dependency removals. See MCP Tools.