Skip to main content

dry-lint: one concept, one implementation

PyPI CI Duplicates kept out Python 3.11+ TypeScript Apache 2.0 Documentation

Why dry-lint · First-run tutorial · How CI runs it · Documentation · Related tools

Coding agents rarely copy and paste. They write new code for a job the codebase already does: a second truncate, another pagination loop, a fresh Mongo query helper, each slightly different. Copy-paste detectors (pylint's duplicate-code, jscpd) look for repeated lines, so they miss this. Every rewrite is also a chance to drift: one version rounds, the other truncates, and callers get different answers to the same question.

Set it up with your coding agent. Give Claude Code, Codex, Cursor or any coding agent in your repository this one prompt:

Set up dry-lint in this repository. Fetch https://dry-lint.readthedocs.io/en/latest/agent-setup.md and follow it.

The agent reads how your repository works (default branch, action pinning, pull request template, existing secrets), writes the settings, accepts today's duplicates in a baseline, adds the workflows and hooks, proves the check catches a copied function, and opens a pull request. Repository settings and secrets stay with you: it stops and asks you to add a TypeSafe API key secret if there is none, to make the dry-lint check required, and to add a token for the weekly cleanup pull request. To do it by hand, follow the first-run tutorial; how CI runs dry-lint explains the moving parts.

dry-lint finds functions in a pull request that look like they re-implement something that already exists. A judge decides whether each pair really is one concept, and the result goes back as PR annotations and one comment (see one):

src/widgets/caption.py:1: preview_caption_text looks like src/text.py::shorten_text (drifted)
    judge 0.91; the two already behave differently; call the existing function;
    similarity 0.71; if they are different concepts, add
    `# dry-lint: distinct-from src/text.py::shorten_text`;
    if they are one concept copied on purpose, add a [[patterns]] entry with a reason

You bring your own keys. dry-lint never provides API keys, models or judge execution: judges run on the credentials your repository passes in, at your cost, and without any it only lists look-alikes (design).

Duplicate functions dry-lint has kept out of codebases

Quick start

Python, TypeScript and TSX work out of the box. TypeScript repositories need no Python project, bun install, Node or build step: dry-lint installs its own tools and parses source without executing your code (TypeScript and Bun covers monorepos).

Try it locally, without an API key

Install uv, open a terminal in your Git repository, and run:

uvx --no-config --python 3.13 dry-lint scan --judge none --limit 30

uv downloads Python and runs dry-lint in its own environment, so nothing is added to your project. This lists look-alikes without calling a model or failing on findings. To inspect just your branch, replace scan --judge none --limit 30 with check --judge none --base origin/main (use your default branch's name).

For a permanent dry-lint command, then open a new terminal:

uv tool install --no-config --python 3.13 dry-lint
uv tool update-shell

Add it to GitHub Actions

Save this as .github/workflows/dry-lint.yml. It works without a secret. For judged findings, store your TypeSafe API key as a repository or organization secret and pass it to typesafe-api-key:. The secret can have any name; this example calls it TYPESAFE_AI_API_KEY (check gh secret list and your organization's secrets first).

name: dry-lint
on: [pull_request]
permissions:
  contents: read
  pull-requests: write
concurrency:
  group: dry-lint-${{ github.event.pull_request.number }}
  cancel-in-progress: true
jobs:
  dry-lint:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v7
        with:
          ref: ${{ github.event.pull_request.head.sha || github.sha }}
          fetch-depth: 1
      - uses: gigaverse-app/dry-lint@v1
        with:
          typesafe-api-key: ${{ secrets.TYPESAFE_AI_API_KEY }}

The action installs its own Python and dependencies; your project's Python version, uv configuration and virtual environment do not change, and no setup-python, pip install or build step is needed. It annotates the changed functions, keeps one sticky PR comment up to date and caches verdicts between runs. The comment links both functions at the analyzed commit, shows the review workload, and folds evidence and pair-specific suppression instructions under each summary. A clean pull request gets a green sticky with what was checked (comment-on-clean: "false" to opt out), and every sticky keeps a running account of what each push cost and each finding and its current outcome (the ledger).

A reported duplicate fails the check at the preset's threshold (98% of them are real duplicates with jev+opus); fail-at raises or lowers it, and the dry-lint: override label lets one through. That precision is for people. A coding agent can check findings itself, so for agents a cheap judge at a lower threshold catches more for less (who reads the findings). Pull requests from forks get no secrets, so the default mode: auto runs dry-lint as two jobs for them: detect on the pull request, and judge in a workflow_run job that keeps the key away from pull request code (design). For default-branch runs, rechecks when override labels change, and a fork job named dry-lint detect so it can never satisfy a required dry-lint check, use the extended workflow; the action guide lists every option.

pre-commit

default_install_hook_types: [pre-commit, prepare-commit-msg]
repos:
  - repo: https://github.com/gigaverse-app/dry-lint
    rev: v1
    hooks:
      - id: dry-lint
      - id: dry-lint-trailers  # optional: records absence/dismissal without claiming removal

The hook inherits repository settings. Use preset = "balanced" for functions and keep model candidates routed to agent ownership review. Set ANTHROPIC_API_KEY in the environment or an untracked .env. The hook only needs a key when there are pairs to judge. With a baseline, use args: [--baseline, .dry-lint/baseline.json, --require-complete].

To upgrade an existing adoption, change the preset and run dry-lint baseline-migrate; this preserves all original allowances. Refresh cached hooks with pre-commit clean && pre-commit install --install-hooks. See defaults, migration and regression evidence.

The optional trailers hook records Dry-Lint-Not-Reported or Dry-Lint-Dismissed. A finding disappearing from a scan does not establish that a duplicate was removed. Cleanup credit requires evidence from the accepted baseline.

Commands

Command Does
check [--base REF | --staged] detect, judge and report the functions a change touched (base: origin/HEAD)
scan [--limit N] [--refresh] [--repo OWNER/NAME=PATH ...] the repository's backlog, or cross-repository pairs from a combined workspace
sweep [--init | --update] audit the configured repository; explicitly initialize or shrink its accepted backlog and README progress
config which judges, thresholds and budget would run, and what they cost
explain A B why a pair is, or is not, reported
detect --out candidates.json CI job 1: propose pairs; no judge, no secrets, no store
judge --candidates candidates.json CI job 2: judge them, store the verdicts, report
report --from report.json --format F render a report as text, github, markdown, json, sarif or check-run
bench --gold gold.jsonl [--comparer] measure the judge, or the comparer, on a gold set
bench --replay N [--preset P] [--fail-at X] [--label K] what check would have done on each of the last N commits of the default branch; with --label, what it would have caught, missed and blocked wrongly

--report report.json and --output comment.md write the report and the PR comment from any command that judges. Without a judge, dry-lint lists the candidate pairs and never fails. With TYPESAFE_AI_API_KEY set, Jev judges them; to use another judge, pass --judge command --judge-command "your-llm-cli" (judges).

To Read
Fully adopt hooks, PR/README stickies and a shrinking backlog Adoption playbook
Set it up with an agent the one prompt above; the agent follows skills/dry-lint/SKILL.md
See the PR comment before installing Example report
Put judged findings on pull requests GitHub Action setup
Add structural matching The optional Dryer comparer (compared on gigaverse-backend)
Find copies across related repositories Workspace scans and shared ownership
Avoid cloning peer repositories in CI Versioned function indexes
Audit existing duplication, shrink its baseline and show cleanup in your README Repository sweeps and ratchets

How it works

dry-lint is a fixed core (the pipeline, the file formats, the verdict store's rules and the reports) with four plugin slots: how functions are found, how they are compared, how a pair is judged, and where verdicts are kept (design, plugins).

  1. Detector (local, no model, about 4.5 s on 10,000 functions). It finds the functions the diff touched. The comparer proposes each one's nearest look-alikes in other files; the built-in one is a TF-IDF fingerprint of what a function does: the names it calls, the attributes it touches, the words in its identifiers, its loops, try blocks and awaits. One shared policy consumes language-adapter facts: Python special methods, recognized forwarding wrappers, a function that calls the other (resolved within the file), declared patterns and inline distinct-from. Inheritance alone does not exclude repeated logic.

  2. Judge (separate and pluggable). Jev answers three typed questions per pair in about 0.3 s:

    • Is it one concept?
    • Do the two already behave differently?
    • Which side should own the single implementation?

    Any LLM CLI, or any program, can be the judge instead, and a second judge can take the scores the first is least sure about.

  3. Verdict store (a cache, not a reviewed file). Each verdict is kept per pair with a structure hash of each function, which comments and formatting do not change. Python also normalizes local renames; TypeScript conservatively re-judges them to preserve binding semantics. Most cosmetic pushes cost zero judge calls.

Research on profiles, judging budgets and discovery across repeated runs is in Discovery over time and the four-cent discovery trial.

When it is right not to merge them

Some look-alikes are deliberate. Silence them where the decision belongs:

  • Inline: put # dry-lint: distinct-from src/text.py::shorten_text in the new function. The reason sits next to the code it explains, and moves or disappears with it.
  • A whole function: put # dry-lint: ignore in it (generated code, a deliberate copy). It is left out of every pair, on either side.
  • Families, and copies kept on purpose: declare a pattern in .dry-lint.toml, for deliberate per-resource instances or for one concept a project keeps in two places (say, a module that vendors a helper so it imports nothing):
# .dry-lint.toml
exclude = ["*/tests/*", "tests/*", "*/migrations/*"]

[[patterns]]
members = "src/*/api/*_api.py::create_router"
reason = "one router per resource"

[[patterns]]
members = ["pkg/funcutils.py::_indent", "pkg/strutils.py::indent"]
reason = "funcutils vendors strutils.indent so it imports nothing"

A pair matches a pattern when both of its functions do: each side's path::Qualified.name is compared with fnmatch against members, one glob or a list. Keep globs narrow, since a broad one silences real duplicates too, and check each with dry-lint explain A B, which prints rule: declared pattern: <reason> for a match. Do not put copies kept on purpose in the baseline instead: a baseline entry accepts both functions exactly as they are, so the day someone fixes a bug in both copies, the changed pair fails as new debt. Machine "not a duplicate" verdicts stay in the store and do not need to be checked in.

Measured

On 600 gigaverse-ai pull requests, against a 250-pair gold set labelled blind by three vendors' models (docs/benchmark.md):

Changed functions per commit median 1, p90 13
Judge calls per PR (uncached) 2.5
Findings per PR at the default threshold about 0.2
Jev reuse-v2: ranking quality AUC 0.97
preset jev+opus, failing at 0.55, within $0.04 a pull request 98% precision, 85% recall; about $0.005 per pull request on average
preset jev+sonnet, failing at 0.7 97% precision, 84% recall; about $0.0035 per pull request
preset jev+codex (ChatGPT subscription), failing at 0.7 96% precision, 85% recall; no per-call cost
preset jev, failing at 0.8 94% precision, 73% recall; 15% of pull requests fail
Known duplicates found and scored ≥ 0.8 11 of 13
Verdict store for the whole repository about 1,900 pairs, 0.75 MB

The spending ledger, checked against a model

The campaign ledger that admits and settles paid judging is also a Quint model. CI replays generated histories against the real ledger and requires every deliberately broken ledger to be caught (campaign contract). The block below is the latest complete run, checked by pytest-quint-connect on every change that runs the contract.

What pytest-quint-connect's contracts caught in gigaverse-app/dry-lint's pull requests

Quint contracts: 1 contract passed · 20 histories · 4/4 mutants caught

✅ 1 contract · 25/25 cases · 4/4 mutants caught · 20 histories
Contract Cases passed Mutants caught
✅ campaign campaign/test_campaign_contract.py::test_campaign
20 histories (4 witnesses, 16 samples, seed 11) · every action covered · Quint 0.33.1
25/25 4/4
🐞 1 real bug found by this contract
Contract Bug Fixed in Regression test
campaign settle() accepted an already settled reservation: an answered attempt could turn failed and protected exploration credit was refunded again
found by witness secondSettleIsRefusedTest · mutant double-settle reintroduces it: 13 of 20 histories diverge
gigaverse-app/dry-lint#157 tests/test_discovery.py
::test_a_reservation_settles_exactly_once
🧪 4 mutants (planted fake bugs), all caught
Contract Mutant What it breaks Caught by At
campaign double-settle settle() accepts an already settled reservation and refunds its credit again
reintroduces a real bug this contract found
witness-secondSettleIsRefusedTest
samples: 12/16 diverge
state 4, after settle(idx=0, actual=0, success=False)
campaign credit-per-call every advance() mints exploration credit, not only a new revision's first witness-creditMintedOncePerRevisionTest
samples: 13/16 diverge
state 2, after advance()
campaign residual-skips-pass residual reserve() does not wait for the revision's protected attempts to be answered witness-residualWaitsForTheProtectedPassTest
samples: 2/16 diverge
state 2, after reserve(kind='residual', cand='c2', cost=1)
campaign no-dedupe reserve() admits the same pair twice on one revision witness-residualWaitsForTheProtectedPassTest
samples: 2/16 diverge
state 5, after reserve(kind='residual', cand='c2', cost=1)
What campaign says

Actions, and the code each one drives:

  • init: a new CampaignStore on an empty ledger
  • push: a new CampaignStore for the next immutable revision on the same ledger
  • advance: CampaignStore.advance
  • reserve: CampaignStore.reserve
  • reserveFamily: CampaignStore.reserve_family
  • settle: CampaignStore.settle
  • inspect: read only

Invariant withinBudget, checked while sampling histories.

Witnesses, scenarios replayed exactly as written: creditMintedOncePerRevisionTest, secondSettleIsRefusedTest, residualWaitsForTheProtectedPassTest, familyNeedsAnEnteredRevisionTest.

Bounds: seed 11 · max_samples 300 · max_steps 10 · n_traces 16.

Witness creditMintedOncePerRevisionTest, step by step: the observation the model starts from, then what it expects each action to change.

State Action Model expects
0 init() { attempts: [], credit: 0, outcome: NoOutcome, rev: 0, revisions: 0 }
1 advance() credit: 0 → 2
revisions: 0 → 1
2 advance() unchanged
3 push() rev: 0 → 1
4 advance() credit: 2 → 4
revisions: 1 → 2
5 inspect() unchanged

Generated by pytest-quint-connect from contract receipts; what a passing run proves.

Settings

Settings live in .dry-lint.toml at the repository root, as top-level keys with tables such as [budget] and [[patterns]]. The same keys also work under [tool.dry-lint] in pyproject.toml ([tool.dry-lint.budget], [[tool.dry-lint.patterns]]); when both files exist, .dry-lint.toml wins. Judges and thresholds come from the preset (docs/judges.md); anything set here wins over it. dry-lint config prints the result, including how many source files the scope covers:

Setting Default
include / exclude everything / tests, migrations, scripts fnmatch over tracked paths; setting exclude replaces the defaults
patterns none [[patterns]] entries with members (a glob or a list) and a reason: deliberate look-alikes
neighbours 3 candidates per changed function
preset "auto" balanced with an Anthropic key; balanced-subscription with a Claude token; jev for TypeSafe-only compatibility, otherwise none (detection only). Adopters pin balanced; models require agent review
drop_below / report_at / fail_at from the preset balanced uses 0.5 / 0.5 / 0.5; confidence in a named shared operation, not lines saved
drift_at 0.8 a duplicate whose behaves_differently reaches this is drifted
budget { usd = 0.04, subscription_calls = 20 } most judging spends on a pull request across all its pushes, at list price, subscriptions included (--budget-usd); and calls per run to subscription judges
prices built-in table USD per million input and output tokens, by model
reopen_margin 0.05 for a comparer that permits similarity reuse (no built-in one does), how much closer a "separate" pair must get before it is judged again
max_findings 10 rows in the PR comment
extractors ["python", "typescript"] .py, .ts, .tsx, .mts, .cts
comparer "tfidf" options min_similarity (0.5), min_similarity_small (0.3) under small_function_lines (6)
judge / escalate from the preset name your own judge to run it alone, or escalate = "none" to turn the second judge off
store "dir" .git/dry-lint/verdicts/, or { use = "s3", uri = "s3://bucket/prefix" }

A plugin slot takes a name, or a table with use and the plugin's options: comparer = { use = "tfidf", min_similarity = 0.45 }.

The counter

Legacy global totals include disappearance-based claims and are historical, not verified removal counts. Current versions report disappearance separately and send zero removal credit for it. Baseline reductions remain visible in the PR and repository's debt progress. Old positive weak labels inferred from disappearance must not train judges.

When a pull request merges, the action's run on the default branch sends its counts to a Cloudflare Worker: duplicates kept out (how many had drifted, how many were rewrites, and their lines), caught and dismissed, pushes, functions checked, look-alikes compared, verdicts reused, judgments, judging spend and the dry-lint version. No code, names, paths or people are sent. The repository is pseudonymous: it is sent as its counter key, the SHA-256 of its numeric GitHub id, which ties its pull requests together but which its name does not lead to; a private repository's id is visible only to people who can see the repository. Each pull request is counted once. Opt out with share-totals: "false".

Separately, a repository can opt in to dry-lint's benchmark with share-goldens: "true": each merged pull request's settled pairs (pairs dismissed after being reported) are kept as pointers in a dry-lint-goldens artifact in its own repository, and collected only from public repositories registered in docs/goldens/adopters.toml. See sharing goldens.

A repository whose audit keeps a README block gets its sign there automatically, beside the old duplicates it has cleaned up and still has. To show it anywhere else, take its counter key from the log of a dry-lint run on your default branch (dry-lint: this repository's counter key is ...). name only labels the sign; the counter never looks a name up:

<picture>
  <source media="(prefers-color-scheme: dark)" srcset="https://dry-lint-counter.gigaverse-oss.workers.dev/v1/sign.svg?theme=dark&key=KEY&name=OWNER/NAME">
  <img alt="Duplicates dry-lint kept out of OWNER/NAME" src="https://dry-lint-counter.gigaverse-oss.workers.dev/v1/sign.svg?key=KEY&name=OWNER/NAME" width="100%">
</picture>

or a badge, with metric=kept-out, drifted, lines, pulls, functions or repositories:

![duplicates kept out](https://img.shields.io/endpoint?url=https%3A%2F%2Fdry-lint-counter.gigaverse-oss.workers.dev%2Fv1%2Fbadge%3Fkey%3DKEY%26metric%3Dkept-out)

Lint

Lint, the dry-lint mascot: a purple ball of dryer lint holding a mint-green hair dryer

Lint is what is left behind when you dry things. It carries a hair dryer for blowing duplicated code away. uv run --with pillow python scripts/make_assets.py rebuilds the avatar, the mark, the banners and the README hero from docs/assets/lint.png.


License

Apache 2.0. See CONTRIBUTING.md to work on dry-lint itself.

Metadata

Release files for dry-lint 1.9.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for dry-lint 1.9.2
File Size Uploaded Provenance Actions
dry_lint-1.9.2.tar.gz 26.5 MB With provenance Details for dry_lint-1.9.2.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for dry-lint 1.9.2
File Interpreter ABI Platform Actions
dry_lint-1.9.2-py3-none-any.whl Python 3 none any Details for dry_lint-1.9.2-py3-none-any.whl

Total release size: 26.7 MB

Release files / dry_lint-1.9.2.tar.gz

Download URL dry_lint-1.9.2.tar.gz
Size 26.5 MB
Tags Source
SHA-256 checksum
How to use checksums
6d80d769ff274d1eae1e45bba047212f07e5f75fd13c5920eac3a7bca5112905
BLAKE2b-256 checksum
How to use checksums
86844385ff97d6deb68a25e4514e54c52662c9e22801678289a9ebc0630f49e5
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 9, 2026.

Transparency log

Release files / dry_lint-1.9.2-py3-none-any.whl

Download URL dry_lint-1.9.2-py3-none-any.whl
Size 239.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
8425d20ab28fe68a62e4817f5e0fb3cd9ac55b4b866c630899aa10e5f8e61451
BLAKE2b-256 checksum
How to use checksums
371787476ef5ee8e6b70e9f4d5d4c5402d9fc44b948c1e8b0a5c7dc2e051b320
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 9, 2026.

Transparency log

Security for dry-lint 1.9.2

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for dry_lint-1.9.2.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 9, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

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