ContextPruner

How to write a CLAUDE.md file (with examples)

CLAUDE.md tells Claude Code how to work in your repo. Here's what to put in it, a copy-paste template, and the mistakes that make Claude ignore it.

·

Short answer

A good CLAUDE.md is short and specific: a one-line project overview, the exact build and test commands, the conventions Claude should follow, and an explicit list of files to ignore. Put it at your repository root, keep it under a page, and write rules as direct instructions (“use X, never Y”) rather than background prose the agent has to interpret.

CLAUDE.mdis a plain-Markdown file that Claude Code reads automatically to learn how to work in your repository — the stack, the commands, your conventions, and which files to ignore. It's the same idea as AGENTS.md, just the filename Claude looks for. A good one saves you from re-explaining all of that in every session. The real work is keeping it short and specific enough that Claude actually follows it.

Where CLAUDE.md goes

Claude Code looks in a few places, and uses all that apply:

What to put in it

Keep it short and imperative — Claude follows a scannable list of rules far better than a wall of prose. The sections that pull their weight:

A copy-paste template

Start from this and swap in your project's specifics:

# CLAUDE.md

## Project
Next.js 16 app (App Router) + TypeScript. Payments via Stripe,
data in Supabase. Real source lives in app/, lib/, and components/.

## Commands
- Install: `npm install`
- Dev server: `npm run dev`
- Test: `npm test` (Vitest) — run before every commit
- Lint: `npm run lint`

## Conventions
- Use the semantic color tokens in globals.css; never hard-code hex.
- Server Components by default; add "use client" only when needed.
- Match the style of the file you're editing.

## Don't read these
- package-lock.json, dist/, .next/, **/*.min.js — generated files
  with no signal. Skip them to keep context on real code.

Tip: inside Claude Code, the /initcommand drafts a starter CLAUDE.md by scanning your repo. It's a solid first pass — then tighten it and, above all, add the “don't read these” list it won't know to include.

One thing about that last section: a “don't read these” list in CLAUDE.md is advisory — Claude reads it and usually complies, but nothing stops it from opening a listed file anyway. Claude Code can also enforce the skip at the harness level, through deny rules in .claude/settings.jsonthat block a read before it happens — a best-effort block, not a guarantee, but one that doesn't depend on the model's cooperation. That's how enforcement works.

Why Claude sometimes ignores it

When CLAUDE.md doesn't seem to stick, it's usually one of these:

Using more than one agent?

If your team also uses Cursor, Gemini, or Copilot, each reads its own file, and you want the instructions identical across all of them — see CLAUDE.md vs AGENTS.md for how the files relate. Rather than hand-copy, ContextPruner generates AGENTS.md, CLAUDE.md, GEMINI.md, Cursor rules, and Copilot instructions — plus the four enforced ignore files, all nine from one triage of your file tree — with the ignore lists already filled in, free and entirely in your browser.

Related guides