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.
Quick Start Β· ML Engines Β· Commands Β· Checks Β· CI/CD Β· Contributing
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%
What makes claude-code-doctor unique: 9 custom ML engines built from scratch with zero external ML dependencies.
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.
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.
claude-doctor analyzeBuilds 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
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.
claude-doctor generate-claudeignoreAutomatically 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.
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 analyzeScores 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 (
anytypes, assertions, suppressions) - Coupling (import density, circular dependency risk)
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
# 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| 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 |
# 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 filesclaude-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 reportAuto-detect your project type and generate best-practice Claude Code configuration:
claude-doctor initSupports: React, Next.js, Vue, Angular, Express, Python, Rust, Go, monorepos, and more.
| 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.
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.
# Quick fix (automatic)
claude-doctor --fix
# Interactive fix (step-by-step)
claude-doctor --fix-interactiveclaude-doctor --watchclaude-doctor --badgeAdd to your README: 
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# .husky/pre-commit
npx claude-code-doctor --only claudemd configuration security ai-insights --quiet| Code | Meaning |
|---|---|
0 |
All checks passed (or only warnings) |
1 |
One or more errors found |
2 |
Doctor itself failed to run |
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`);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
We welcome new checks and ML engines! See CONTRIBUTING.md.
MIT β see LICENSE.
Built by Mishit18 Β· β Star us if this helped!
9 ML engines Β· 45+ checks Β· 10 categories Β· Zero external ML dependencies