Skip to main content

Structural code quality analysis for Python

Project description

CodeClone

Structural code quality analysis for Python

PyPI Tests Benchmark Python

CodeClone provides deterministic structural code quality analysis for Python. It detects architectural duplication, computes quality metrics, and enforces CI gates with baseline-aware governance: known technical debt stays accepted, new regressions stay visible.

The same analysis pipeline powers CLI reports, CI checks, the MCP server, and native IDE/agent clients.

Features

  • Clone detection: function, block, and report-only segment clones.
  • Structural findings: duplicated branch families, clone guard/exit divergence, and clone-cohort drift.
  • Quality metrics: complexity, coupling, cohesion, dependency cycles, adaptive dependency depth, dead code, health score, and overloaded-module profiling.
  • Coverage Join: combines Cobertura XML with CodeClone units to surface coverage hotspots and scope gaps.
  • Security Surfaces: report-only inventory of security-relevant boundaries and sensitive capabilities. It does not claim vulnerabilities.
  • Baseline governance: separates accepted legacy debt from new regressions.
  • Reports: HTML, JSON, Markdown, SARIF, and text from one report payload.
  • MCP control surface: read-only agent/IDE interface over the same pipeline.
  • Native clients: VS Code extension, Claude Desktop bundle, and Codex plugin.

Quick Start

uv tool install codeclone

codeclone .                    # analyze
codeclone . --html             # write HTML report
codeclone . --html --open-html-report
codeclone . --json --md --sarif --text
codeclone . --ci               # CI mode

Run without installing:

uvx codeclone@latest .

CI Workflow

# 1. Generate and commit the baseline
codeclone . --update-baseline

# 2. Enforce it in CI
codeclone . --ci

--ci enables baseline-aware gating and exits with deterministic status codes:

Code Meaning
0 Success
2 Contract error, such as an untrusted baseline or invalid config
3 Gating failure, such as new clones or failed metric thresholds
5 Internal error

Reports

codeclone . --html
codeclone . --json
codeclone . --md
codeclone . --sarif
codeclone . --text

All report formats are rendered from the same deterministic report payload. The HTML report is intended for human review; JSON, SARIF, Markdown, and text are intended for automation and CI surfaces.

Report contract: https://orenlab.github.io/codeclone/book/08-report/

MCP and Native Clients

Install the optional MCP runtime when you want CodeClone in AI agents or IDEs:

uv tool install "codeclone[mcp]"

codeclone-mcp --transport stdio

The MCP server is read-only by contract. It does not mutate source files, baselines, cache, or repository state.

Client surfaces:

Surface Link
VS Code extension https://marketplace.visualstudio.com/items?itemName=orenlab.codeclone
Claude Desktop bundle https://github.com/orenlab/codeclone/tree/main/extensions/claude-desktop-codeclone
Codex plugin https://github.com/orenlab/codeclone/tree/main/plugins/codeclone

MCP docs: https://orenlab.github.io/codeclone/book/20-mcp-interface/

Configuration

CodeClone reads project configuration from pyproject.toml:

[tool.codeclone]
baseline = "codeclone.baseline.json"
min_loc = 10
min_stmt = 6
block_min_loc = 20
block_min_stmt = 8
fail_on_new = true
fail_cycles = true
fail_dead_code = true
fail_health = 80

Precedence is deterministic:

CLI flags > pyproject.toml > built-in defaults

Config reference: https://orenlab.github.io/codeclone/book/04-config-and-defaults/

License

  • Code: MPL-2.0 (LICENSE)
  • Documentation and docs-site content: MIT (LICENSE-MIT)

License scope map: https://github.com/orenlab/codeclone/blob/main/LICENSES.md

Project details


Download files

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

Source Distribution

codeclone-2.0.0.tar.gz (570.5 kB view details)

Uploaded Source

Built Distribution

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

codeclone-2.0.0-py3-none-any.whl (462.3 kB view details)

Uploaded Python 3

File details

Details for the file codeclone-2.0.0.tar.gz.

File metadata

  • Download URL: codeclone-2.0.0.tar.gz
  • Upload date:
  • Size: 570.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for codeclone-2.0.0.tar.gz
Algorithm Hash digest
SHA256 f2f389c3a9a2483ec930da0fd51c6b871fb65a1d9ebc66861f5416e6ba081564
MD5 23a532d114dad810a572d73423c9911b
BLAKE2b-256 4ae572919296801ea41c75d5fe2ba0ff7c5506a766bf3f9cfc25320e2b4ebfd1

See more details on using hashes here.

Provenance

The following attestation bundles were made for codeclone-2.0.0.tar.gz:

Publisher: publish.yml on orenlab/codeclone

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

File details

Details for the file codeclone-2.0.0-py3-none-any.whl.

File metadata

  • Download URL: codeclone-2.0.0-py3-none-any.whl
  • Upload date:
  • Size: 462.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for codeclone-2.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 63876bc2e14052cf0c18014178d3387667ae871518f28b7dc5c2399d3eb1d8de
MD5 6107f94598095e4242e33c87cc95a8a6
BLAKE2b-256 a62cf74e76fddc4302d21e9f55a603f27aa4a130a074201be0db9a2823bed09e

See more details on using hashes here.

Provenance

The following attestation bundles were made for codeclone-2.0.0-py3-none-any.whl:

Publisher: publish.yml on orenlab/codeclone

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

Supported by

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