CLAUDE.md Best Practices — Do’s and Don’ts

You’ve written a CLAUDE.md. Claude is reading it. But you’re not getting the results you expected — Claude is ignoring some rules, producing inconsistent output, or the file has grown into something unwieldy that’s hard to maintain.

Most CLAUDE.md problems come down to a small set of recurring mistakes. This article names them, shows you exactly what the wrong version looks like versus the right version, and gives you a checklist to validate your own file.

📋 TL;DR
– The biggest mistake: writing vague rules (“write clean code”) instead of specific ones (“use 2-space indentation, no semicolons”)
– Don’t make your CLAUDE.md a placeholder — real project details only, no generic filler
– Keep it focused on what changes Claude’s behavior, not on documenting things Claude already knows
– Update it when your project evolves — a stale CLAUDE.md is worse than a short one
– The file has a sweet spot for length — too short is underused, too long is unreadable

This is part of our complete CLAUDE.md — The Complete Beginner’s Guide (2026).


The Do’s

✅ DO: Write Specific, Testable Rules

Every rule in your CLAUDE.md should be specific enough to verify. You should be able to look at Claude’s output and check whether the rule was followed.

❌ Don’t write this:


- Write clean, readable code
- Use good variable names
- Handle errors properly

✅ Write this instead:


- Use 2-space indentation — never 4 spaces or tabs
- Variable names must describe what they contain: `userEmailAddress` not `email` not `e`
- All async functions must have a try/catch block — caught errors must be logged or re-thrown

The second version is verifiable. You can look at Claude’s output and immediately see if the rule was followed. The first version is an aspiration, not an instruction.


✅ DO: Include Real Project Details

Your CLAUDE.md should describe your actual project, not a hypothetical one. Replace every placeholder.

❌ Don’t leave placeholders:


## Tech Stack
- Framework: [your framework here]
- Database: [your database here]
- Testing: [your testing setup]

✅ Fill in actual details:


## Tech Stack
- Framework: Next.js 14, App Router
- Database: PostgreSQL 15 via Prisma ORM
- Testing: Vitest + React Testing Library

Generic placeholders are useless. They don’t help Claude and they just add noise to the file.


✅ DO: Use Code Examples for Complex Patterns

When a rule describes a pattern that’s easier to show than to describe, show it.

❌ Description alone for a complex pattern:


- Service functions should use the result pattern for error handling

✅ Description plus example:


- Service functions use the result pattern — return `{ data, error }` where one is always null:

async function getUser(id: string): Promise> {

try {

const user = await db.user.findUnique({ where: { id } })

return { data: user, error: null }

} catch (error) {

return { data: null, error: ‘Database error’ }

}

}


Claude anchors to code examples more reliably than prose descriptions of patterns.


✅ DO: Explicitly State What You’ve Decided Against

Some of the most valuable lines in a CLAUDE.md are “we don’t use X.” These prevent Claude from suggesting technically valid alternatives that you’ve already ruled out.


## Decisions Made
- **No Redux** — we use Zustand. If you're about to suggest Redux, use Zustand instead.
- **No tRPC** — we use REST API routes. Our API is consumed by a mobile app that isn't TypeScript.
- **No inline SQL** — all database access goes through Prisma ORM.
- **No CSS Modules** — Tailwind utility classes only. We removed CSS Modules in our last refactor.

This section alone can save dozens of redirections per week in an active project.


✅ DO: Separate Global from Project-Specific Rules

Personal habits and preferences go in your global ~/CLAUDE.md. Project-specific rules go in the project’s CLAUDE.md. Mixing them causes confusion in unrelated projects.

Global (in ~/CLAUDE.md):


- Always explain what you're going to do before writing code
- Ask when there are multiple valid approaches
- Keep responses concise

Project-level (in /your-project/CLAUDE.md):


- TypeScript strict mode — no `any`
- Components use named exports only
- Tests required for all utility functions

For the full breakdown of this distinction, see CLAUDE.md Global vs Project-Level — What’s the Difference?.


✅ DO: Keep It Structured with Clear Headings

Claude reads your entire CLAUDE.md as context. A well-structured file with clear H2 and H3 headings makes it easier to navigate and harder to overlook important sections.


## Tech Stack
## Coding Standards
### Formatting
### Naming Conventions
### TypeScript Rules
## Folder Structure
## Commands
## Architecture Notes
## Constraints

Flat files with no headings work, but structured files produce more consistent results.


✅ DO: Include a “Never Touch” List

If there are files, folders, or categories of changes Claude should never make without explicit instruction, list them. This protects frozen code, auto-generated files, and migration histories.


## Files Claude Must Never Modify
- `/src/legacy/` — frozen code kept for historical reference
- `/database/migrations/` — never edit existing migration files
- `/public/static/` — assets managed by a separate process
- `package-lock.json` — don't suggest changes that require a lockfile update without flagging it

The Don’ts

❌ DON’T: Write Rules Claude Already Follows by Default

Adding rules Claude would follow anyway just adds noise and makes your file longer without adding value.

Unnecessary rules:


- Write code that compiles and runs
- Don't introduce syntax errors
- Use proper indentation
- Follow the language's basic syntax rules

Claude already does all of these. Every line in your CLAUDE.md should change or constrain Claude’s behavior in some way. If it wouldn’t change anything, cut it.


