Welcome to my digital garden. 🌱

Tim Le

Writing a CLAUDE.md that actually helps your coding agent

What belongs in a CLAUDE.md, what to leave out, and how to keep it short and true: a practical guide with real examples, a layered setup and a simple maintenance loop for Claude Code and other coding agents.

Writing a CLAUDE.md that actually helps your coding agent

Every Claude Code session in a repo starts the same way: the agent reads the project's CLAUDE.md before it reads your prompt. That makes it the most-read file in the project. It is loaded on every task, by every session, for as long as the repo exists.

And yet most CLAUDE.md files I see fall into one of two traps. Either they are a generated wall of text that restates the README and lists every folder, or they are three lines written on day one and never touched again. Neither helps much. The first burns context and buries the rules that matter; the second leaves the agent guessing.

This post is how I write and maintain mine now. It applies, with small changes, to AGENTS.md and the instruction files other coding agents read too.

What CLAUDE.md is for

The agent can already do a lot on its own. It can list files, read package.json, open the router and figure out that this is a Nuxt app with Tailwind. Anything it can discover in a few tool calls does not need to be in the file.

So the job of CLAUDE.md is narrow: tell the agent what it cannot cheaply discover, and what it would otherwise get wrong. I ask one question of every line:

Would a smart new teammate get this wrong on their first day without being told?

If yes, it goes in. If they would figure it out by reading the code, it stays out. That single test removes most of the bloat.

What to include

These are the sections that earn their place in almost every project I work on.

Commands, exactly as they run. How to install, run the dev server, run one test, run the linter and type-check. Not "run the tests", but the real command with the real flags. Agents love to run the whole suite when one file would do; telling them how to run a single test saves minutes per task.

Non-obvious conventions. The things that look arbitrary but aren't: "API handlers return { data, error }, never throw", "dates are stored in UTC and formatted only in components", "new components go in components/ui and use the Base prefix".

Boundaries. Files and folders the agent should not edit (generated code, vendored libraries, migrations that already ran), and commands it must never run (anything that touches production, drops a database or force-pushes).

Gotchas. The trap that cost someone an afternoon: the env var that must be set for tests, the port that is already used by another service, the package that must stay pinned.

How to verify work. What "done" means here: tests pass, types check, lint is clean, and maybe "check the page in the browser for UI changes".

Two columns comparing what belongs in CLAUDE.md and what to leave out

What to leave out

The opposite list is just as important, because every line you add is sent with every request and competes for the model's attention.

  • The README. Project history, marketing copy, setup for humans on a new laptop. The agent can read the README if it needs to.
  • A folder tree. It goes stale in a week and the agent can run ls in a second.
  • Generic advice. "Write clean code", "follow best practices", "be careful". The model already tries to do this; the line adds nothing but tokens.
  • Rules the linter already enforces. If Prettier and ESLint run in CI and in a hook, you don't need to describe quote style.
  • Secrets. No API keys, tokens or internal URLs you would not paste in a public issue. The file is committed and read by tools.
  • Long code samples. Point to a good example file instead: "follow the pattern in server/api/posts.get.ts".

A useful rule of thumb: if a section is longer than the code it describes, it is probably documentation, and documentation belongs somewhere else.

A real example

Here is the shape of a CLAUDE.md I would write for a typical Nuxt 3 app. It is short on purpose.

# Project notes for the agent

## Commands
- Install: pnpm install
- Dev: pnpm dev  (port 3000)
- One test: pnpm vitest run path/to/file
- Checks: pnpm lint && pnpm typecheck

