Skip to main content

code-ranker

CI codecov code-ranker Crates.io npm PyPI License

Website Install the GitHub App

Structural-analysis tool for Rust (production-ready) plus Python, TypeScript/JavaScript, Go, C, C++, C# and Markdown (beta) codebases. Built AI-agent-friendly first — finds where a project has structural problems and hands an actionable shortlist to a human or an AI agent for the actual refactor.

👉 Map your codebase's worst structural problems in 30 seconds — jump to the Rust quick start and run it on your repo now.

Status: 5.0.3 — the Rust analyzer is production-ready; the other languages are beta, so their output shapes may still change.

Rust quick start

cargo install code-ranker  # install the CLI
code-ranker report .       # make html report in .code-ranker/ folder

report . needs no flags: it writes a self-contained HTML report (plus a JSON snapshot) into .code-ranker/. Open the latest …-<commit>.html to explore the dependency graph, per-file metrics, and the AI prompt generator. Everything below is detail.

Offline & private

code-ranker always runs entirely on your machine. It makes no network calls, sends no telemetry or analytics, and never uploads your code or analysis results anywhere. Generated HTML reports are self-contained — no CDN, no external requests, no tracking.

AI agents friendly

Hand your codebase to an AI agent and let it fix the worst spot. code-ranker is built to feed work straight to an AI coding agent (Claude Code, Cursor, …). Run code-ranker docs <lang> ai in your repo (e.g. code-ranker docs rust ai) — it prints a short, offline playbook (no network) that teaches the agent which two metrics matter (dependency cycles ADP, coupling HK) and the exact fix loop (scorecard → snapshot → fix → re-check → before/after report), for your project's language.

Then just ask, e.g.:

  • "Run code-ranker docs rust ai and follow it: find the worst dependency cycle in this project and propose a refactor that breaks it — show me the plan before changing code."
  • "Run code-ranker docs rust ai for the playbook, then find the most complex / highest-HK file and analyze how to split it; explain what the split buys for me (lower coupling, smaller blast radius). Take a before report, apply the split, take an after report, and show me the HTML diff."

The agent drives the CLI itself — code-ranker docs <lang> ai spells out the commands and the loop, so no glue is needed. (Prefer a file in context? The same playbook lives at docs/ai-skill.md.)

What it finds

  • Files that grew too complex and should be split. Per-file cyclomatic / cognitive / Halstead / MI metrics; flags files above your threshold.
  • Strong coupling between files. Computes fan-in / fan-out / HK on the file dependency graph; surfaces the files that everything depends on (or that depend on everything). Third-party libraries are tracked separately as depth-1 external nodes (fan_out_external), so they never inflate your internal-coupling numbers.
  • Cyclic dependencies. Detects SCCs in the file graph — including the silent ones the compiler does not catch.
  • Files that are just too big. Raw LOC, public surface size per file.

The tool does not refactor for you. It produces a structured, machine-readable list of problem spots and an offline HTML report a human or an LLM can act on.

CI integration

Runs as a linter. Configure thresholds in code-ranker.toml; the CLI exits non-zero when the codebase breaches them — so a PR that introduces a new cycle, a file above your cognitive budget, or a file above your LOC limit fails the build.

code-ranker check . \
  --threshold file.cognitive=25 --threshold file.loc=800

The linter is the check command — exits non-zero on any cycle or threshold violation, e.g. a PR that introduces a new file-level cycle or a file above your LOC limit (mutual and chain cycle checks are on by default). See docs/CLI.md for all flags.

Add it to your pipeline today — one code-ranker check step stops new cycles and bloat from ever landing.

Prefer zero config? Install the GitHub App — it publishes a per-PR HTML structural report on every pull request, no workflow YAML to write. More at code-ranker.com.

Full CLI

Written in Rust — fast, memory-safe, single static-ish binary with no runtime dependencies (no Python, no Node, no JVM, no shared libs to install). One file on PATH, done.

Two commands: check (linter — exits non-zero on violations; with --baseline, a relative regression gate) and report (snapshot JSON + offline HTML; with --baseline, a baseline↔current diff). Both accept a directory or an existing .json/.html snapshot as input — analyze once, then run cheap passes over the snapshot. No daemon, no language server, no plugin host required at runtime. Full reference: docs/CLI.md.

HTML report with dynamic diagrams

code-ranker report writes a single self-contained HTML file with:

  • An interactive file dependency graph; third-party libraries appear as depth-1 external nodes in a distinct amber colour with dashed edges.
  • Dagre-laid-out graph with pan/zoom and live filtering.
  • Sortable table per metric; click a node to open its neighbourhood.
  • "Prompt generator" panel that copies a ready-to-paste prompt (one for each principle: ADP, SRP, OCP, LSP, ISP, DIP, DRY, KISS, LoD, MISU, CoI, YAGNI; plus Reduce Complexity, Split Components) — feed the prompt + the selected nodes to your AI agent.

No network, no analytics, no telemetry. Open in any browser, share as a file.

Live demo — code-ranker run on its own repo: interactive HTML report · JSON snapshot (regenerated on every push to main).

Install

Pick any channel — all ship the same code-ranker binary (Linux, macOS, Windows). Full guide with exact commands: docs/installation.md.

  • Shell / PowerShell installer — prebuilt binary on PATH (universal)
  • Cargocargo install code-ranker · crates.io
  • npmnpm install -g code-ranker · npm
  • pip / uv / pipxpip install code-ranker · PyPI
  • DockerDocker Hub · GHCR

Quick start

# lint a project — non-zero exit on violations (CI linter)
code-ranker check ./path/to/project

