no-duplicate-logic

no-duplicate-logic is a skill for Claude Code from Fergius-Engineering/instincts. It costs 32 tokens per session (431 once invoked), scanned A, original, MIT.

A coding rule for avoiding repeated logic inside an existing function. It requires reading the whole function before adding a new case, check, branch, or output.

In plain words
What is it for?
Use it when modifying handlers, switches, validators, or other functions that already process the same kind of record, identifier, or result.
Why use it?
The behavior being added may already exist elsewhere in the same function, causing duplicate results when a second block is inserted. The rule helps extend the existing code instead.

Skill for Claude Code

Written for Claude Code: shipped in a Claude Code plugin.

Part of the instincts plugin — 20 skills, 2 hooks shipped together

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 skills/fergius-engineering/instincts/no-duplicate-logic
Any agent
npx skills add Fergius-Engineering/instincts --skill no-duplicate-logic
Clone the repo
git clone --depth 1 https://github.com/Fergius-Engineering/instincts

Made for: Claude Code.

Or install instincts, the plugin that ships this one along with the rest of its 20 skills, 2 hooks.

Wrote this? Show the measurements

A badge with what this costs and how it scanned, read live from this page, so it follows the numbers instead of freezing them. Markdown for a README, HTML for a documentation site or a project page.

agentmods badge for no-duplicate-logic

README.md
[![agentmods](https://agentmods.dev/badge/skills/fergius-engineering/instincts/no-duplicate-logic.svg)](https://agentmods.dev/skills/fergius-engineering/instincts/no-duplicate-logic)
Your own site
<a href="https://agentmods.dev/skills/fergius-engineering/instincts/no-duplicate-logic"><img src="https://agentmods.dev/badge/skills/fergius-engineering/instincts/no-duplicate-logic.svg" alt="Measured on agentmods" height="20"></a>
Per session 32 Skills are progressive disclosure: only the name and description are preloaded; the body loads when the skill is used.
When invoked 431 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.1 $0.00032 $0.00431
Opus 5 $0.00016 $0.00216
Sonnet 5 $0.00006 $0.00086
Haiku 4.5 $0.00003 $0.00043

Measured 5d ago against content hash 546aa33f223c, method: parsed. Prices are Anthropic first-party input rates as of 2026-09-06, from the pricing page.

Security

Grade A, and why

no-duplicate-logic 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 5d 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.

skills/no-duplicate-logic/SKILL.md · 31 lines

What it actually says

The rule

Before you add logic to a function that already exists, read the whole function. The case you're about to write is often already handled a few lines down. A second block that produces the same result doesn't replace the first — both run, and the output silently doubles. The fix you needed was usually three lines added to the block that's already there, not a new block beside it.

This is not the same as fixing in the shared layer. That's about where a bug lives across callers. This is narrower: don't paste a parallel branch inside one function without reading what's already in it.

Fires when

Adding a case, branch, check, or emit to an existing function, handler, switch, or validation pass — especially when you jumped straight to the insertion point without reading the rest of the function.

How to apply

Before adding logic that emits a result keyed by some id or name, search the whole function for that id or that result. If a block already handles it, extend that block instead of adding a new one. Read the function top to bottom before you insert anything into it.

Worked example

A validation function already emits a "bad-name" issue for a record. You add a new block to emit "bad-name" without noticing the existing one a screen above. Now every bad-named record produces two identical issues, and a count somewhere is quietly off by a factor of two. The real change was three lines inside the block that was already there. Reading the function before inserting would have shown it.

Red flags

Thought Reality
"I'll just add the block here" The block may already exist above; read first.
"It's a new case" Check it's actually new before you write it.
"The function's long, I'll jump to the spot" Jumping to the spot is how you duplicate the spot.
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. 5d ago First seen · 31 lines · 32 tokens per session scan A 546aa33f223c

Subscribe to this mod's changes

no-duplicate-logic is a skill published in the GitHub repository Fergius-Engineering/instincts (2 stars, last pushed 11d ago), licensed MIT. It adds 32 tokens to every session and 431 once invoked, about $0.0002 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-31.

Related

Other skills, from other repositories

rulesync

Generates and syncs AI rule configuration files (.cursorrules, CLAUDE.md, copilot-instructions.md) across 20+ coding tools from a single source. Use when syncing AI rules, running rulesync commands, importing or generating rule files, or managing shared AI coding configurations.

dyoshikawa/rulesync · 64 tokens

autoprompt

Explicit-only useful-first orchestration. Invoke /autoprompt to turn a mission into one executable roadmap, build dependency-safe lanes, and verify the result with independent reviewers. Never infer invocation from ordinary requests. Never resume from leftover artifacts without an explicit resume instruction.

Spielewoy/autoprompt-skill · 56 tokens

establishing-project-context

Use when the user asks to establish shared project language, or project work exposes a conflicting, renamed, or deprecated domain term that needs active semantic modeling. Routine small tasks stay on the fast path.

GanyuanRan/Aegis · 45 tokens

gitnexus

将 GitNexus 作为受控可选代码智能能力接入,用于 brownfield MCP 查询、影响面分析、 detectchanges、多仓分析和更深代码图谱证据。输出必须回落到 /team- 主链和 artifacts。.

hashgraph-online/awesome-codex-plugins · 58 tokens

loop

Full execution protocol for MODE: LOOP — the compound-engineering loop: brainstorm → plan → build → review → improve, iterating under defense-in-depth stop conditions with generator/critic separation, durable resumable state, and mandatory compounding learning capture. Loaded on demand by the architect when the loop…

ZaxbyHub/opencode-swarm · 72 tokens

restore-internals-seams-in-finally-blocks-after-each-test

When delegating a task affected by this skill, include.

ZaxbyHub/opencode-swarm · 26 tokens