Remove Duplication
Workflow for identifying and eliminating duplicated code
CLAUDE.md
When removing duplicated code:
- Identify the duplicated code blocks. Are they truly identical, or just similar?
- If identical: extract the common code into a shared function or module.
- If similar: identify the differences. Parameterize the shared function to handle the variations.
- Replace each duplicate with a call to the shared function.
- Run the tests after each replacement to verify behavior is preserved.
- Don’t force it. If the code is similar but serves different purposes, duplication is acceptable — premature abstraction is worse than repetition.
Copy this workflow into your CLAUDE.md or agent config file so your agent follows this process automatically.