# analyze and write a snapshot JSON + offline HTML report
code-ranker report
# → .code-ranker/{ts}-{git-hash-3}.json + .code-ranker/{ts}-{git-hash-3}.html
#   (override paths via --output.<fmt>.path or [output.<fmt>] in code-ranker.toml)

# before / after refactor comparison: an HTML diff against a baseline snapshot
code-ranker report . --baseline .code-ranker/before.json

Built-in plugins for all nine supported languages (rust uses cargo + syn; Rust is production-ready, the rest are beta) — all compiled into the single binary, nothing to install.

Documentation

  • Installation — every install channel with exact commands
  • CLI — commands, flags, and examples
  • Rule reference — rule ids grouped by concern (CYC/CPX/CPL/SIZ), per-file thresholds (file), what each flags, and how to fix it
  • Configcode-ranker.toml schema
  • AI agent skill — a short playbook to attach to an AI agent's context (the ADP/HK fix loop)
  • PRD — product requirements
  • DESIGN — technical design
  • Why structure matters — the empirical evidence (studies, books, statistics) behind the signals code-ranker measures
  • Principles corpus — Rust / Python / TypeScript principle catalogues used by the prompt generator

Try it now

cargo install code-ranker && code-ranker report . && open .code-ranker/

One command on any Rust project — you'll have an interactive structural map and an AI-ready shortlist in seconds. ⭐ the repo if it helps.

License

Apache-2.0. Copyright (c) 2026 Roman Fedorov.

Contributions are accepted under the project CLA — see CONTRIBUTING.md. The "code-ranker" name is a trademark of Roman Fedorov and is not covered by the code license; naming rules for forks and derivative products are in TRADEMARK.md.

Download files

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

Source Distribution

code_ranker-5.0.3.tar.gz (1.3 MB view details)

Uploaded Source

Built Distributions

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

code_ranker-5.0.3-py3-none-win_amd64.whl (6.7 MB view details)

Uploaded Python 3Windows x86-64

code_ranker-5.0.3-py3-none-manylinux_2_28_x86_64.whl (6.7 MB view details)

Uploaded Python 3manylinux: glibc 2.28+ x86-64

code_ranker-5.0.3-py3-none-manylinux_2_28_aarch64.whl (6.3 MB view details)

Uploaded Python 3manylinux: glibc 2.28+ ARM64

code_ranker-5.0.3-py3-none-macosx_11_0_arm64.whl (6.3 MB view details)

Uploaded Python 3macOS 11.0+ ARM64

File details

Details for the file code_ranker-5.0.3.tar.gz.

File metadata

  • Download URL: code_ranker-5.0.3.tar.gz
  • Upload date:
  • Size: 1.3 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for code_ranker-5.0.3.tar.gz
Algorithm Hash digest
SHA256 519ed5f116f8ea7850c03abdc5fca72f6b651ee00b1596a1b02731a0de40c13f
MD5 fad6eca71d3416701e07664342013d7f
BLAKE2b-256 ca446152d9f309c1746bb9317bd6190c1cf3794a8903137f8281f529e0304dd9

See more details on using hashes here.

File details

Details for the file code_ranker-5.0.3-py3-none-win_amd64.whl.

File metadata

  • Download URL: code_ranker-5.0.3-py3-none-win_amd64.whl
  • Upload date:
  • Size: 6.7 MB
  • Tags: Python 3, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for code_ranker-5.0.3-py3-none-win_amd64.whl
Algorithm Hash digest
SHA256 b435676e0269346b5ebb54ee16d59a1ff45692bfd356fa74a7586eda838ebf8f
MD5 1224cb20c1b5769ecdbaf1f2f7f9085f
BLAKE2b-256 4618772fe031778e20f5bcf40e06cd7f1d78db79b3ec04c3231f92b7f7eba0a3

See more details on using hashes here.

File details

Details for the file code_ranker-5.0.3-py3-none-manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for code_ranker-5.0.3-py3-none-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 d45986fdf70e452a12d5750cdceb7b702d5c1e3f7ea70b06293ef39e4da8e6bd
MD5 afe03b69ff7c6149c1b4ba9678489821
BLAKE2b-256 77dd9d28dad598519164f926de40ec2865a3057efa40f32af63d1d287eb84d44

See more details on using hashes here.

File details

Details for the file code_ranker-5.0.3-py3-none-manylinux_2_28_aarch64.whl.

File metadata

File hashes

Hashes for code_ranker-5.0.3-py3-none-manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 c1984c37a679ec9a0014e8e154e3a13b6fa6d1d4ea1575a3be3cc5fa7a1cab3a
MD5 21c6e24e30e8d74db6d36a889cca840d
BLAKE2b-256 83d2b756433ad4da2fb66ee0032a962ff25818db466a81e8a752d80fd11b85aa

See more details on using hashes here.

File details

Details for the file code_ranker-5.0.3-py3-none-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for code_ranker-5.0.3-py3-none-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 a65641264d5ba2c387837d0291ac359ea4f3a1dccfba9d8649465583c489fd82
MD5 3be63028972a6f6d6c31765401248046
BLAKE2b-256 7c770c7130f23550f05f4ef10c716d463beb01a91bf919f0bb04fbbca651a5b9

See more details on using hashes here.

Release history Release notifications | RSS feed

5.0.4

5 files

This release

5.0.3 This release

5 files

5.0.0

5 files

4.0.0

5 files

3.0.2

5 files

3.0.1

5 files

3.0.0

5 files

2.0.0

5 files

1.1.0

5 files

1.0.0

5 files

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page