Code Health Check
Automated codebase health analysis with scored report and prioritized fixes.
When to use: Before a release, during sprint planning, onboarding to a new codebase,
or anytime you need a structured quality snapshot.
When NOT to use: For runtime debugging (use a debugger). For security-specific audits
(use a dedicated security tool). This is a structural health check, not a pentest.
Activation Protocol
Before running any checks:
- Load check definitions: Read
references/health-checks.md
- Load scoring: Read
references/scoring-methodology.md
- Detect project type: Glob for package.json, pyproject.toml, Cargo.toml, go.mod
- Scope the check:
- If
$ARGUMENTS provided, use as path scope
- If not, use current working directory
- Verify it's a code repo: Check for
.git/ or source files
- If no code found: "This doesn't appear to be a codebase. Point me to a project directory."
Question System
| Input |
Required |
If Missing |
| Target path |
Yes |
Ask: "Which directory should I analyze?" |
| Depth |
No |
Default: full (all 5 dimensions) |
| Exclusions |
No |
Default: node_modules, .git, dist, build, vendor |
Core Instructions
Run 5 health dimensions in sequence. Each produces a 0-100 score.
Dimension 1: Dead Code (weight: 15%)
# Find unused exports
grep -r "export " --include="*.ts" --include="*.js" | # extract export names
# Cross-reference with imports across codebase
# Unused export = dead code candidate
- Glob all source files
- Extract exported symbols (functions, classes, constants)
- Grep for imports/usage of each symbol
- Score: 100 - (dead_exports / total_exports × 100)
Dimension 2: Dependency Health (weight: 20%)
- Read package.json / requirements.txt / Cargo.toml
- Check last publish date of each dependency (if available via Bash)
- Flag: dependencies > 1 year old, deprecated packages, known CVEs
- Score: 100 - (stale_deps / total_deps × 100)
Dimension 3: Test Coverage (weight: 25%)
- Glob test files (.test., .spec., test_*, _test.)
- Glob source files
- Calculate ratio: test_files / source_files
- Check for test configuration (jest.config, pytest.ini, etc.)
- Score: (test_ratio × 50) + (has_config × 25) + (has_ci × 25)
Dimension 4: Security Surface (weight: 20%)
- Grep for hardcoded secrets (API keys, tokens, passwords)
- Check for eval(), exec(), dangerouslySetInnerHTML
- Check .env.example exists (if .env is gitignored)
- Check dependency audit (npm audit / pip-audit)
- Score: 100 - (findings × 10), min 0
Dimension 5: Complexity Hotspots (weight: 20%)
- Find files > 500 lines (candidates for splitting)
- Find functions > 50 lines (candidates for extraction)
- Find deeply nested code (> 4 levels of indentation)
- Score: 100 - (hotspots / total_files × 100)
Quality Gate
Before presenting the report, verify:
Pre-Execution Gate
Before running checks:
Degradation Handling
| Missing Element |
Behavior |
| No tests at all |
Score dimension 3 at 0, note "No test infrastructure detected" |
| No package manager |
Skip dimension 2, note "No dependency manifest found" |
| Binary/generated files |
Exclude from analysis, note count |
| Monorepo |
Ask which package to analyze, or run on root |
| Empty directories |
Skip, don't count as dead code |
Anti-Patterns
- Counting lines as quality — More lines ≠ worse. Measure complexity, not volume.
- Flagging all old dependencies — Stable deps (lodash, express) being "old" is fine.
- Test file ratio as coverage — File existence ≠ meaningful test coverage.
- Generic advice — "You should write more tests" is useless. Specify WHICH files need tests.
- Ignoring context — A prototype has different health standards than production code.
- Running on vendor code — Always exclude node_modules, vendor, generated code.
- One-time snapshot thinking — Health checks should be re-run periodically, not once.
Output Format
CODE HEALTH REPORT — {project_name}
Generated: {date} | Scope: {path} | Files: {N}
OVERALL HEALTH: {score}/100 {grade}
Dead Code {score}/100 ████████░░ {dead_count} unused exports
Dependencies {score}/100 ██████████ {stale_count} stale, {vuln_count} vulnerable
Test Coverage {score}/100 ██████░░░░ {test_ratio}% file coverage
Security Surface {score}/100 █████████░ {finding_count} findings
Complexity {score}/100 ████████░░ {hotspot_count} hotspots
TOP PRIORITIES (fix these first):
1. {file:line} — {issue} — {impact}
2. {file:line} — {issue} — {impact}
3. {file:line} — {issue} — {impact}
DETAILED FINDINGS: {N} total across 5 dimensions
[See below for per-dimension breakdown]
Grade scale: A (90+), B (75-89), C (60-74), D (40-59), F (<40)
1---2name: code-health-check3description: Run a comprehensive codebase health analysis covering dead code, dependency freshness, test coverage gaps, security surface, and complexity hotspots. Produces a scored report with prioritized remediation. Use when the user asks to "check health", "audit the codebase", "code quality", or "technical debt".4---56<!-- WHY: D1 (Activation Protocol) — Load check definitions and scoring before7 running any analysis. Without this, checks are ad-hoc and inconsistent. -->89# Code Health Check1011> Automated codebase health analysis with scored report and prioritized fixes.1213**When to use:** Before a release, during sprint planning, onboarding to a new codebase,14or anytime you need a structured quality snapshot.1516**When NOT to use:** For runtime debugging (use a debugger). For security-specific audits17(use a dedicated security tool). This is a structural health check, not a pentest.1819---2021## Activation Protocol2223Before running any checks:24251. **Load check definitions:** Read `references/health-checks.md`262. **Load scoring:** Read `references/scoring-methodology.md`273. **Detect project type:** Glob for package.json, pyproject.toml, Cargo.toml, go.mod284. **Scope the check:**29 - If `$ARGUMENTS` provided, use as path scope30 - If not, use current working directory315. **Verify it's a code repo:** Check for `.git/` or source files32 - If no code found: "This doesn't appear to be a codebase. Point me to a project directory."3334---3536<!-- WHY: D5 (Question System) — If scope is ambiguous, ask before running37 a potentially expensive analysis on the wrong directory. -->3839## Question System4041| Input | Required | If Missing |42|-------|----------|-----------|43| Target path | Yes | Ask: "Which directory should I analyze?" |44| Depth | No | Default: full (all 5 dimensions) |45| Exclusions | No | Default: node_modules, .git, dist, build, vendor |4647---4849## Core Instructions5051Run 5 health dimensions in sequence. Each produces a 0-100 score.5253### Dimension 1: Dead Code (weight: 15%)5455```bash56# Find unused exports57grep -r "export " --include="*.ts" --include="*.js" | # extract export names58# Cross-reference with imports across codebase59# Unused export = dead code candidate60```6162- Glob all source files63- Extract exported symbols (functions, classes, constants)64- Grep for imports/usage of each symbol65- Score: 100 - (dead_exports / total_exports × 100)6667### Dimension 2: Dependency Health (weight: 20%)6869- Read package.json / requirements.txt / Cargo.toml70- Check last publish date of each dependency (if available via Bash)71- Flag: dependencies > 1 year old, deprecated packages, known CVEs72- Score: 100 - (stale_deps / total_deps × 100)7374### Dimension 3: Test Coverage (weight: 25%)7576- Glob test files (*.test.*, *.spec.*, test_*, *_test.*)77- Glob source files78- Calculate ratio: test_files / source_files79- Check for test configuration (jest.config, pytest.ini, etc.)80- Score: (test_ratio × 50) + (has_config × 25) + (has_ci × 25)8182### Dimension 4: Security Surface (weight: 20%)8384- Grep for hardcoded secrets (API keys, tokens, passwords)85- Check for eval(), exec(), dangerouslySetInnerHTML86- Check .env.example exists (if .env is gitignored)87- Check dependency audit (npm audit / pip-audit)88- Score: 100 - (findings × 10), min 08990### Dimension 5: Complexity Hotspots (weight: 20%)9192- Find files > 500 lines (candidates for splitting)93- Find functions > 50 lines (candidates for extraction)94- Find deeply nested code (> 4 levels of indentation)95- Score: 100 - (hotspots / total_files × 100)9697---9899<!-- WHY: D4 (Quality Gate) — The report must meet these criteria before100 being presented to the user. Prevents low-quality analysis. -->101102## Quality Gate103104Before presenting the report, verify:105- [ ] All 5 dimensions produced a numeric score (0-100)106- [ ] At least 10 files were analyzed (otherwise scope is too narrow)107- [ ] Each finding has a specific file path (not generic advice)108- [ ] Remediation priorities are ordered by impact (not alphabetically)109110---111112<!-- WHY: D7 (Pre-Execution Gate) — Verify preconditions before running113 the potentially expensive analysis. -->114115## Pre-Execution Gate116117Before running checks:118- [ ] Target directory exists and contains source files119- [ ] At least one recognized language detected120- [ ] Not running inside node_modules or .git121- [ ] Sufficient context to complete analysis122123---124125<!-- WHY: D14 (Graceful Degradation) — Handle repos that are missing126 tests, deps, or other expected structures without crashing. -->127128## Degradation Handling129130| Missing Element | Behavior |131|----------------|----------|132| No tests at all | Score dimension 3 at 0, note "No test infrastructure detected" |133| No package manager | Skip dimension 2, note "No dependency manifest found" |134| Binary/generated files | Exclude from analysis, note count |135| Monorepo | Ask which package to analyze, or run on root |136| Empty directories | Skip, don't count as dead code |137138---139140<!-- WHY: D2 (Anti-Pattern Guard) — Common mistakes when doing health checks. -->141142## Anti-Patterns1431441. **Counting lines as quality** — More lines ≠ worse. Measure complexity, not volume.1452. **Flagging all old dependencies** — Stable deps (lodash, express) being "old" is fine.1463. **Test file ratio as coverage** — File existence ≠ meaningful test coverage.1474. **Generic advice** — "You should write more tests" is useless. Specify WHICH files need tests.1485. **Ignoring context** — A prototype has different health standards than production code.1496. **Running on vendor code** — Always exclude node_modules, vendor, generated code.1507. **One-time snapshot thinking** — Health checks should be re-run periodically, not once.151152---153154<!-- WHY: D16 (Composability) — No hardcoded paths. Works in any project. -->155156## Output Format157158```159CODE HEALTH REPORT — {project_name}160Generated: {date} | Scope: {path} | Files: {N}161162OVERALL HEALTH: {score}/100 {grade}163164 Dead Code {score}/100 ████████░░ {dead_count} unused exports165 Dependencies {score}/100 ██████████ {stale_count} stale, {vuln_count} vulnerable166 Test Coverage {score}/100 ██████░░░░ {test_ratio}% file coverage167 Security Surface {score}/100 █████████░ {finding_count} findings168 Complexity {score}/100 ████████░░ {hotspot_count} hotspots169170TOP PRIORITIES (fix these first):171 1. {file:line} — {issue} — {impact}172 2. {file:line} — {issue} — {impact}173 3. {file:line} — {issue} — {impact}174175DETAILED FINDINGS: {N} total across 5 dimensions176 [See below for per-dimension breakdown]177```178179Grade scale: A (90+), B (75-89), C (60-74), D (40-59), F (<40)