agentleFS
m2ai-mcp-serversm2ai-mcp-servers/claude-skills/skills/dark-code-audit/SKILL.md

dark-code-audit

Skill0 starsChanged 7 months agoMITView on GitHub

Scan a codebase to map where human comprehension has gone missing -- identifying modules with no decision logs, no behavioral contracts, no authorship trail, and high AI-generation signals. Produces a tiered darkness report (summary heat map + ranked TODO list) scoring each module 0-100. Use when onboarding to a new repo, auditing AI-generated code risk, assessing technical debt from comprehension gaps, or as a periodic health check. Trigger on "dark code", "darkness audit", "comprehension map", "who understands this code", "AI-generated code risk", "code understanding gap".

The file

Show its rules and text

We split this skill into the rules it gives an agent

14 rules. About 0 are common, 12 are distinctive, and 2 are very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈12

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 2

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Distinctive:

    Ask the user for ONE of:

    line 14
  2. Distinctive:

    If no input is provided, scan the current working directory.

    line 19
  3. Very specific:

    Search for ADR files (docs/adr/, docs/decisions/, ADR-*.md)

    line 77
  4. Distinctive:

    Check for test files corresponding to module files

    line 97
  5. Distinctive:

    Read test files: do they test behavior ("when X happens, Y should result") or implementation ("mock A, assert B was called")?

    line 98
  6. Distinctive:

    Check public function/class signatures for type annotations and docstrings

    line 99
  7. Distinctive:

    Look for contract/schema validation (JSON Schema, Pydantic models, Zod schemas)

    line 100
  8. Distinctive:

    Check for CODEOWNERS or equivalent ownership files

    line 119
  9. Distinctive:

    Search architecture docs, README files, and system diagrams for references

    line 120
  10. Very specific:

    If a previous scan report exists in the repo (.dark-code-audit/ directory), compare:

    line 188
  11. Distinctive:

    After producing the report:

    line 201
  12. Distinctive:

    If a prior scan exists, include trend data automatically

    line 205
  13. Distinctive:

    Before producing the final report:

    line 239
  14. Distinctive:

    Every discovered module must have a score (nothing skipped without explanation)

    line 240

≈ “Common” is an estimate: at least 1 in 5 of the 350,495 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

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:

  1. Language detection: Identify primary language(s) from file extensions
  2. 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)
  3. 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.

SignalScore 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 -rn for author diversity
  • git 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.

SignalScore 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.

SignalScore 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.

SignalScore 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

TierScore RangeMeaning
DARK80-100No evidence anyone understood this module. High risk.
DIM50-79Partial understanding. Some signals present, significant gaps.
UNDERSTOOD0-49Clear 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:

  1. Save the raw scores as JSON to .dark-code-audit/latest.json for trend comparison
  2. Offer to save the full report as .dark-code-audit/report-[date].md
  3. 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

SettingDefaultDescription
Darkness threshold80Modules above this score appear in the TODO list
Min module size50 LOCSkip modules smaller than this
Exclude patternsvendor/, node_modules/, *.generated.*, *.lockPaths to exclude
Trend comparisonautoCompare 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.

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.