A structural review layer for Python — baseline-aware, deterministic, built for CI and AI agents
Project description
A structural review layer for Python — baseline-aware, deterministic, built for CI and AI agents
CodeClone adds a control layer between analysis and CI: it isolates structural regressions from historical debt, so merges are blocked only by what actually got worse.
The same analysis pipeline powers CLI reports, CI checks, the MCP server, and native IDE/agent clients — so humans and AI agents operate on identical, deterministic facts.
- Documentation: https://orenlab.github.io/codeclone/
- Live sample report: https://orenlab.github.io/codeclone/examples/report/
- Source: https://github.com/orenlab/codeclone
- Issues: https://github.com/orenlab/codeclone/issues
Features
Control & governance
- Baseline governance — separates accepted legacy debt from new regressions; CI fails only on what changed
- CI-first — deterministic output, stable ordering, exit code contract, pre-commit support
- Reports — interactive HTML, JSON, Markdown, SARIF, and text from one canonical report
Detection & analysis
- Clone detection — function (CFG fingerprint), block (statement windows), and segment (report-only) clones
- Structural findings — duplicated branch families, clone guard/exit divergence, and clone-cohort drift
- Quality metrics — cyclomatic complexity, coupling (CBO), cohesion (LCOM4), dependency cycles, adaptive depth profile, dead code, health score, and overloaded-module profiling
- Adoption & API — type/docstring annotation coverage, public API surface inventory and baseline diff
- Coverage Join — fuse external Cobertura XML into the current run to surface coverage hotspots and scope gaps
- Security Surfaces — report-only inventory of security-relevant capability boundaries without vulnerability claims
Surfaces & integrations
- MCP control surface — triage-first agent and IDE interface over the same canonical pipeline; read-only by contract
- IDE & agent clients — VS Code extension, Claude Desktop bundle, and Codex plugin over the same MCP contract
Performance
- Fast — incremental caching, parallel processing, warm-run optimization
Quick Start
uv tool install codeclone
codeclone . # analyze
codeclone . --html # 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 equals --fail-on-new --no-color --quiet. When a trusted metrics
baseline is loaded, CI mode also enables --fail-on-new-metrics.
Exit codes:
| Code | Meaning |
|---|---|
0 |
Success |
2 |
Contract error — untrusted baseline, invalid config, unreadable sources in CI |
3 |
Gating failure — new clones or metric threshold exceeded |
5 |
Internal error |
Contract errors (2) take precedence over gating failures (3).
Reports
codeclone . --html
codeclone . --json
codeclone . --md
codeclone . --sarif
codeclone . --text
All formats are rendered from one canonical report payload.
Report contract: https://orenlab.github.io/codeclone/book/08-report/
MCP and Native Clients
uv tool install "codeclone[mcp]"
codeclone-mcp --transport stdio
The MCP server is read-only by contract: it never mutates source files, baselines, cache, or repository state.
| 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
[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: 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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file codeclone-2.0.2.tar.gz.
File metadata
- Download URL: codeclone-2.0.2.tar.gz
- Upload date:
- Size: 594.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d728147d98a98da10cd2e06210a0e7d9362bd56bb4dec4d2aaf320259e0c4677
|
|
| MD5 |
814e038ec3bff05bcdbfc0f5bb9e1319
|
|
| BLAKE2b-256 |
91bb01b330119024c30e4ae70ef958d73b2405efe7d8da55ebaa26954f553979
|
Provenance
The following attestation bundles were made for codeclone-2.0.2.tar.gz:
Publisher:
publish.yml on orenlab/codeclone
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
codeclone-2.0.2.tar.gz -
Subject digest:
d728147d98a98da10cd2e06210a0e7d9362bd56bb4dec4d2aaf320259e0c4677 - Sigstore transparency entry: 1573012551
- Sigstore integration time:
-
Permalink:
orenlab/codeclone@7732c87cca03ff5ac54b4eae1e8e831ffb9cd254 -
Branch / Tag:
refs/tags/v2.0.2 - Owner: https://github.com/orenlab
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@7732c87cca03ff5ac54b4eae1e8e831ffb9cd254 -
Trigger Event:
release
-
Statement type:
File details
Details for the file codeclone-2.0.2-py3-none-any.whl.
File metadata
- Download URL: codeclone-2.0.2-py3-none-any.whl
- Upload date:
- Size: 478.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6967a604a5ad9f0b8975ea6a753bd9035519f01f5b314da99e33dcbd16e79340
|
|
| MD5 |
4210b9b8eda35317ed71d9014b6616a2
|
|
| BLAKE2b-256 |
c5b17e71f3fce294e679702ab37d4b2073a203517f5b11220bb16f4edaa93335
|
Provenance
The following attestation bundles were made for codeclone-2.0.2-py3-none-any.whl:
Publisher:
publish.yml on orenlab/codeclone
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
codeclone-2.0.2-py3-none-any.whl -
Subject digest:
6967a604a5ad9f0b8975ea6a753bd9035519f01f5b314da99e33dcbd16e79340 - Sigstore transparency entry: 1573012570
- Sigstore integration time:
-
Permalink:
orenlab/codeclone@7732c87cca03ff5ac54b4eae1e8e831ffb9cd254 -
Branch / Tag:
refs/tags/v2.0.2 - Owner: https://github.com/orenlab
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@7732c87cca03ff5ac54b4eae1e8e831ffb9cd254 -
Trigger Event:
release
-
Statement type: