CC-301a · Module 1

Code Snippet Patterns

3 min read

Telling Claude "use named exports" is less effective than showing Claude a named export. This is the show-versus-tell principle, and it applies to every rule in your CLAUDE.md that governs code style, patterns, or conventions. Claude is a pattern-matching engine. Give it a pattern to match.

The implementation is straightforward. After any rule that governs code output, include a short code snippet — three to eight lines — that demonstrates the correct pattern. Not a full file. Not a comprehensive example. Just enough code to show the shape of what you want. "Always use the repository pattern for data access" followed by a five-line snippet of a repository method is ten times more effective than the text instruction alone.

There are three scenarios where snippets are essential rather than merely helpful. First: custom DSLs or framework patterns that Claude has not seen in training data. If your team uses a home-grown state management pattern, Claude cannot infer it from a text description. Show it. Second: naming conventions that differ from community norms. If your React components use PascalCase files but your hooks use camelCase files, show both patterns side by side. Third: import ordering or file structure rules. "Imports should be ordered: React, external libraries, internal modules, styles" is ambiguous. A four-line import block demonstrating the order is not.

The token cost of snippets is minimal — a five-line code block is roughly 30 tokens. The accuracy improvement is substantial. This is one of the highest-ROI investments you can make in your CLAUDE.md.