❌ DON’T: Use Contradictory Rules

Contradictory rules create unpredictable behavior. Claude will pick one and ignore the other, but you won’t know which.

❌ Contradictory:


- Keep functions short (under 20 lines)
- Functions should be comprehensive and handle all edge cases without splitting

Those two rules directly conflict. Claude will follow whichever one applies to the current context, producing inconsistent results. Pick one and commit to it.


❌ DON’T: Include Sensitive Information

This is a safety rule, not just a best practice.

Never include in your CLAUDE.md:

  • API keys or secret keys
  • Database connection strings with credentials
  • Passwords or authentication tokens
  • Private internal URLs or IP addresses
  • Customer or user data

Your CLAUDE.md is a plain text file. If it’s committed to version control, anyone with repository access can read it. Use environment variables for all credentials and reference them by variable name in your CLAUDE.md if needed:


## Environment Variables
- `DATABASE_URL` — PostgreSQL connection string (in .env.local, never committed)
- `STRIPE_SECRET_KEY` — Stripe API key (in .env.local, never committed)
- `CLERK_SECRET_KEY` — Clerk authentication secret (in .env.local, never committed)

This tells Claude the variable names without exposing the values.


❌ DON’T: Make It a Dumping Ground

Some developers treat CLAUDE.md as a place to capture every note, decision, and thought about the project. The result is a sprawling document that’s hard to maintain and hard for Claude to use effectively.

Every section in your CLAUDE.md should answer one of these questions:

  • What does this project do?
  • What tech does it use?
  • What are the coding rules?
  • Where do files go?
  • What commands should be run?
  • How is the system structured?
  • What must Claude never do?

If a note doesn’t answer one of these questions, it probably belongs somewhere else — in a README, a wiki, a project management tool, or a separate documentation file.


❌ DON’T: Write It Once and Forget It

A CLAUDE.md that described your project six months ago but doesn’t describe it today is worse than a short, accurate one. Stale context sends Claude in the wrong direction.

Common staleness triggers:

  • You migrated from Pages Router to App Router
  • You switched state management libraries
  • You restructured your folder layout
  • You added a new major integration
  • You changed your testing framework
  • A folder you listed as “off limits” was deleted

When any of these happen, update your CLAUDE.md in the same commit as the change. Make it part of the same pull request.


❌ DON’T: Write Rules That Are Too Long to Enforce

If a rule takes five sentences to explain and still leaves room for interpretation, break it into smaller rules or simplify it.

❌ Too complex:


- When creating new components, consider the context in which they'll be used, and if they
  are likely to be reused across multiple features, place them in the ui/ folder, but if
  they're specific to a particular feature, place them in the features/ folder, unless the
  feature itself has subfolders, in which case co-locate the component with the closest
  relevant subfolder, except when the component could theoretically be used elsewhere someday.

✅ Split into clear rules:


- Generic UI primitives (Button, Input, Modal) go in `components/ui/`
- Feature-specific components go in `components/features/`
- If you're unsure which applies, ask — don't guess

The CLAUDE.md Checklist

Use this to validate your CLAUDE.md before your next session:

Content quality:

  • [ ] Every rule is specific enough to verify in Claude’s output
  • [ ] No placeholders — all brackets replaced with real details
  • [ ] Real code examples included for complex patterns
  • [ ] “We decided against X” notes for the alternatives you’ve ruled out
  • [ ] No sensitive credentials or API keys

Structure:

  • [ ] Clear H2 sections for each major topic
  • [ ] Tech stack clearly listed with versions
  • [ ] Folder structure described with explanations
  • [ ] Commands included for dev, test, build
  • [ ] “Never touch” list included for protected files

Maintenance:

  • [ ] Reflects your project’s current state (not what it looked like months ago)
  • [ ] Global vs project-level rules are in the correct file
  • [ ] No contradictory rules
  • [ ] No rules Claude already follows by default

Common Troubleshooting

Claude is ignoring a rule in my CLAUDE.md.

Check if the rule is specific enough. “Write readable code” won’t be enforced consistently. “Use camelCase for all variable names, PascalCase for all class and component names” will be. Also check for contradictions — if two rules conflict, Claude picks one.

My CLAUDE.md is getting too long.

Audit each section: does every line change Claude’s behavior in a way that matters? Cut anything that doesn’t. For project type-specific content, consider whether a framework-specific guide like CLAUDE.md for React/Next.js Projects has what you need without you maintaining it yourself.

Claude generates good code but doesn’t follow my folder structure rules.

Make sure your folder structure section explains rules (where new files go), not just describes the current structure. “New API utility functions go in lib/api/utils/” is a rule. “We have a lib/api/utils/ folder” is just a description.


Key Takeaways

  • Specific and testable** beats vague and aspirational — if you can’t verify a rule in Claude’s output, rewrite it
  • Real content only** — no placeholders, no generic filler, no aspirational rules that don’t reflect reality
  • Include code examples** for complex patterns — Claude pattern-matches from them reliably
  • State what you’ve decided against** — this section prevents suggestions you’ve already evaluated and rejected
  • Update it with your project** — a stale CLAUDE.md actively misleads Claude; treat updates as part of any significant change

Next Steps

Return to CLAUDE.md — The Complete Beginner’s Guide (2026) for the full picture.