Skip to main content

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 eleven 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_syntax for Rust, ANTLR (Kotlin spec grammar for Kotlin, grammars-v4 for Java and C#), 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 .sql files.
  • Deterministic, no network — pure static analysis. Same input → same output. Safe for air-gapped CI.
  • Pull-request native — built-in mehen diff plus 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.

Configuration

Drop a mehen.toml (or .mehen.toml) anywhere between the directory you run mehen from and the git repository root — discovery walks upward and stops at the repository boundary — or pin an explicit file with --config <PATH>:

[thresholds]
cognitive = 15         # higher-is-worse metrics: the limit is a maximum
"loc.lloc" = 500
mi.visual_studio = 40  # higher-is-better metrics (mi.*): the limit is a minimum

[languages.python.thresholds]
cognitive = 10         # overrides the global limit for Python files only

Every command that reports a configured metric enforces it: mehen metrics checks the full metric set of the analyzed file, while mehen diff (head side) and mehen top-offenders check the metrics selected for output — across all analyzed files, not just the displayed rows. Any crossed limit prints a grouped report on stderr and fails the command with exit code 1:

  × 2 metric threshold violations (config: /repo/mehen.toml)
  │
  │ src/app/core.py
  │   cognitive = 23 — exceeds max 10  (set by languages.python.thresholds)
  │   loc.lloc = 640 — exceeds max 500  (set by thresholds)
  help: adjust or remove the limit at the configuration path shown, or bring the file back within it.

Configuration mistakes fail fast with a caret into the TOML source and a suggestion ("unknown metric cognitve … did you mean cognitive?"): every metric name is validated against the keys the analyzers actually publish — including the sql.* and markdown.* namespaces — so a typo can never silently disable a gate. Full reference: https://mehen.ophi.dev/configuration.

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).
  • Commandsmehen metrics, mehen diff, mehen top-offenders.
  • Configurationmehen.toml thresholds and per-language overrides.
  • 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.

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

mehen-1.9.0.tar.gz (1.6 MB view details)

Uploaded Source

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

mehen-1.9.0-py3-none-win_arm64.whl (11.1 MB view details)

Uploaded Python 3Windows ARM64

mehen-1.9.0-py3-none-win_amd64.whl (12.4 MB view details)

Uploaded Python 3Windows x86-64

mehen-1.9.0-py3-none-manylinux_2_28_x86_64.whl (11.9 MB view details)

Uploaded Python 3manylinux: glibc 2.28+ x86-64

mehen-1.9.0-py3-none-manylinux_2_28_aarch64.whl (11.0 MB view details)

Uploaded Python 3manylinux: glibc 2.28+ ARM64

mehen-1.9.0-py3-none-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (11.0 MB view details)

Uploaded Python 3manylinux: glibc 2.17+ ARM64

mehen-1.9.0-py3-none-manylinux_2_5_x86_64.manylinux1_x86_64.whl (12.0 MB view details)

Uploaded Python 3manylinux: glibc 2.5+ x86-64

mehen-1.9.0-py3-none-macosx_11_0_arm64.whl (10.9 MB view details)

Uploaded Python 3macOS 11.0+ ARM64

mehen-1.9.0-py3-none-macosx_10_12_x86_64.whl (11.8 MB view details)

Uploaded Python 3macOS 10.12+ x86-64

File details

Details for the file mehen-1.9.0.tar.gz.

File metadata

  • Download URL: mehen-1.9.0.tar.gz
  • Upload date:
  • Size: 1.6 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for mehen-1.9.0.tar.gz
Algorithm Hash digest
SHA256 0a9c8260e4e867d08af2fa52e0798113770ae018fe024eceb25d94de9b806a00
MD5 f9487a329e39a57e38aa0ad2f5ca3d95
BLAKE2b-256 2f662fc14a319c5897e00a5fe958121f3d15d2c8b81e487fc7b64135839c5666

See more details on using hashes here.

Provenance

The following attestation bundles were made for mehen-1.9.0.tar.gz:

Publisher: release.yml on ophi-dev/mehen

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file mehen-1.9.0-py3-none-win_arm64.whl.

File metadata

  • Download URL: mehen-1.9.0-py3-none-win_arm64.whl
  • Upload date:
  • Size: 11.1 MB
  • Tags: Python 3, Windows ARM64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for mehen-1.9.0-py3-none-win_arm64.whl
Algorithm Hash digest
SHA256 3dc0780efbddf08d9442a6085aa86b6c813887dd01453ce509a0a3bd7b282e81
MD5 596ba0149b31ced3783ebe0a66ae464b
BLAKE2b-256 b268d4fbbbbf8eab01e4a6291e9d1b7811d598ac0eeb258fedfb186f59979d4f

See more details on using hashes here.

Provenance

The following attestation bundles were made for mehen-1.9.0-py3-none-win_arm64.whl:

Publisher: release.yml on ophi-dev/mehen

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file mehen-1.9.0-py3-none-win_amd64.whl.

File metadata

  • Download URL: mehen-1.9.0-py3-none-win_amd64.whl
  • Upload date:
  • Size: 12.4 MB
  • Tags: Python 3, Windows x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for mehen-1.9.0-py3-none-win_amd64.whl
