Dark Code Audit
Scan a repository and produce a tiered report of where human comprehension has gone missing. "Dark code" is code that works correctly but that no human understood at any point in its lifecycle -- it was generated, merged, and deployed without anyone building a mental model of what it does or why.
Dark code is not bad code. It passes linters, tests, and style checks. The danger is that when it breaks, nobody knows how to fix it because nobody ever understood it.
Phase 1: Intake
Ask the user for ONE of:
- A repository path to scan (local)
- A GitHub repo URL (will clone or use gh CLI)
- A specific subdirectory to scope the audit
If no input is provided, scan the current working directory.
Scoping options (ask if repo is large):
- Full repo scan (default)
- Specific directories only
- Files changed in the last N days
- Files with fewer than N commits
Phase 2: Module Discovery
Identify the natural module boundaries in the codebase:
- Language detection: Identify primary language(s) from file extensions
- Module mapping: Group files into logical modules based on:
- Directory structure (each top-level src directory = module)
- Package/module declarations (Python packages, Go packages, JS modules)
- Service boundaries (Dockerfiles, serverless configs, API route groups)
- Size filtering: Skip vendored code, node_modules, generated files, lock files, and build artifacts
Output a module inventory before proceeding to scoring.
Phase 3: Darkness Scoring
Score each module on four dimensions (25% weight each). Each dimension scores 0-100 where 100 = maximum darkness (worst).
Dimension 1: Authorship Signal (25%)
Measures whether the code has traceable human authorship or appears to be AI-generated without human review.
| Signal | Score Impact |
|---|---|
| Single author for entire module | +20 (could be human or AI, but bus factor = 1) |
| Commits with generic messages ("fix", "update", "refactor") | +15 per pattern |
| AI-generation markers (copilot tags, "generated by", boilerplate comments) | +25 |
| No code review artifacts (no PR references in commit messages) | +20 |
| High code churn with no corresponding discussion | +20 |
| Multiple reviewers, descriptive commits | -30 (strong human signal) |
How to measure:
git log --format='%an' -- <module_path> | sort | uniq -c | sort -rnfor author diversitygit log --oneline -- <module_path>and classify commit message quality- Grep for AI-generation markers in source files and commit messages
Dimension 2: Decision Trail (25%)
Measures whether the why behind architectural choices is documented anywhere.
| Signal | Score Impact |
|---|---|
| No ADRs (Architecture Decision Records) referencing this module | +25 |
| No CLAUDE.md / README mentioning this module's design rationale | +20 |
| Commit messages are "what" only, no "why" | +20 |
| No inline comments explaining non-obvious choices | +15 |
| Git blame shows rationale in commit messages | -20 |
| ADR or design doc references this module explicitly | -30 |
| CLAUDE.md has rules/patterns specific to this module | -25 |
How to measure:
- Search for ADR files (
docs/adr/,docs/decisions/,ADR-*.md) - Grep CLAUDE.md files for references to the module name or key functions
git log --format='%s%n%b' -- <module_path>and classify messages as "what" vs "why"- Sample 5-10 non-trivial functions and check for explanatory comments
Dimension 3: Behavioral Contracts (25%)
Measures whether the module's expected behavior is specified anywhere outside the implementation itself.
| Signal | Score Impact |
|---|---|
| No tests for this module | +30 |
| Tests exist but only assert implementation details (mock-heavy, brittle) | +20 |
| No docstrings or type annotations on public interfaces | +15 |
| No error handling documentation (what errors can this throw and when?) | +15 |
| Behavioral tests that describe what the module does in plain language | -25 |
| Type annotations + docstrings on all public interfaces | -20 |
| Contract tests (schema validation, API contract tests) | -25 |
How to measure:
- Check for test files corresponding to module files
- Read test files: do they test behavior ("when X happens, Y should result") or implementation ("mock A, assert B was called")?
- Check public function/class signatures for type annotations and docstrings
- Look for contract/schema validation (JSON Schema, Pydantic models, Zod schemas)
Dimension 4: Dependency Awareness (25%)
Measures whether the module's role in the larger system is understood and documented.
| Signal | Score Impact |
|---|---|
| Module not referenced in any architectural documentation | +25 |
| No import graph visibility (nothing documents what depends on this) | +20 |
| Orphan module (imported by nothing, or imports nothing) | +15 if large |
| Module is a dependency bottleneck (many importers) but undocumented | +25 |
| Referenced in architecture docs or system diagrams | -25 |
| Import/dependency relationships are documented or self-evident | -20 |
| Module has a clear owner (CODEOWNERS file, team assignment) | -15 |
How to measure:
- Grep the codebase for imports of this module
- Count dependents (modules that import from this one)
- Check for CODEOWNERS or equivalent ownership files
- Search architecture docs, README files, and system diagrams for references
Score Calculation
module_darkness = (authorship_score * 0.25) + (decision_trail_score * 0.25) +
(behavioral_contracts_score * 0.25) + (dependency_awareness_score * 0.25)
Clamp each dimension to 0-100 before averaging. Final score is 0-100.
Darkness Tiers
| Tier | Score Range | Meaning |
|---|---|---|
| DARK | 80-100 | No evidence anyone understood this module. High risk. |
| DIM | 50-79 | Partial understanding. Some signals present, significant gaps. |
| UNDERSTOOD | 0-49 | Clear evidence of human comprehension. Managed risk. |
Phase 4: Output
Produce a tiered report with two sections:
Section 1: Summary Heat Map
## Dark Code Heat Map: [Repo Name]
Scanned [N] modules, [M] files, [L] lines of code
Scan date: [date]
### Overall Darkness Distribution
- DARK (80-100): [N] modules ([X]% of codebase by LOC)
- DIM (50-79): [N] modules ([X]% of codebase by LOC)
- UNDERSTOOD (0-49): [N] modules ([X]% of codebase by LOC)
### Aggregate Score: [weighted average by LOC] / 100
### Module Scores
| Module | Darkness | Authorship | Decision Trail | Contracts | Dependencies | LOC |
|--------|----------|------------|----------------|-----------|--------------|-----|
| [path] | [score] | [score] | [score] | [score] | [score] | [N] |
| ... | ... | ... | ... | ... | ... | ... |
(Sorted by darkness score descending)
Section 2: Drill-Down TODO List
For each module scoring above the darkness threshold (default: 80):
### [Module Path] -- Darkness Score: [N]/100
**Why it's dark:**
- [Specific gaps from each dimension that contributed to the high score]
**Highest-impact actions to reduce darkness:**
1. [Most impactful action] -- reduces score by ~[N] points
- Example: "Add behavioral tests for the 3 public functions in this module"
2. [Second action] -- reduces score by ~[N] points
3. [Third action] -- reduces score by ~[N] points
**Estimated effort:** [Quick fix / Half-day / Multi-day]
Section 3: Trend Data (if prior scan exists)
If a previous scan report exists in the repo (.dark-code-audit/ directory), compare:
### Trend Since Last Scan ([date])
- Modules that got DARKER: [list with delta]
- Modules that got LIGHTER: [list with delta]
- New modules (unscored): [list]
- Removed modules: [list]
- Overall darkness delta: [+/- N points]
Phase 5: Persistence
After producing the report:
- Save the raw scores as JSON to
.dark-code-audit/latest.jsonfor trend comparison - Offer to save the full report as
.dark-code-audit/report-[date].md - If a prior scan exists, include trend data automatically
JSON schema for latest.json:
{
"scan_date": "2026-04-13",
"repo": "repo-name",
"modules": [
{
"path": "src/module",
"darkness_score": 85,
"authorship": 90,
"decision_trail": 80,
"behavioral_contracts": 85,
"dependency_awareness": 85,
"loc": 1200
}
],
"aggregate_score": 72,
"threshold": 80
}
Configuration
| Setting | Default | Description |
|---|---|---|
| Darkness threshold | 80 | Modules above this score appear in the TODO list |
| Min module size | 50 LOC | Skip modules smaller than this |
| Exclude patterns | vendor/, node_modules/, *.generated.*, *.lock |
Paths to exclude |
| Trend comparison | auto | Compare to .dark-code-audit/latest.json if it exists |
Verification
Before producing the final report:
- Every discovered module must have a score (nothing skipped without explanation)
- Scores must be mathematically consistent with dimension inputs
- TODO actions must be specific to the module, not generic advice
- Trend data (if present) must reference the actual prior scan, not estimates
Adoption Path
Source
Inspired by Nate Jones' "Dark Code" framework (2026-04-13): code generated by AI that no human ever understood at any point in its lifecycle. The audit maps where comprehension has gone missing so teams can systematically reattach understanding to their codebase.