butter-code-health
Enables AI assistants to analyze code health in TypeScript/JavaScript projects, providing tools to run analysis, start a dashboard, and get summaries.
README
butter-code-health
A global Node.js CLI tool that analyzes code health in TypeScript/JavaScript projects and provides a beautiful browser-based dashboard for visualizing static analysis results.
Features
- 🔍 Multi-tool Analysis: Combines ESLint, dependency-cruiser, knip, and cloc
- 📊 Browser Dashboard: Beautiful, interactive web UI for exploring results
- 👁️ Watch Mode: Live updates as you code
- 🏗️ Monorepo Support: Works with npm/yarn/pnpm workspaces
- 🚫 Zero Config: No files added to your repo by default
- 🎯 Smart Defaults: Sensible rules and thresholds out of the box
Installation
Install globally:
npm install -g butter-code-health
Or run directly with npx:
npx butter-code-health dashboard
Usage
Dashboard Mode (Recommended)
Launch an interactive dashboard to explore your code health:
# Basic dashboard
code-health dashboard
# With file watching and auto-refresh
code-health dashboard --watch
# Auto-open browser
code-health dashboard --open
Analyze Mode
Run a one-time analysis and view results:
code-health analyze
# With custom directory
code-health analyze --cwd /path/to/project
Print Mode (CI-Friendly)
Output analysis results to stdout:
# Text format (default)
code-health print
# JSON format for CI/CD pipelines
code-health print --format json
# Fails with exit code 1 if thresholds exceeded
code-health print --max-lines 300 --complexity-threshold 10
CLI Options
Global Options
--cwd <path>- Set root directory for analysis (default: current directory)--include <glob,glob>- Include specific file patterns--exclude <glob,glob>- Exclude specific file patterns--no-gitignore- Don't use .gitignore for exclusions--port <number>- Dashboard server port (default: 43110)--open- Auto-open browser when server starts
Threshold Options
--max-lines <n>- Max lines per file (default: 400)--max-lines-per-function <n>- Max lines per function (default: 80)--complexity-threshold <n>- Cognitive complexity threshold (default: 15)
MCP (Model Context Protocol) Integration
The tool includes an MCP server for AI assistant integration. Add to your .mcp.json:
{
"mcpServers": {
"code-health": {
"command": "npx",
"args": ["butter-code-health@latest", "code-health-mcp"],
"env": {
"CODE_HEALTH_AUTO_START": "true",
"CODE_HEALTH_PORT": "3020"
}
}
}
}
This allows AI assistants to analyze your code health directly.
What It Analyzes
📏 Code Size
- Lines of code per file
- Identifies largest files
- Tracks code vs comments vs blank lines
🧠 Cognitive Complexity
- Functions with high cognitive complexity
- Based on SonarJS rules
- Helps identify hard-to-maintain code
🔄 Dependency Cycles
- Circular dependencies between modules
- Helps maintain clean architecture
- Essential for large codebases
💀 Dead Code
- Unused files and exports
- Powered by knip
- Reduce bundle size and maintenance burden
📐 Code Standards
- Max lines violations
- TypeScript best practices
- Performance anti-patterns
Dashboard Features
The browser dashboard provides:
- Sortable Tables: Click headers to sort by any column
- Search & Filter: Quick filtering for all tables
- Live Updates: Auto-refresh in watch mode
- Copy to Clipboard: Easy sharing of findings
- Detailed Views: Expandable rows for more context
Default Ignore Patterns
The tool automatically ignores:
node_modules/.git/- Build outputs (
dist/,build/,.next/) - Cache directories
- Lock files
- Environment files
- Config files
Plus anything in your .gitignore (unless --no-gitignore is used).
Monorepo Support
Automatically detects and analyzes:
- npm/yarn workspaces (via
package.json) - pnpm workspaces (via
pnpm-workspace.yaml) - Common patterns (
apps/*,packages/*)
Configuration
While the tool works with zero configuration, it respects existing project configs:
- ESLint configurations (flat or legacy)
- TypeScript configs for path resolution
.gitignorefor file exclusions
Examples
Analyze a TypeScript monorepo
cd /path/to/monorepo
npx butter-code-health dashboard --watch --open
CI/CD Integration
# In your CI pipeline
npx butter-code-health print --format json > code-health.json
# Or fail on violations
npx butter-code-health print --max-lines 500 --complexity-threshold 20
Custom Analysis
# Analyze specific directories
code-health analyze --include "src/**/*.ts" --exclude "**/*.test.ts"
# Override thresholds
code-health dashboard --max-lines 600 --max-lines-per-function 100
MCP Integration (Model Context Protocol)
This tool can be used as an MCP server, making it available to AI assistants like Claude Code for automatic code analysis.
Installation for MCP
Install globally:
npm install -g butter-code-health
Add to your .mcp.json file in your project root:
{
"mcpServers": {
"code-health": {
"command": "code-health-mcp",
"args": []
}
}
}
Or use with npx (if not installed globally):
{
"mcpServers": {
"code-health": {
"command": "npx",
"args": ["butter-code-health", "code-health-mcp"]
}
}
}
MCP Tools Available
Once configured, the following tools are available to AI assistants:
code_health_analyze: Run comprehensive code health analysiscode_health_dashboard: Start the dashboard server with browser UIcode_health_stop_dashboard: Stop the running dashboard servercode_health_summary: Get a quick summary of code health metrics
Example MCP Usage
AI assistants can now run commands like:
- "Analyze the code health of this project"
- "Start a code health dashboard for this codebase"
- "Show me a summary of code quality issues"
The dashboard will be automatically available at http://localhost:43110 when started via MCP.
Requirements
- Node.js 18 or higher
- Works with any JavaScript/TypeScript project
License
MIT
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
推荐服务器
Baidu Map
百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。
Playwright MCP Server
一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。
Magic Component Platform (MCP)
一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。
Audiense Insights MCP Server
通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。
VeyraX
一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。
graphlit-mcp-server
模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。
Kagi MCP Server
一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。
e2b-mcp-server
使用 MCP 通过 e2b 运行代码。
Neon MCP Server
用于与 Neon 管理 API 和数据库交互的 MCP 服务器
Exa MCP Server
模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。