Algorithm Hash digest
SHA256 dff88b87c9dc3eedf07f476bfa33025ad675c8f832c43c0184bca7fbccecffbd
MD5 e461b7d400426157b09c05f3f00725bb
BLAKE2b-256 d760a593a1a017b5b66d9d355e3a46ddd153aeebc7af9a1158eae5c2991aed58

See more details on using hashes here.

Provenance

The following attestation bundles were made for mehen-1.9.0-py3-none-win_amd64.whl:

Publisher: release.yml on ophi-dev/mehen

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file mehen-1.9.0-py3-none-manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for mehen-1.9.0-py3-none-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 d8c80d6d32e8bcec5f6e050a9ef6b4e3d5b0822596df965e46053962dad5c263
MD5 c5764cc4d096127c2a0a8ac2a8b863a0
BLAKE2b-256 e37be4d0f64ad7c685e834dcd23795ac83259db166d771052c95e6fe6dfbf60e

See more details on using hashes here.

Provenance

The following attestation bundles were made for mehen-1.9.0-py3-none-manylinux_2_28_x86_64.whl:

Publisher: release.yml on ophi-dev/mehen

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file mehen-1.9.0-py3-none-manylinux_2_28_aarch64.whl.

File metadata

File hashes

Hashes for mehen-1.9.0-py3-none-manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 bb16c1d7281efdeef783453fee1606aa3e177434445773a4b270179c34381963
MD5 036b27c520ee10731264703048d419d7
BLAKE2b-256 a8344e4e1f30482fa236a00314b63199b744ea62b5fee9a5bf7a7dc4a4540f25

See more details on using hashes here.

Provenance

The following attestation bundles were made for mehen-1.9.0-py3-none-manylinux_2_28_aarch64.whl:

Publisher: release.yml on ophi-dev/mehen

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file mehen-1.9.0-py3-none-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for mehen-1.9.0-py3-none-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 47c4609be0a99ddbdacd7140b8653d1a2d4c141db67417fe0986069c3ac81223
MD5 ab191c58d1e5044757a03025f30e5329
BLAKE2b-256 a4fcc90e0caf3b27083bce971766e50fa21243803a93c671bded25e1ea68664f

See more details on using hashes here.

Provenance

The following attestation bundles were made for mehen-1.9.0-py3-none-manylinux_2_17_aarch64.manylinux2014_aarch64.whl:

Publisher: release.yml on ophi-dev/mehen

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file mehen-1.9.0-py3-none-manylinux_2_5_x86_64.manylinux1_x86_64.whl.

File metadata

File hashes

Hashes for mehen-1.9.0-py3-none-manylinux_2_5_x86_64.manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 424039460f028ee99156be1270f542d74fded331dd32e05cffa6693346a23afc
MD5 7025aafdd5b2c30730ccd1b36c8a0696
BLAKE2b-256 6c420cc7ef6aa2fd8703dfff6258bb7f61356aea959dcec633eca3d1d3016b83

See more details on using hashes here.

Provenance

The following attestation bundles were made for mehen-1.9.0-py3-none-manylinux_2_5_x86_64.manylinux1_x86_64.whl:

Publisher: release.yml on ophi-dev/mehen

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file mehen-1.9.0-py3-none-macosx_11_0_arm64.whl.

File metadata

  • Download URL: mehen-1.9.0-py3-none-macosx_11_0_arm64.whl
  • Upload date:
  • Size: 10.9 MB
  • Tags: Python 3, macOS 11.0+ ARM64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for mehen-1.9.0-py3-none-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 db88782bc98a5097c5c9620f8ccba67bda1e93f0b4718c49979b9a6b52e1c211
MD5 0a7f46e097a3f9fd174a164e5240293e
BLAKE2b-256 7013385166f85b35011700e7fa6117353c7e81dbff18f351f3186d298227c4dc

See more details on using hashes here.

Provenance

The following attestation bundles were made for mehen-1.9.0-py3-none-macosx_11_0_arm64.whl:

Publisher: release.yml on ophi-dev/mehen

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file mehen-1.9.0-py3-none-macosx_10_12_x86_64.whl.

File metadata

File hashes

Hashes for mehen-1.9.0-py3-none-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 3b1d460a7ea6a0bebf80e773c7c8472c4f51b40806db57149ebf7862a677ed4e
MD5 1a738f2e31a7c3b9bc0d033bbe689cd8
BLAKE2b-256 e9cf34ad33cdc0baaa757098ff6aa49466d0d732d2e04b116204265656bb152c

See more details on using hashes here.

Provenance

The following attestation bundles were made for mehen-1.9.0-py3-none-macosx_10_12_x86_64.whl:

Publisher: release.yml on ophi-dev/mehen

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Release history Release notifications | RSS feed

1.10.0

9 files

This release

1.9.0 This release

9 files

1.8.1

9 files

1.8.0

9 files

1.7.0

9 files

1.6.0

9 files

1.5.1

9 files

1.4.1

9 files

1.4.0

9 files

1.3.0

9 files

1.2.0

9 files

1.1.0

9 files

1.0.2

9 files

0.7.0

7 files

0.5.0

8 files

0.4.3

7 files

0.4.1

8 files

0.4.0

8 files

0.2.0

8 files

0.1.0

7 files

0.0.6

8 files

0.0.5

8 files

0.0.4

7 files

0.0.3

8 files

0.0.2

8 files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page