Skip to content

Mishit18/claude-code-doctor

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

1 Commit
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

🩺 Claude Code Doctor

Diagnose, lint, and auto-fix your Claude Code setup. Now with AI-powered security scanning, dependency intelligence, and context optimization.

The missing health-check tool for Claude Code β€” built with custom ML engines, zero external dependencies.

npm version npm downloads CI License: MIT PRs Welcome

Quick Start Β· ML Engines Β· Commands Β· Checks Β· CI/CD Β· Contributing


Why?

Claude Code is powerful, but misconfigured setups waste context window tokens, break MCP servers, leak secrets, and silently cause suboptimal results. Worse β€” your codebase could contain prompt injection attacks hiding in comments, configs, or encoded strings.

claude-code-doctor fixes all of this. One command gives you a health score, finds issues, scans for threats, and fixes problems. Built with 9 custom ML engines β€” all zero-dependency, from-scratch implementations.

npx claude-code-doctor
  ╔═══════════════════════════════════════════════╗
  β•‘   🩺  Claude Code Doctor                       β•‘
  β•‘   Diagnose Β· Scan Β· Optimize Β· Auto-Fix        β•‘
  β•šβ•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•

  Overall Health Score

  β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–‘β–‘β–‘β–‘ 89%
  Grade: A-

  22 passed Β· 4 warnings Β· 1 errors Β· 2 skipped
  πŸ’‘ 2 issue(s) can be auto-fixed with --fix

  ─────────────────────────────────────────────────

  πŸ–₯️  Environment  100%        βš™οΈ  Configuration  83%
  πŸ“¦  Installation  50%         πŸ“  CLAUDE.md Lint  88%
  πŸ”Œ  MCP Servers  100%         πŸͺ  Hooks  100%
  πŸ”  Permissions  100%         🧠  Context  100%
  πŸ›‘οΈ  Security Audit  100%      🧠  AI Intelligence  92%

🧠 ML-Powered Engines

What makes claude-code-doctor unique: 9 custom ML engines built from scratch with zero external ML dependencies.

πŸ›‘οΈ Prompt Injection Scanner

The first tool in the Claude ecosystem to scan codebases for AI-targeted attacks.

claude-doctor scan-injections
  πŸ›‘οΈ  Claude Code Doctor β€” Prompt Injection Scanner

  βœ… CLEAN β€” No prompt injection threats detected!
  87 files scanned.

Detects:

  • 20+ direct injection patterns ("ignore previous instructions", system prompt overrides)
  • Role-play/jailbreak attacks (DAN, "you are now", identity hijacking)
  • Unicode manipulation (zero-width chars, bidi overrides β€” Trojan Source)
  • Encoded payloads (Base64/hex-encoded hidden instructions)
  • Social engineering (false authorization, urgency-based overrides)
  • CLAUDE.md poisoning (malicious instructions targeting AI agents)
  • Config poisoning (wildcard permissions, suspicious hooks)
  • Comment-based injections (instructions hidden in code comments)

5 severity levels with confidence scoring. Supports TS/JS, Python, Go, Rust, Java, C/C++, Ruby, PHP, markdown, and config files.

πŸ“ CLAUDE.md Auto-Generator

Auto-generate a high-quality CLAUDE.md from codebase analysis:

claude-doctor generate-claudemd
  βœ” Detected: TypeScript, JavaScript
  βœ” Frameworks: Next.js, Tailwind CSS, Prisma
  βœ” Architecture: full-stack
  βœ” 7 sections generated
  βœ” ~420 tokens

  ✨ CLAUDE.md generated!

Analyzes: tech stack (15+ languages, 40+ frameworks), architecture patterns (monorepo, MVC, API, CLI, library), coding conventions (indentation, quotes, naming), build/test/lint commands, and project structure.

πŸ”— Dependency Graph Intelligence

claude-doctor analyze

Builds a full import graph and identifies:

  • Circular dependencies via Tarjan's Strongly Connected Components
  • God files via PageRank-inspired importance scoring
  • Orphan files (dead code wasting AI context)
  • Blast radius prediction (which files break if you edit X)
  • Optimal context loading order via topological sort
  • Module clusters for project organization

πŸ’° Session Cost Predictor

claude-doctor token-cost
  πŸ’° Claude Code Doctor β€” Token Cost Analyzer

  Total Project: 45,203 tokens
  Context Usage: 23% of 200K window

  πŸ“Š Top 10 Costliest Files:

    high        5,102 tokens (11%)  src/core/engine.ts
    moderate    2,891 tokens (6%)   src/utils/parser.ts
    ...

  🎭 Scenario Estimates:

    Bug Fix             12,450 tokens  (6% window)
    Refactor            28,100 tokens  (14% window)
    New Feature         31,200 tokens  (16% window)
    Code Review         38,400 tokens  (19% window)

