agentleFS
KubementatKubementat/ai_agent_skills/skills/code-doctor/SKILL.md

code-doctor

Skill2 starsChanged 8 months agoMITView on GitHub

Diagnose structural problems in any codebase — god classes, circular dependencies, complexity violations, SOLID anti-patterns. Produces agent-actionable findings with severity, code context, recommended fixes, and example diffs. Offers to start subagents to fix issues.

1 other project uses a version of this.

Adopted by

Most recently taken up by

The file

We split this skill into the rules it gives an agent

3 rules. About 0 are common, 3 are distinctive, and 0 are very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈3

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 0

    Very specific

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

  • Common
  • Distinctive
  • Very specific
  1. Distinctive:

    If no dependency file is found, check for source file extensions.

    line 41
  2. Distinctive:

    After the report, ask the user if they want to fix issues:

    line 99
  3. Distinctive:

    If the user chooses to fix:

    line 109

≈ “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

/code-doctor — Code Quality Diagnosis

You are a code quality doctor. Your job is to diagnose structural problems in any codebase — god classes, circular dependencies, complexity violations, SOLID anti-patterns, and encapsulation issues. You produce agent-actionable findings that another coding agent can use to improve the codebase.

Trigger

User invokes /code-doctor followed by their input:

/code-doctor Check the codebase
/code-doctor --check lint Check only lint issues
/code-doctor --check complexity Check only complexity
/code-doctor --check design Check only design patterns

Workflow

Step 1: Detect Project (Subagent)

Spawn a subagent to detect the project language by scanning for language indicators:

  • requirements.txt or pyproject.toml → Python
  • package.json → JavaScript/TypeScript
  • go.mod → Go
  • pom.xml or build.gradle → Java

If no dependency file is found, check for source file extensions. If still no detection, ask the user.

Step 2: Install Missing Tools (Subagent)

Spawn a subagent to install missing tools. For each required tool, check if it's installed. If not, add it to the project's dev dependencies with major version pinning (e.g., radon>=5.0,<6.0). Commit the changes.

Step 3: Pass 1 — Scouting (Parallel, Tooling-Heavy)

Spawn four parallel subagents:

  • /lint-scout — Run language-specific linters
  • /complexity-scout — Run complexity tools
  • /structure-scout — Run structural checks (method length, class size, file size)
  • /dependency-scout — Run dependency analysis

Each subagent uses the appropriate tool for the detected language(s). Results are collected and aggregated.

Step 4: Pass 2 — Design Analysis (LLM, Only Flagged Items)

For each item flagged in Pass 1, the LLM analyzes with a tailored prompt:

  • God class → "Analyze for concern mixing, suggest extraction into separate classes"
  • Feature envy → "Analyze for methods that reach into other classes too much, suggest moving methods"
  • SOLID violation → "Analyze for Single Responsibility and Open/Closed violations"
  • Encapsulation issue → "Analyze for fields accessible from too many places" Context for the LLM: flagged item + its imports + classes that import it (1-level deep).

Step 5: Report

Output a structured summary to the console:

🏥 Code Doctor — Diagnosis Report
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

📊 Summary
  Total issues: 23
  🔴 Errors: 5 (must fix)
  🟡 Warnings: 12 (should fix)
  🔵 Info: 6 (nice-to-have)

🏆 Top Issues
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

1. 🔴 God Class — src/services/user_service.py:1
   UserService has 23 methods mixing data access, business logic, and formatting

2. 🔴 Circular Dependency — src/models/user.py ↔ src/models/order.py
   User references Order, Order references User — consider a third model

3. 🔴 Long Method — src/services/user_service.py:150
   process_user_data is 127 lines — extract into smaller methods

...

Full findings: ./findings.json

Step 6: Fix Phase (Optional)

After the report, ask the user if they want to fix issues:

Would you like me to start subagents to fix these issues?
  1. Fix all 🔴 errors (5 issues)
  2. Fix 🔴 errors and 🟡 warnings (17 issues)
  3. Fix everything (23 issues)
  4. Skip — I'll review the findings first

If the user chooses to fix:

  1. Create a new branch — git checkout -b code-doctor-fix-YYYYMMDD so fixes are not done directly on the main or current feature branch
  2. Spawn one fix subagent per finding, running in parallel with file-level locking. Each subagent commits its fix as it completes.
🔧 Starting fixes (5 🔴 errors)...

  1/5 ✓ Extracted UserRepository from UserService — committed
  2/5 ✓ Resolved circular dependency User↔Order — committed
  3/5 ✓ Split UserService into UserService + UserFormatter — committed
  4/5 ✓ Extracted OrderProcessor from OrderService — committed
  5/5 ✓ Extracted PaymentProcessor from PaymentService — committed

━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
All fixes complete. 5 files modified, 5 commits created.
Branch: code-doctor-fix-20260623

Thresholds

MetricPythonJS/TSGoJava
Max method length50406050
Max class length300250200300
Max class methods15121015
Max class dependencies5545
Max inheritance depth3223

Output Format

Console Output

Markdown summary with severity indicators and top issues.

File Output

findings.json — machine-readable, agent-actionable:

{
  "finding_id": "god-class-001",
  "severity": "ERROR",
  "type": "god-class",
  "file": "src/services/user_service.py",
  "line": 1,
  "class_name": "UserService",
  "code_context": "class UserService:\n    def __init__(...):\n        ...",
  "violation_reason": "UserService has 23 methods mixing data access, business logic, and formatting concerns",
  "recommended_fix": "Extract into: (1) UserRepository (data access), (2) UserService (business logic), (3) UserFormatter (formatting)",
  "example_diff": "--- a/src/services/user_service.py\n+++ b/src/services/user_service.py\n@@ -1,50 +1,30 @@\nclass UserRepository:\n    ...",
  "metrics": {
    "method_count": 23,
    "line_count": 450,
    "dependency_count": 12
  }
}

Findings Priority Order

  1. Circular dependencies — structural blockers
  2. God classes — biggest structural issues
  3. Long methods — easier to refactor
  4. Other structural issues — feature envy, deep inheritance, etc.
  5. Lint issues — cosmetic

Severity Levels

  • ERROR — Must fix (structural violations, circular dependencies, god classes)
  • WARNING — Should fix (potential issues, complexity violations)
  • INFO — Nice-to-have (minor issues, lint warnings)

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.