## Conventions
- Server routes: server/api/*.ts, return
  { data, error }; never throw to client.
- Shared types live in types/, not in
  components.
- Use composables in composables/ for
  fetch logic; components stay dumb.
- Dates: store UTC, format with
  utils/date.ts only.

## Boundaries
- Do not edit: .output/, generated/,
  migrations that are already merged.
- Never run db:reset or anything with
  --prod.
- Ask before adding a dependency.

## Gotchas
- Tests need NUXT_PUBLIC_API=mock.
- Images go in public/, referenced with
  a ?v= suffix for cache busting.

## Done means
- Lint, typecheck and the related tests
  pass. For UI changes, check the page.

That is around 30 lines. It doesn't explain what Nuxt is, doesn't list every folder and doesn't repeat the lint rules. But an agent reading it avoids the mistakes I would otherwise correct by hand: running the full suite, throwing errors from API routes, adding a date library, or touching generated files.

Notice that the bullets are specific and checkable. "Keep components simple" is a wish. "Fetch logic goes in composables; components stay dumb" is a rule the agent can follow and you can review.

Layers: not everything belongs in one file

Claude Code reads instructions from more than one place, and spreading them out keeps each file small and relevant.

Where agent instructions live: user, project and folder CLAUDE.md files, plus skills and hooks

How I split them:

WhereWhat goes thereLoaded
~/.claude/CLAUDE.mdPersonal habits for every repoEvery session
CLAUDE.md at the rootTeam rules for this projectEvery session
CLAUDE.md in a subfolderRules for that area onlyWhen work touches it
SkillsLong workflows (deploy, release)Only when needed
HooksThings that must always happenRun by the harness

User-level is for preferences that follow me everywhere, like how I want commit messages written. They don't belong in a team file.

Folder-level files are great in monorepos. The rules for apps/mobile have nothing to do with services/billing, so the agent shouldn't carry both all the time.

Skills are where long procedures go. A twelve-step release checklist in the root file costs tokens on every unrelated bug fix. As a skill, only a short description stays in context, and the full steps load when the task actually needs them.

Hooks are for rules that must never be skipped. This is the most important distinction in the whole setup: CLAUDE.md is guidance, not enforcement. The model follows it most of the time, which is great for conventions and terrible for "never push to main". If breaking a rule would be expensive, enforce it with a hook, a permission rule or CI, and keep the sentence in CLAUDE.md only as an explanation.

You can also import other files with an @path reference, which is handy when a project already has a good CONTRIBUTING.md. I use it sparingly; an import is still loaded into context, so it only moves the bloat to a different file.

Write it like a checklist, not an essay

The format matters almost as much as the content. A few habits that make instructions easier for a model to follow:

  • Short bullets, one rule each. A paragraph that mixes three rules gets one of them followed.
  • Imperative and concrete. "Use pnpm, not npm" beats "we generally prefer pnpm".
  • Give the reason when it isn't obvious. "Don't edit generated/: it is overwritten by pnpm codegen" helps the agent make the right call in a situation you didn't foresee.
  • Emphasis only where it counts. If every line says IMPORTANT, nothing is. I reserve strong wording for one or two rules where a mistake is costly.
  • Real paths and names. The agent can open utils/date.ts. It can't open "our date helper".

Keep it alive: the maintenance loop

A CLAUDE.md is never finished. The best lines in mine were not written up front; they were added the day the agent made a mistake.

A loop: notice a repeated mistake, ask why, add one specific line, check in the next session, prune what is stale

The loop I follow:

  1. Notice a repeated mistake. Once is noise. The second time the agent runs the whole test suite, or puts a type in the wrong folder, it is a missing instruction.
  2. Ask why it happened. Was the rule missing, vague, or buried under forty other lines? Sometimes the fix is deleting something, not adding.
  3. Add one specific line. Phrase it so it would have prevented this exact mistake.
  4. Check it in the next session. Start fresh and give a similar task. If the agent still gets it wrong, the line needs rewording or a hook.
  5. Prune. When a convention changes or a gotcha is fixed, delete the line. A stale instruction is worse than none, because the agent trusts it.

I also review the file whenever I review a big refactor. If we moved the API layer, the paths in CLAUDE.md probably moved too. Treat it like code: it lives in the repo, it goes through pull requests, and it can have bugs.

Starting from zero

If a project has no CLAUDE.md yet, running /init in Claude Code gives you a starting draft based on the codebase. I find it a useful first pass, but I always edit it hard afterwards:

  • Delete everything the agent could discover itself (structure, framework, obvious scripts).
  • Fix the commands so they are exactly what the team runs.
  • Add the boundaries and gotchas, which no generator can know.

What's left is usually a third of the original length and twice as useful.

A quick self-review

Before I commit changes to a CLAUDE.md, I run through this list:

  • Could I read the whole file in under two minutes?
  • Does every line pass the "smart new teammate" test?
  • Are the commands copy-pasteable and correct today?
  • Is every "never" rule also enforced somewhere else?
  • Are long workflows in skills, and area-specific rules in folder files?
  • Is there nothing secret in it?

Conclusion

A good CLAUDE.md is short, specific and a little bit opinionated. It tells the agent the things it can't see: the exact commands, the conventions that look arbitrary, the boundaries and the traps. Everything else is noise that costs tokens and attention on every single request.

Start small, add a line each time the agent stumbles, delete lines when they stop being true, and move anything that must never fail into a hook. After a few weeks, you will notice you correct the agent much less, and that is the whole point.