Skip to content

chore: add Duplication Watch (Rule of Three) section to CLAUDE.md - #37

Merged
TrainTravel merged 1 commit into
mainfrom
chore/duplication-watch-rule
May 26, 2026
Merged

chore: add Duplication Watch (Rule of Three) section to CLAUDE.md#37
TrainTravel merged 1 commit into
mainfrom
chore/duplication-watch-rule

Conversation

@TrainTravel

Copy link
Copy Markdown
Owner

Summary

Codifies the rule that should have prevented the late language-* edge function consolidation in #36: before copying an entire file as a sibling, stop at copy #3 and parameterize first.

Why

PR #36 collapsed 4 language-specific edge functions (french-feedback, chinese-feedback, french-chat, chinese-chat) into 2 generic ones parameterized by targetLang. That consolidation should have happened at instance #3 (Chinese being added in PR #29), not at instance #4 (Japanese being added in #36).

The lateness exposed a pre-existing bug (Spanish routes to French edge function), required a rebase + codemod sweep, and added ~2 hours of work that could have been avoided.

This CLAUDE.md section is the prevention: future sessions (and subagents that auto-load CLAUDE.md) will see the rule and flag pattern-creation at copy #3.

What's in the section

  • The Rule of Three (Sandi Metz): 1st copy is fine, 2nd is tolerable, 3rd must parameterize first
  • Why late consolidations are expensive (with the Spanish-bug example as evidence)
  • A list of known parameterized patterns in this repo (extend, don't clone): language-* edge fns, Translations type, COMPASSION_PHRASES, EMOTION_SUGGESTIONS, VAGUE_EMOTIONS, GARDEN_THEMES
  • A spec/plan checklist question: "Does this create a 3rd instance of an existing pattern?"
  • Concrete examples that the rule would catch (Korean as a target = config change, not a new edge fn)

Test plan

  • CLAUDE.md still renders cleanly (no broken markdown)
  • Section sits inside ## Coding Standards, after Option Pattern, before ADHD-Friendly UX Principles

This is doc-only. No code changes, no tests.

🤖 Generated with Claude Code

Codifies the rule that surfaced during the language-* edge function
consolidation: before copying an entire file as a sibling, check
if it's the 3rd instance of a pattern. If yes, parameterize first.

Lists the known parameterized patterns in this repo so future
sessions know to extend them rather than clone:
- language-feedback / language-chat (parameterized by targetLang)
- LanguageContext.tsx Translations type
- COMPASSION_PHRASES, EMOTION_SUGGESTIONS, VAGUE_EMOTIONS,
  GARDEN_THEMES config arrays

Also adds the spec/plan checklist question: "Does this create a
3rd instance of an existing pattern?"

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@TrainTravel
TrainTravel merged commit 31932b9 into main May 26, 2026
1 check failed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant