hermes

Reduce code duplication

Finds duplicated logic, separates true duplication from code that only looks alike, and merges only true duplicates behind one well-named function. Use when one fix keeps landing in many places.

context

Duplication hurts when the copies must change together and someone forgets one of them. Code that only looks alike but changes for different reasons is not duplication. Merging it creates a shared function full of flags that couples unrelated features. The wrong abstraction costs more than the copies did.

task

Reduce duplication in .

  1. Find candidate duplicates: repeated blocks, near-identical functions, parallel switch statements, the same validation or formatting written several times.
  2. For each group, decide whether it is:
  • true duplication: the copies represent the same rule and must change together. Look for evidence: commits that changed several copies at once, or a bug fixed in one copy and not the others;
  • coincidental: the copies look alike today but belong to different concepts that will change independently.
  1. Merge only true duplication with at least three copies, or two copies that have already drifted and caused a bug. Give the shared code a name that states the rule it represents, and keep its parameters few. If it needs a boolean flag to serve its callers, it is the wrong abstraction.
  2. Where copies have already drifted, decide which behaviour is correct. If you cannot tell, do not merge; report the difference as a question.
  3. Run the tests after each merge.
constraints
  • Leave coincidental duplication alone and say why.
  • No behaviour changes. If merging would change one copy's behaviour, stop and report it.
  • Prefer a plain function over a class hierarchy, generic or framework hook.
  • Do only what was asked. If you notice something else worth changing, mention it in one line at the end instead of changing it.
  • Keep the change as small as it can be while still being correct.
  • Before saying the work is done, run the check that proves it (tests, build, type check or the command the user gave) and report the real result.
  • If you could not run a check, say so plainly and say which one.
output format

Duplicates

A table: # | Where (path:line for each copy) | True or coincidental | Evidence | Action.

Changes

The diff for the merges you made.

Verification

Test commands and results. List any drifted copies you left for a decision.

1 required value still a placeholder; the assistant will ask for it.

details

kind
Prompt: a task you run by name to get one finished thing back
domain
Software engineering
category
Refactoring
level
Intermediate
made for
Software engineer, Tech lead / staff engineer
needs
repo-read, file-write, shell
risk
runs-commands
version
v1.0.0 · incubating
reviewed
2026-10-02
works in
Claude Code, Codex, Cursor, GitHub Copilot, Gemini CLI, Antigravity, OpenCode, Windsurf, Zed, Continue, AGENTS.md

Edit on GitHubReport a problem

use in

Hodios CLI
npx @hermes-hq/hodios install reduce-duplication --target claude-code
Agent Skills
npx skills add hermes-hq/hodios-dist --skill reduce-duplication -a claude-code
Add the Hodios marketplace (once)
claude plugin marketplace add hermes-hq/hodios-dist
Install the software-engineering plugin
claude plugin install hodios-software-engineering@hodios

The plugin brings every entry in this domain at once.

more in refactoring

All of Refactoring
PromptRefactoring

Extract a module

Moves one responsibility out of a large file or class into its own module in small, test-verified steps, without changing behaviour or the public API. Use when a file does too many things.

extract-module
PromptRefactoring

Improve naming in code

Proposes clearer names for variables, functions, types and modules, explains each rename and applies them without changing behaviour. Use when code reads poorly because of its names.

improve-naming
PromptRefactoring

Plan a large refactor in safe steps

Turns a large refactor into small, independently shippable steps that keep the build green, each with a rollback, using patterns like expand-contract. Use for refactors too big for one PR.

plan-large-refactor
PromptRefactoring

Remove dead code safely

Finds unused code, flags, endpoints, jobs and dependencies, proves each dead with static and runtime evidence, and removes it or stages a reversible retirement. Use to shrink a codebase.

remove-dead-code
PromptRefactoring

Simplify a complex function

Rewrites a hard-to-follow function into a clearer one with identical behaviour, using guard clauses, named steps and simpler conditions, verified by tests. Use on long or deeply nested code.

simplify-function
PromptRefactoring

Plan splitting a large module

Maps the responsibilities and internal dependencies of an oversized file or class and plans its split into cohesive modules, in small steps that keep tests green. Use before breaking up a god class.

split-large-module