Reuse Before Create
Default assumption
The project already has something close. Find it before writing.
Search before you create
| Creating… | Search for… |
|---|---|
| New helper | Same behavior via grep (verb + noun) |
| New component | Similar UI in sibling folder |
| New API route | Adjacent routes / shared middleware |
| New type | Existing model/DTO/interface |
| New dependency | Same capability in package.json / imports |
Spend one grep pass before any new symbol.
Extend vs duplicate
| Situation | Action |
|---|---|
| Existing function needs one flag | Add optional param |
| Two call sites differ slightly | Parameterize; don't fork |
| Logic 80% same | Extract shared only if both call sites exist now |
| Logic used once | Keep inline in caller |
New file gate
Create a new file only if all are true:
- No reasonable home in existing modules
- User asked for it, or project convention requires it
- File will hold multiple related symbols or clear boundary (route, component, test)
New dependency gate
Add a package only if:
- Not in manifest already
- Stdlib can't do it in reasonable lines
- User didn't ban new deps
Report briefly
When reusing, one line is enough: "Extended formatDate in utils/date.ts" — no need to paste the old implementation.