duplicates

A command that finds functions and methods with very similar code, even when names, literal values, or comments have changed.

In plain words
What is it for?
Use it after indexing a C, C++, or Zig codebase to report near-duplicate function pairs above a chosen similarity threshold.
Why use it?
It reveals duplicated code that a line-by-line comparison may miss, helping you identify places where maintenance can be consolidated.

Command

Install

Getting it into your agent

One page per mod, every tool's command on it. A separate URL per tool would split the same page into five that compete with each other.

agentmods
npx agentmods add commands/agentis-tools/ctx/duplicates
Clone the repo
git clone --depth 1 https://github.com/agentis-tools/ctx
Per session 0 Only the description is in the session, so the agent can decide to use it. The body loads when it is invoked.
When invoked 996 The whole file, excluding the scripts and references it only reads on demand.
Security scan A 0 findings. Scan, not verified.
Origin original No closer match found in the catalogue.
Token cost

What it costs to keep this loaded

Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.

ModelPer sessionOnce invoked
Fable 5 $0.00000 $0.00996
Opus 5 $0.00000 $0.00498
Sonnet 5 $0.00000 $0.00199
Haiku 4.5 $0.00000 $0.00100

Measured 2d ago against content hash 7624ce309f0c, method: parsed. Prices are Anthropic first-party input rates as of 2026-08-30, from the pricing page.

Security

Grade A, and why

duplicates scanned grade A with 0 findings against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured 2d ago.

A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.

Nothing flagged

None of the 26 patterns this scan looks for appear in this file: no shell pipes, no recursive deletes, no credential paths, no hidden text, no instruction-override or anti-refusal phrasing, no agent-config snooping. That is not a guarantee, it is the absence of the things that are checkable.

docs/commands/duplicates.md · 119 lines

How it starts

The opening of the file, as written. The whole thing — 119 lines — stays where its author put it; the contents beside it link to each section on GitHub.

ctx duplicates

Detect structurally similar functions with MinHash near-duplicate search.

Synopsis

ctx duplicates [OPTIONS]

Description

The duplicates command compares MinHash fingerprints (built during ctx index) of every indexed function and method, including C/C++ and Zig functions and methods, and reports pairs whose normalized token shingles have a Jaccard similarity at or above the threshold.

Tokens are normalized before comparison - identifiers become ID, string and number literals become LIT, comments are dropped - so renamed variables and changed literals still match. Candidate pairs are found with LSH banding over 128-permutation MinHash signatures, then verified with the exact Jaccard similarity.

Breaking change: this replaces the old line-based detector. --threshold is a 0.0-1.0 Jaccard similarity over normalized 5-token shingles, not a percentage of matching lines; the old --similarity <PERCENT> / --min-lines <N> flags are gone. Existing indexes lack fingerprints: rebuild once with ctx index --force after upgrading.

Prerequisites

Fingerprints are computed during indexing:

ctx index

Options

Option Description Default
--threshold <F> Jaccard similarity threshold (0.0-1.0) over normalized token shingles. Values below 0.5 are clamped to 0.5 (LSH candidate detection is unreliable below that) 0.85
--min-tokens <N> Ignore functions with fewer than N normalized tokens 50
--against <REF> Only report pairs where at least one function is in a file changed relative to REF none
--fail-on-found Exit 1 when any near-duplicate pair is reported false
--json Machine-readable output (global flag) false

Exit Codes

Code Meaning
0 Success (default mode is informational, even with pairs found)
1 --fail-on-found was given and at least one pair was reported
2 Operational error (missing index, bad git ref, invalid threshold)

Read the full file on GitHub · 119 lines

Changes

What this file has done since we first saw it

Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.

  1. 2d ago First seen · 119 lines · 0 tokens per session scan A 7624ce309f0c

Subscribe to this mod's changes

duplicates is a command published in the GitHub repository agentis-tools/ctx (11 stars, last pushed 15d ago), licensed Apache-2.0. It costs nothing until one of its globs matches a file; then it loads 996 tokens. A static security scan graded it A with 0 findings. No closer match exists in the catalogue, so it is treated as the original; first seen 2026-08-30.