audit-duplication

A code-review command for finding duplicated or nearly duplicated code across Detrix's Rust crates and client languages.

In plain words
What is it for?
Run it across the whole project or a selected branch or set of uncommitted changes to compare functions, data types, and related patterns.
Why use it?
It helps locate repeated implementations that can drift apart and become harder to maintain.

Command for Claude Code

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/flashus/detrix/audit-duplication
Clone the repo
git clone --depth 1 https://github.com/flashus/detrix

Made for: Claude Code.

Per session 7 Only the description is in the session, so the agent can decide to use it. The body loads when it is invoked.
When invoked 1,405 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.00007 $0.01405
Opus 5 $0.00003 $0.00702
Sonnet 5 $0.00001 $0.00281
Haiku 4.5 $0.00001 $0.00140

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

Security

Grade A, and why

audit-duplication 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.

.claude/commands/audit-duplication.md · 170 lines

How it starts

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

You are a senior developer analyzing the Detrix codebase for cross-crate and cross-language code duplication. Your goal is to find code that is duplicated or nearly-duplicated across different crates/clients and recommend consolidation.

Scope

"$ARGUMENTS" — if empty, analyze the entire project. If a scope like branch or uncommitted is given, focus on changed crates only.

Strategy: Fingerprint → Compare → Confirm

You CANNOT read all crates at once (context limit). Instead, use a 3-phase approach:

Phase 1: Automated Pattern Search

Use Grep to search across ALL crates simultaneously for duplication signals. Run these searches in parallel — each one is cheap and covers the whole codebase:

1a. Identical/similar function signatures:

Search for common function name prefixes that appear in multiple crates:
- "fn new(" across crates (constructor patterns)
- "fn from_" / "fn to_" / "fn into_" (conversion functions)
- "fn validate" / "fn parse" / "fn format" (utility patterns)
- "fn get_" / "fn find_" / "fn list_" (data access patterns)

1b. Similar struct/enum definitions:

Search for struct/enum names that appear in multiple crates.
Look for structs with similar field sets (e.g., same fields in different DTOs).

1c. Error type duplication:

Search for error enum variants across crates.
Look for similar error messages/patterns.

1d. Conversion boilerplate:

Search for From/TryFrom/Into implementations.
Look for similar .map() / .map_err() / conversion chains.

1e. Similar imports:

Search for identical multi-line use statements that suggest shared patterns.

1f. Copy-pasted blocks:

Search for distinctive string literals, magic numbers, or unique code patterns
that appear in multiple files across different crates.

Write raw search results to .agents/audit/_duplication_raw.md.

Phase 2: Catalog Extraction (via subagents)

Launch subagents in parallel — one per "cluster" of related crates. Each subagent:

  • Reads the crate using get_symbols_overview (NOT full file reads)
  • Extracts a structured catalog of public API surface
  • Writes to .agents/audit/_catalog_<cluster>.md

Read the full file on GitHub · 170 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 · 170 lines · 7 tokens per session scan A d3dd52fed450

Subscribe to this mod's changes

audit-duplication is a command published in the GitHub repository flashus/detrix (23 stars, last pushed 9d ago), licensed MIT. It adds 7 tokens to every session and 1,405 once invoked, about $0.0000 per session on Opus 5. 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.