Code Complexity Analyzer
Calculate cyclomatic complexity, cognitive complexity, Halstead metrics, and maintainability index for any codebase.
Get the CLI Tool
Run the complexity analyzer locally as an MCP server, or try it online below.
npx @clinetools/complexity
- 4 metrics — Cyclomatic, Cognitive, Halstead, Maintainability Index
- Per-function breakdowns with risk ratings
- Directory scanning — analyze entire projects
- JS/TS, Python, Go, Rust, Java, C/C++ support
- Zero config — just run with npx
How to Use It
Three ways to analyze code complexity — pick the one that fits your workflow.
Try Online
Use the interactive demo below to paste code and analyze complexity — no install needed.
Use via CLI
Run as a local MCP server and connect any MCP-compatible client.
Add to Cline / Claude Code
Add the tool to your MCP settings for instant access from your AI assistant.
MCP Client Configuration (Cline)
{
"mcpServers": {
"code-complexity": {
"command": "npx",
"args": ["@clinetools/complexity"]
}
}
}
Claude Code Configuration
# In your project's .mcp.json:
{
"mcpServers": {
"code-complexity": {
"command": "npx",
"args": ["@clinetools/complexity"]
}
}
}
Example Prompt: Analyze a Directory
// Prompt to your AI agent:
"Analyze the complexity of src/ and flag any
function with cyclomatic complexity over 15"
// The agent calls:
analyze_complexity({
path: "src/",
metrics: ["cyclomatic", "cognitive"]
})
Example Prompt: Find the Most Complex Function
// Prompt to your AI agent:
"Find the most complex function in this project
and suggest how to simplify it"
// The agent calls:
analyze_complexity({
path: ".",
metrics: ["all"]
})
// Then reads the hotspots list and offers refactoring advice
Try It Online
Paste code below and analyze its complexity with 4 industry-standard metrics.
Paste Code to Analyze
JavaScript, TypeScript, or Python source code
Paste code and click Analyze Complexity to see metrics.
Per-Function Breakdown
| Function | CC | Cog | Lines | Risk |
|---|
Understanding Complexity Metrics
What each metric measures and why it matters for code quality.
Cyclomatic Complexity
Counts independent paths through code: if, for, while, case, catch, &&, ||, ternary. Target: ≤10 per function. Created by Thomas McCabe in 1976.
Cognitive Complexity
Measures how hard code is to understand. Like cyclomatic but penalizes nesting: a nested if inside a for scores higher. Target: ≤15. Created by SonarSource.
Halstead Metrics
Counts operators and operands to estimate Volume (program size), Difficulty, Effort (time to write), and predicted Bugs. Created by Maurice Halstead in 1977.
Maintainability Index
Composite score (0-100) combining Halstead Volume, Cyclomatic Complexity, Lines of Code, and Comment Ratio. Grade A (≥80) to F (<20). Target: ≥60.
Need Automated Quality Gates?
Our Pro plan includes CI/CD complexity checks that block merges when thresholds are exceeded.
View Plans