Codelens
High performance code analysis tool written in Rust — stats, health scores, hotspots, trends, and cost estimation.
Features
- Fast: Parallel file traversal, 30-50x faster than Python alternatives
- 65+ Languages: Built-in support for popular programming languages
- Smart Filtering: Respects
.gitignore, auto-excludes build directories - Multiple Outputs: Console, JSON, CSV, Markdown, HTML with charts
- Complexity Analysis: Function count, cyclomatic complexity, nesting depth
- Health Score: Project/directory/file-level health grading (A-F) with pluggable scoring models
- Hotspot Detection: Identify risky files via churn × complexity analysis
- Trend Tracking: Save snapshots and compare codebase evolution over time
- Cost Estimation: Multi-model development cost estimation (COCOMO Basic/II, Putnam, LOCOMO)
- Extensible: Add custom languages via TOML configuration
Installation
Homebrew (macOS/Linux)
Cargo
Build from source
Usage
# Analyze current directory
# Analyze specific directories
# Only count specific languages
# Output JSON
# Output HTML report
# Show top 20 languages by code lines
# Exclude directories
# List supported languages
Health Score
Score code health across five dimensions (complexity, function size, comment ratio, file size, nesting depth) with grades from A to F.
Hotspot Detection
Find the riskiest files by combining git change frequency (churn) with code complexity — files that change often AND are complex are the most likely sources of bugs.
Trend Tracking
Save snapshots and compare codebase evolution over time. Snapshots are stored in .codelens/snapshots/. Use latest, latest~N, or a date prefix like 2025-01-01 as references.
Cost Estimation
Estimate development cost, schedule, and team size using four pluggable models. Default mode runs all models and shows a comparison table.
| Model | Description | Reference | Typical Use |
|---|---|---|---|
| COCOMO Basic | Classic Boehm 1981 regression | Software Engineering Economics, Boehm 1981 (ISBN 0-13-822122-7) | Quick estimates, scc comparison |
| COCOMO II | Modern 2000 calibration with scale factors | Software Cost Estimation with COCOMO II, Boehm et al. 2000 (ISBN 0-13-026692-2) | Organization-level planning |
| Putnam/SLIM | Rayleigh-curve conservative model | A General Empirical Solution to the Macro Software Sizing and Estimating Problem, IEEE TSE 1978 | Risk assessment, worst case |
| LOCOMO | LLM token cost model | scc LOCOMO model, Boyter 2026 | AI-assisted development cost |
Output Formats
| Format | Flag | Description |
|---|---|---|
| Console | -f console |
Colored terminal output (default) |
| JSON | -f json |
Structured data for processing |
| CSV | -f csv |
Spreadsheet compatible |
| Markdown | -f markdown |
Documentation friendly |
| HTML | -f html |
Interactive report with charts |
Configuration
Create .codelens.toml in your project root:
# Exclude patterns
= "*test*,*mock*"
# Target languages
= "rust,go,python"
# Output format
= "json"
# Threading
= 8
# Depth limit
= 10
# Show git info
= true
Custom Languages (Planned)
Note: This feature is planned but not yet implemented.
Custom language definitions will be supported in ~/.config/codelens/languages.toml:
[]
= "MyLang"
= [".ml", ".mli"]
= ["#"]
= [["/*", "*/"]]
= "^\\s*def\\s+\\w+"
= ["if", "for", "while"]
License
MIT