The CLAUDE.md file: give your AI permanent memory
4m read time

The CLAUDE.md file: give your AI permanent memory

Every Claude Code session starts from zero unless you tell it otherwise. The CLAUDE.md file is how you give it persistent context about your project, your stack, and your preferences.

If you've used Claude Code for more than a day, you've experienced the frustration. You open a new session, ask it to build something, and it starts exploring your codebase from scratch. It re-reads your dependencies. It guesses at your conventions. It makes assumptions about your stack that you then have to correct. Every. Single. Time.

The fix is embarrassingly simple: a Markdown file called CLAUDE.md.

What It Does

The CLAUDE.md file gives Claude Code persistent memory about your project. You place it in the root of your repository, and Claude reads it automatically at the start of every session. Think of it as an onboarding script for your codebase.

Technically, the contents of CLAUDE.md are appended to your prompt. Claude doesn't "remember" your project between sessions, but it reads this file before it does anything else, which has the same practical effect.

You can bootstrap one instantly:

bash
/init

Claude will scan your codebase and generate a CLAUDE.md based on what it finds. It's a solid starting point, but you'll want to refine it.

What Goes In It

A good CLAUDE.md is short and opinionated. It answers the three questions Claude asks itself at the start of every session: What is this project? How should I write code here? What commands do I need?

Here's the structure I follow:

Stack

Tell Claude what it's working with. Framework, language version, ORM, CSS approach. Don't make it guess.

markdown
- Next.js 15, App Router
- TypeScript (strict mode)
- Tailwind CSS
- Drizzle ORM

Preferences

This is where you encode your conventions. Named exports or default exports? Tabs or spaces? Server actions or API routes? Every team has opinions. Write them down.

markdown
- Use two-space indentation
- Prefer named exports
- Use server actions instead of API routes where possible
- All API routes go in app/api/

Commands

Tell Claude how to run things. Dev server, tests, linting. Don't assume it knows.

markdown
- Dev server: `npm run dev`
- Run tests: `npm test`
- Lint: `npm run lint`

That's it. Three sections. Keep it compact. A CLAUDE.md that's three pages long defeats the purpose, you're burning context tokens on instructions instead of actual work.

The Hierarchy

There's more than one place to put a CLAUDE.md. The file system follows a hierarchy:

Project-level (CLAUDE.md in the root of your repository): shared context about this specific project. This is the one you commit to version control. Your entire team benefits from it.

User-level (CLAUDE.md in your Claude configuration folder): personal preferences that apply across all your projects. Things like your preferred comment style, your editor conventions, how you like error messages formatted. This one stays on your machine.

The project-level file takes precedence for project-specific instructions, while user-level preferences fill in the gaps.

Three Tips That Actually Matter

Start without one. Anthropic's own recommendation, and I agree with it: begin a new project without a CLAUDE.md and pay attention to where you have to constantly course-correct the model. Those corrections are exactly what should go in the file. This keeps it lean and relevant instead of bloated with instructions Claude would've followed anyway.

Use @ references. If your project has documentation, architecture decision records, or API specs, don't paste them into CLAUDE.md. Reference them:

markdown
Refer to @docs/architecture.md for the system design.
Refer to @docs/api-spec.yaml for endpoint contracts.

Claude will read those files when it needs them, keeping your CLAUDE.md compact while giving it access to deep context.

Ask Claude to save corrections to memory. When you correct Claude during a session, like "always use server actions instead of API routes", explicitly ask it to save that to its memory. Next session, it will know. This is the lowest-friction way to evolve your CLAUDE.md over time.

The Difference It Makes

The gap between a frustrating Claude Code session and a productive one is almost always a context problem. Claude is capable, but it's not psychic. Without a CLAUDE.md, every session is a cold start. With one, Claude walks in already knowing your stack, your conventions, and your commands.

It's the same principle I've talked about before with the hooks guide and Superpowers: the less time Claude spends figuring out how you work, the more time it spends doing actual work.

Start with your stack, your preferences, and your commands. Build from there as you go, and prune as often as you add, because stale memory is worse than no memory. That's all there is to it.

(4 of 30)
01Getting the best out of Claude Code02Superpowers: teaching Claude Code to think before it types03Claude Code hooks: deterministic control over AI workflows04The CLAUDE.md file: give your AI permanent memory05Stop asking your agent nicely06What's new in Claude Code: notes from the London talk07The best number in Opus 4.8 isn't a benchmark08Stale memory is worse than no memory09The agent is just a loop10Build an MCP server, then ask whether it should exist11Skill, subagent, hook, or slash command? Pick the right one12Log in to MCP servers from your shell13The day 'default' became 'Manual'14How to write a proper Claude Code skill15How to write a proper Claude Code subagent16Claude Code permissions: the guide I wish the docs were17Sandboxing Claude Code: put your agent in a box that holds18Prompt injection defense for developers who ship agents19Which Claude model for which coding task20Refactoring legacy code with a coding agent: start with characterization tests21MCP server authentication: OAuth, scopes and rate limits22Opus 5 is here and your effort settings just expired23AI agent incident response: what to do when your coding agent goes wrong24Claude Code /doctor: the health check became a context audit25Claude Code context management: when to /clear and when to /compact26Git worktrees for parallel coding agents: what they isolate and what they share27Claude Code plan mode: decide before the agent writes28Debugging with a coding agent: give it the search, keep the hypothesis29Claude Code checkpoints and /rewind: how to undo an agent's changes30Claude Code cross-session messaging: how to make your sessions talk to each other