All articles

Point Claude at Examples and Patterns

Every codebase has its own way of doing things: how routes are structured, how errors are handled, how tests are named. Rather than describing all of that in words, just point Claude at an example that already gets it right.

When you ask for something new, reference the pattern to follow:

Add a DELETE handler for comments in app/api/comments/[id]/route.js.
Follow the same structure as @app/api/articles/[id]/route.js —
same admin guard, same error shape, same serialize() call on the response.

Claude reads the example file, absorbs the conventions, and matches them. You get code that looks like it belongs, not a generically correct version that ignores how your project actually works.

This works for more than structure. Point at examples for:

  • Style and naming. "Name the test cases like the ones in user.test.js."
  • A pattern to copy and adapt. "Build the tag filter the same way the search filter works."
  • A pattern to avoid. "The old code in legacy/ does this with callbacks; use async/await like the newer files."

The @ mention is the fast path here, because Claude reads the referenced file before it writes anything. That is far more reliable than describing the pattern from memory and hoping the description was complete.

For conventions that apply everywhere, put them in CLAUDE.md so they load automatically instead of being repeated each time. But for one-off work, a live example beats a written rule. Code is unambiguous in a way prose rarely is.

The underlying idea is simple: your codebase is the best spec you have. When a good example exists, showing it is faster and more accurate than explaining it.

Comments

Be the first to comment.