Features a BPE-approximation tokenizer (~90% accuracy vs Claude's actual tokenizer), per-file cost analysis, 5 scenario simulations, and optimization recommendations.

🚫 Smart .claudeignore Generator

claude-doctor generate-claudeignore

Automatically identifies files wasting AI context tokens: lock files, build artifacts, minified code, generated files (via entropy analysis), binary assets, test fixtures, and large data files. Generates a ready-to-use .claudeignore with per-pattern token savings estimates.

πŸ“ Context Budget Optimizer

Uses Shannon entropy and TF-IDF information density scoring to analyze each section of your CLAUDE.md and recommend what to keep, condense, or remove:

claude-doctor analyze

πŸ”¬ Codebase AI-Readability Profiler

Scores every source file on how easy it is for AI coding agents to work with:

  • Cyclomatic complexity (deep nesting confuses AI)
  • Implicit state (global vars, singletons, side effects)
  • Dynamic patterns (eval, metaprogramming, Proxy)
  • Type ambiguity (any types, assertions, suppressions)
  • Coupling (import density, circular dependency risk)

πŸ“ CLAUDE.md Intelligence Analyzer

Parses your CLAUDE.md into discrete instructions and scores each for:

  • Clarity (vague words, action verbs, specificity)
  • Contradictions (pattern matching + semantic negation detection)
  • Redundancies (TF-IDF cosine similarity)
  • Readability (Flesch-Kincaid adapted for AI)
  • Overall AI Comprehension Score

⚑ Quick Start

# Run instantly with npx (no install needed)
npx claude-code-doctor

# Or install globally
npm install -g claude-code-doctor

# Then run anywhere
claude-doctor
# or
ccd

πŸ“‹ All Commands

Command Description
claude-doctor Full diagnostic health check
claude-doctor init Generate optimal Claude Code setup for your project
claude-doctor analyze Deep ML-powered analysis (all 7 engines)
claude-doctor scan-injections Prompt injection security scan
claude-doctor generate-claudemd Auto-generate CLAUDE.md from codebase
claude-doctor generate-claudeignore Smart .claudeignore with token savings
claude-doctor token-cost Token cost analysis and scenario prediction

Common Flags

# All commands support these
--path <path>          # Target project (defaults to cwd)
--format json          # Machine-readable JSON output
--dry-run              # Preview without writing files
--force                # Overwrite existing files

Diagnostic Flags

claude-doctor --fix                # Auto-fix all issues
claude-doctor --fix-interactive    # Step-by-step fix mode
claude-doctor --watch              # Watch mode (re-run on changes)
claude-doctor --badge              # Generate health badge SVG
claude-doctor --verbose            # Show detailed output
claude-doctor --only claudemd security  # Run specific checks only
claude-doctor --skip environment        # Skip specific checks
claude-doctor --format markdown > report.md  # Markdown report

✨ Smart Init

Auto-detect your project type and generate best-practice Claude Code configuration:

claude-doctor init

Supports: React, Next.js, Vue, Angular, Express, Python, Rust, Go, monorepos, and more.

πŸ” What It Checks

Category Checks What It Validates
πŸ–₯️ Environment 5 Node.js, npm, git, OS, memory
πŸ“¦ Installation 3 Claude Code binary, version, auth
βš™οΈ Configuration 4 .claude/ dir, settings, gitignore, commands
πŸ“ CLAUDE.md Lint 4 Exists, size/tokens, sections, anti-patterns
πŸ”Œ MCP Servers dynamic .mcp.json validity, server accessibility, env vars
πŸͺ Hooks dynamic Event names, commands, scripts
πŸ” Permissions 4 Write access, git init, node_modules
🧠 Context 3 Token overhead, large files, .claudeignore
πŸ›‘οΈ Security 12+ API keys, tokens, passwords, connection strings
🧠 AI Intelligence 10+ Injection scan, comprehension score, contradictions, graph health, token cost

45+ individual checks across 10 categories.

πŸ›‘οΈ Secret Detection

Deep scans for leaked secrets: AWS keys, Anthropic/OpenAI API keys, GitHub tokens, private keys, database URIs, JWT tokens, Slack/Stripe/SendGrid keys, and generic passwords.

πŸ”§ Auto-Fix

# Quick fix (automatic)
claude-doctor --fix

# Interactive fix (step-by-step)
claude-doctor --fix-interactive

πŸ‘€ Watch Mode

claude-doctor --watch

🏷️ Health Badge

claude-doctor --badge

Add to your README: ![Claude Code Health](.claude/health-badge.svg)

πŸ”„ CI/CD Integration

GitHub Actions

name: Claude Code Health
on: [push, pull_request]

jobs:
  doctor:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - uses: actions/setup-node@v4
        with:
          node-version: 20
      - run: npx claude-code-doctor --format json
      - run: npx claude-code-doctor scan-injections  # Security scan

Pre-commit Hook

# .husky/pre-commit
npx claude-code-doctor --only claudemd configuration security ai-insights --quiet

Exit Codes

Code Meaning
0 All checks passed (or only warnings)
1 One or more errors found
2 Doctor itself failed to run

πŸ“¦ Programmatic API

import { diagnose } from 'claude-code-doctor';
import { scanForInjections } from 'claude-code-doctor/ml';
import { generateClaudeMd } from 'claude-code-doctor/ml';
import { predictSessionCost } from 'claude-code-doctor/ml';
import { analyzeDependencyGraph } from 'claude-code-doctor/ml';
import { recommendClaudeignore } from 'claude-code-doctor/ml';

// Full diagnostic
const report = await diagnose({ path: './my-project' });
console.log(`Score: ${report.overallScore}% (${report.grade})`);

// Prompt injection scan
const threats = await scanForInjections('./my-project');
console.log(`Risk: ${threats.riskLevel} (${threats.findings.length} threats)`);

// Auto-generate CLAUDE.md
const claudemd = await generateClaudeMd('./my-project');
console.log(claudemd.content);

// Token cost analysis
const cost = await predictSessionCost('./my-project');
console.log(`${cost.totalProjectTokens} tokens (${cost.contextWindow.utilizationPercent}% of context)`);

// Dependency graph
const graph = await analyzeDependencyGraph('./my-project');
console.log(`${graph.circularDependencies.length} circular deps found`);

πŸ—οΈ Architecture

src/
β”œβ”€β”€ ml/                           # 9 Custom ML Engines (zero dependencies)
β”‚   β”œβ”€β”€ prompt-injection-scanner.ts   # πŸ›‘οΈ Security scan (20+ patterns)
β”‚   β”œβ”€β”€ dependency-graph.ts           # πŸ”— Graph intelligence (Tarjan, PageRank)
β”‚   β”œβ”€β”€ claudemd-generator.ts         # πŸ“ Auto-generate CLAUDE.md
β”‚   β”œβ”€β”€ claudeignore-recommender.ts   # 🚫 Smart .claudeignore
β”‚   β”œβ”€β”€ session-cost-predictor.ts     # πŸ’° Token cost & BPE tokenizer
β”‚   β”œβ”€β”€ instruction-analyzer.ts       # πŸ“Š CLAUDE.md intelligence
β”‚   β”œβ”€β”€ codebase-profiler.ts          # πŸ”¬ AI-readability scoring
β”‚   β”œβ”€β”€ context-optimizer.ts          # πŸ“ Context budget optimizer
β”‚   └── text-analyzer.ts             # πŸ”  NLP primitives (TF-IDF, cosine sim)
β”œβ”€β”€ checks/                       # 10 Diagnostic Check Categories
β”œβ”€β”€ commands/                     # CLI Commands (init, analyze, watch)
β”œβ”€β”€ reporters/                    # Output Formatters (terminal, JSON, markdown, badge)
β”œβ”€β”€ fixes/                        # Auto-Fix Engine
β”œβ”€β”€ utils/                        # Helpers
β”œβ”€β”€ doctor.ts                     # Core Orchestrator
└── types.ts                      # Type Definitions

🀝 Contributing

We welcome new checks and ML engines! See CONTRIBUTING.md.

πŸ“„ License

MIT β€” see LICENSE.


Built by Mishit18 · ⭐ Star us if this helped!

9 ML engines Β· 45+ checks Β· 10 categories Β· Zero external ML dependencies

About

🩺 Diagnose, lint, and auto-fix your Claude Code setup. 9 zero-dependency ML engines: prompt injection scanner, dependency graph intelligence (PageRank + Tarjan SCC), CLAUDE.md auto-generator, .claudeignore optimizer, session cost predictor. 45+ checks, auto-fix, CI/CD ready. The missing DevTool for Anthropic Claude Code.

Topics

Resources

License

Contributing

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors