/adev:codehealthfrom adev
Scans source code for dead exports, orphan files, unused dependencies, stale code, and duplicate logic. Produces severity-tiered reports from repomap artifacts.
Ships in adev. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
None: SKILL.md is the whole skill.
Scan source code for dead exports, orphan files, unused dependencies, stale code, and duplicate logic. Produces a severity-tiered markdown report from /adev:repomap artifacts.
Announce at start: "I'm using the adev:codehealth skill to scan for code health issues."
| Argument | Required | Description |
|---|---|---|
| (none) | — | Full scan: all passes against all hygiene.source_roots |
--module <slug> | No | Restrict scan to a single manifest module's paths |
--check <name> | No | Comma-separated check filter. Valid: dead-exports, orphan-files, unused-deps, stale-code, duplicate-logic |
Both --module and --check may be combined (intersection: only named checks, only files in the module).
Complete these checks in order. Stop at the first failure.
Read .context-index/manifest.yaml. If missing or unreadable:
INVALID_MANIFEST: Missing or invalid manifest.yaml —
source_rootsis required for codehealth scanning.
Verify hygiene.source_roots exists and is a non-empty list. If absent:
INVALID_MANIFEST: manifest.yaml is missing
hygiene.source_roots— required for codehealth scanning.
Check that both files exist:
.context-index/hygiene/symbol-ranks.json.context-index/hygiene/dependency-graph.jsonIf either is missing:
MISSING_REPOMAP: Repomap artifacts not found. Run
/adev:repomapfirst to generate the symbol index and dependency graph.
Stop without running any passes.
If --module <slug> is provided, resolve against manifest.yaml modules[].slug. If not found:
UNKNOWN_MODULE: Unknown module '
<slug>'. Available modules:<comma-separated list of slugs>.
If --check <name> is provided, validate each name against the allowlist: dead-exports, orphan-files, unused-deps, stale-code, duplicate-logic. If any is unrecognized:
UNKNOWN_CHECK: Unknown pass '
<name>'. Valid passes: dead-exports, orphan-files, unused-deps, stale-code, duplicate-logic.
Resolve the set of files to scan:
hygiene.source_roots from manifest (e.g., ["cli/", "hooks/", "skills/", "templates/"])--module <slug> provided: intersect with the module's paths from manifest.yaml modules[]hygiene.coverage_exclude glob patterns (e.g., ["tests/**", "skills/*/evals/**"])Load Skill Extensions: Load any skill extension instructions before proceeding:
adev skill-ext load --skill codehealth
If the output is not __NONE__, incorporate it as additional standing instructions that apply to this skill's entire execution. Frame it as: "The following skill extension instructions apply to this invocation (source: installed domain extensions and/or project-level overrides)." If the output is __NONE__, continue normally.
Execute passes in this fixed order. If --check is provided, skip passes not in the filter.
Scope types: Passes 1 and 2 are dependency-graph-scoped (analyze only files present in dependency-graph.json nodes). Passes 3 and 4 are file-system-scoped (scan all files within resolved source_roots). Pass 5 requires tree-sitter at runtime.
dead-exports)Goal: Find exported symbols with zero imports across the codebase.
Steps:
Read .context-index/hygiene/dependency-graph.json. Parse nodes[] and edges[].
If the JSON has unexpected format, skip this pass with note:
FORMAT_ERROR: dependency-graph.json format error — pass skipped.
For each node in nodes[] within the resolved file scope:
exports[]:
edges[] for an edge where edge.to matches the node's path AND the symbol appears in edge.symbols[].tags including "public-api-entry", OR if symbol-ranks.json records referenceSources[] containing "package-exports" or "doc-reference" for this symbol, the symbol is NOT dead — skip it. The new referenceSources[] field encodes inbound references that the static .mjs-only edge analysis cannot see (SKILL.md prose mentions; package.json:exports entries).Cross-reference with .context-index/hygiene/symbol-ranks.json to get line number for each dead export.
If symbol-ranks.json has unexpected format, skip line number enrichment with note:
FORMAT_ERROR: symbol-ranks.json format error — line numbers unavailable.
Severity classification:
to target of an edge with type: "re-export" (barrel file re-export — may be consumed externally outside the project).Tolerance contract: Unknown edge.type values introduced by future schema evolutions (e.g., the rev-2 "doc-reference" type) MUST NOT cause this pass to crash; treat unknown types as informational and continue.
Emit findings: { pass: "dead-exports", severity, file_path, line_number, symbol, description }.
orphan-files)Goal: Find source files not imported by any other file.
Steps:
From dependency-graph.json, collect all file paths appearing as edge.to in any edge. These are "imported files." (Note: doc-reference edges introduced in rev-2 of core-parser-pipeline.spec.md also populate edge.to, so a file referenced from a SKILL.md is counted here and will not be flagged as an orphan.)
For each node in nodes[] within the resolved file scope:
path does NOT appear in the "imported files" set, it is an orphan candidate.Exclude entry points from orphan detection:
**/cli.* or **/main.* (CLI entry points)hooks/hooks.jsontags includes "public-api-entry" (rev-2 schema — these files are declared as the package's public API surface via package.json:exports and are consumed by external dependents not visible in the local graph).hygiene.coverage_exclude patternsDo NOT blanket-exclude **/index.*. A file named index.mjs because it is the entry point, having zero inbound edges, is exactly the failure this pass exists to catch — not a reason to exempt it (issue-u1jtc0, motivated by lib/repomap/index.mjs: a 1,973-line subtree with zero real callers that read as alive purely because the old exclusion hid it). An index.* candidate goes through step 4's verification like any other file; it is excluded only if that verification actually finds a consumer.
Verify candidates against real consumers (required for every orphan candidate, index.* files included — this step is what step 3's public-api-entry and hook exclusions used to skip past for index.* files without checking):
hooks/*.sh) for the module's filename or its exported symbol names. Hooks often contain inline Node.js blocks with dynamic import() calls that reference library modules — these are invisible in the static .mjs dependency graph but are real consumers.package.json's scripts section for the file's path.cli/index.mjs's verb dispatch table (and lib/cli/*.mjs) for an import(...) referencing the file's containing module — a lib subtree with a real CLI verb is not orphaned even if the entry point itself has no in-repo importer.**/index.*.Severity classification:
index.* file that fails step 4's verification lands here: it typically imports its own submodules (outgoing edges) while nothing imports it back.Emit findings: { pass: "orphan-files", severity, file_path, description }.
unused-deps)Goal: Compare package.json dependencies against actual imports in source files.
Steps:
Read package.json from the project root. If missing, skip this pass with note:
MISSING_PACKAGE_JSON: package.json not found — unused dependency detection skipped.
Collect all package names from dependencies and devDependencies.
Scan all source files within the resolved source_roots (not just dependency graph nodes) for import patterns:
import ... from '<package>' or import ... from '<package>/...'import('<package>') or import('<package>/...')require('<package>') or require('<package>/...') (included for consumer project compatibility — this project is pure ESM per constitution)For each package not matched by any import pattern:
dependencies (production dependency, definitely unused).devDependencies (may be used by scripts, tooling, or test runners not captured by import analysis).Emit findings: { pass: "unused-deps", severity, file_path: "package.json", symbol: "<package-name>", description }.
stale-code)Goal: Flag files not modified recently relative to their module's activity.
Steps:
Read hygiene.staleness_threshold_days from manifest (default: 30 if absent).
For each source file within the resolved scope, run:
git log -1 --format=%ci -- <file-path>
Extract the last commit date. If git log fails or git is unavailable, skip this pass with note:
GIT_UNAVAILABLE: git not available or git log failed — stale code detection skipped.
Group files by module (from manifest.yaml modules[].paths).
For each module, find the most recent commit date across all its files.
For each file whose last commit date is older than staleness_threshold_days ago:
Severity classification:
high severity (meaning the export list is empty of referenced symbols — see the dead-exports row of the Severity Reference table: "Only export in file"). A medium-severity dead-export finding ("Coexists with other referenced exports in the same file") does NOT qualify — the file has at least one live reference and is not actually unreferenced, no matter how many of its other exports are dead.medium-severity dead export.Emit findings: { pass: "stale-code", severity, file_path, description: "Last modified: <date>. Module last active: <date>." }.
duplicate-logic)Goal: Find structurally similar or identical function bodies across files.
Prerequisite: Check if tree-sitter is available at runtime (use the same detection mechanism as /adev:repomap — check for web-tree-sitter module availability). If tree-sitter is NOT available:
TREESITTER_UNAVAILABLE: Duplicate logic detection skipped — tree-sitter not available. Run
/adev:repomapwith tree-sitter enabled for this pass. (Per ADR-0001, tree-sitter is optional.)
Skip this pass entirely.
Steps (if tree-sitter available):
{ pass: "duplicate-logic", severity, file_path, line_number, symbol, description: "Duplicate of <other-file>:<line> (<symbol>)" }.| Pass | High | Medium | Low |
|---|---|---|---|
| dead-exports | Only export in file | Coexists with referenced exports | Re-export target |
| orphan-files | Fully isolated (no edges) | Has outgoing edges only | — |
| unused-deps | dependencies package | devDependencies package | — |
| stale-code | Stale + unreferenced | — | Stale but referenced |
| duplicate-logic | Exact duplicate | Structural similarity | — |
After all passes complete, generate the report.
.context-index/reports/codehealth-<YYYY-MM-DD>.md
Create the .context-index/reports/ directory if it does not exist. If a report for today's date already exists, overwrite it (idempotent).
If unable to write:
WRITE_ERROR: Unable to write report — check directory permissions.
Persona adaptation: The report written to disk always uses the full format below. The chat summary presented to the user should follow the active persona's output rules.
---
date: <ISO 8601 timestamp>
module_filter: <--module value or "all">
check_filter: <--pass value or "all">
total_findings: <count>
summary:
high: <count>
medium: <count>
low: <count>
---
# Code Health Report
| Pass | High | Medium | Low | Total |
|------|------|--------|-----|-------|
| Dead Export Detection | N | N | N | N |
| Orphan File Detection | N | N | N | N |
| Unused Dependency Detection | N | N | N | N |
| Stale Code Detection | N | N | N | N |
| Duplicate Logic Detection | N | N | N | N |
| **Total** | **N** | **N** | **N** | **N** |
For each pass that ran:
If findings exist:
## Dead Export Detection
| Severity | File | Line | Symbol | Description |
|----------|------|------|--------|-------------|
| high | src/utils/old.mjs | 12 | unusedHelper | Only export in file, zero references |
| medium | src/lib/api.mjs | 45 | legacyFetch | Coexists with 3 referenced exports |
Sort findings by severity (high first), then file path ascending, then line number ascending. Show — for optional fields (Line, Symbol) when absent.
If zero findings:
## Dead Export Detection
No issues found.
If pass was skipped:
## Duplicate Logic Detection
Skipped — tree-sitter not available. Run `/adev:repomap` with tree-sitter enabled.
If any finding is missing required fields (pass, severity, file_path, description), skip it and note in the report:
MALFORMED_FINDING: N finding(s) omitted due to missing data.
If ALL passes produced zero findings:
# Code Health Report
**No code health issues found.**
| Pass | High | Medium | Low | Total |
|------|------|--------|-----|-------|
| Dead Export Detection | 0 | 0 | 0 | 0 |
| ... | ... | ... | ... | ... |
| **Total** | **0** | **0** | **0** | **0** |
After writing the report, print to the conversation:
Code health scan complete.
Findings: N high, N medium, N low (N total)
Top issues:
1. [high] src/utils/old.mjs:12 — unusedHelper: Only export in file, zero references
2. [high] package.json — lodash: Production dependency not imported anywhere
3. [medium] src/lib/api.mjs:45 — legacyFetch: Coexists with 3 referenced exports
Full report: .context-index/reports/codehealth-<date>.md
Show top 3 findings sorted by severity descending, then file path ascending. If zero findings:
Code health scan complete. No issues found.
Full report: .context-index/reports/codehealth-<date>.md
What SKILL.md sets; muted values are Claude Code's defaults
Three short reads, in order
npx claudepluginhub agentic-development/adev-plugin --plugin adev31 skills in this plugin
/assessadev:assessAssess codebase readiness for agentic development. Scans the codebase using static file inspection and outputs maturity scores across 8 structural dimensions (raw mode) or 11 dimensions (adev mode). Use when you want to evaluate how well-suited a codebase is for AI-assisted development, identify improvement areas, or track progress over time./brainstormadev:brainstormExplore a feature idea interactively and produce a Feature Charter. Validates against constitution and existing charters. Use before building any new feature or module, when the user mentions a new capability, or says 'let us build X'./Other plugins' skills for the same job