mehen
mehen is a Rust-powered CLI for detecting heuristic source code metrics at scale: complexity, maintainability, lines of code, documentation health, and more.
It is designed for fast, deterministic analysis over large codebases, helping both human and AI engineers track how complexity evolves over time.
Documentation: https://mehen.ophi.dev
What is Mehen?
In Ophidiarium projects, names matter. Mehen is a mythical ancient Egyptian serpent associated with
guarding Ra. In the same spirit, mehen helps guard your codebase from slowly collapsing under
complexity.
Why teams use mehen
- Polyglot by design — per-file language detection across nine source languages plus Markdown and SQL. Useful for monorepos.
- Real language parsers — Ruff for Python, Oxc for TS/JS/JSX/TSX, Mago for PHP, Prism for Ruby,
ra_ap_syntaxfor Rust, the official Kotlin spec ANTLR grammar for Kotlin, pulldown-cmark for Markdown, sqruff for SQL, tree-sitter for Go, C, PowerShell. - Code, documentation, and SQL in one tool — source-code complexity, Markdown documentation
health, and a dedicated relational metric family for
.sqlfiles. - Deterministic, no network — pure static analysis. Same input → same output. Safe for air-gapped CI.
- Pull-request native — built-in
mehen diffplus a sticky comment GitHub Action.
Install
# npm
npm install -g mehen
# PyPI / uv
uv tool install mehen
# or: pip install mehen
# cargo binstall
cargo binstall --git https://github.com/ophi-dev/mehen mehen
Full installation guide: https://mehen.ophi.dev/installation.
Quick start
# Analyze a single file
mehen metrics src/main.py --pretty
# Rank the worst offenders in a tree
mehen top-offenders src --metric cognitive
# Diff metrics against main
mehen diff --from main --to HEAD --paths src --output-format markdown
Quickstart: https://mehen.ophi.dev/quickstart.
GitHub Action
Drop the action into a workflow to publish per-PR metric trends:
permissions:
contents: read
pull-requests: write
issues: write
steps:
- uses: actions/checkout@v6
with:
fetch-depth: 0
- uses: ophi-dev/mehen@v1
with:
paths: src
Full reference: https://mehen.ophi.dev/guides/github-action.
Documentation
Everything else lives in the docs site:
- Code metrics — cyclomatic, cognitive, Halstead, MI, ABC, LOC family, NOM, NPA, NPM, WMC.
- Markdown metrics — DMI, MRPC, MCC, link debt, filler/lazy risk, English/Japanese prose layer.
- SQL metrics — CTE graphs, join/subquery structure,
object-touch risk, SQL Halstead, and composite scores via
mehen-sql(sqruff-backed). - Commands —
mehen metrics,mehen diff,mehen top-offenders. - Developers guide — build, test, contribute, add a language.
Contributing
Issues and pull requests welcome at https://github.com/ophi-dev/mehen/issues.
License
mehen is released under the GNU Affero General Public License v3.0.