Extend Not Duplicate

Use when about to write a new script, command, or file that is near-identical to an existing one with small variations — adds a CLI flag, parameter, or config option to the existing script instead of creating a parallel copy.

amitkot a54e460 1.3 KB Updated

File contents

Extend existing scripts; don't duplicate them

If you're about to write a new script that's >80% the same as an existing one with small differences (different env, different mode, different flag combo), extend the existing one with a CLI argument or config option instead of writing a parallel copy.

Why

Two near-identical scripts diverge over time. A bug fix lands in one and not the other. A new feature gets added inconsistently. Reviewers can't tell which is canonical. The duplicated logic compounds with every change.

How to apply

When you notice you'd be copying an existing script and changing a few values:

  • Identify what's actually different — usually a flag, env var, or config field.
  • Add that as a CLI arg (--mode prod / --target dev) or env knob to the existing script.
  • Update callers if needed.

If the differences are structural (different control flow, different inputs, different outputs), then a separate script IS appropriate — but check first whether the structural difference can be expressed as a parameter.

amitkot/claude-code-tools/tree/main/code-habits/skills/extend-not-duplicate commit a54e460359

Frequently asked questions

npx skillmds@latest add amitkot/extend-not-duplicate