beginner 30 minutes

CLAUDE.md file: set up your first one in Claude Code

Set up your first CLAUDE.md file in Claude Code: run /init, add four short sections, check Claude loaded it, and learn what belongs in rules, skills or hooks.

A boxy yellow robot points at a framed rulebook labelled CLAUDE.MD on a workshop wall while a green dog sits beside a pile of crossed-out sticky notes.
You'll be able to
  • write a first CLAUDE.md that covers your project, stack and conventions, rules and commands;
  • check that Claude Code loaded it, and that Claude follows it;
  • decide whether an instruction belongs in CLAUDE.md, auto memory, a rule file, a skill or a hook;
  • keep the file short and current as the project changes.
Who it’s for
people who use Claude Code on a real project. This guide is part of the Claude Code strand; the section “If you also use Cursor, Codex or Copilot” covers the file names other assistants read.
Time
about 30 minutes, including the exercise (an estimate).

You open Claude Code and spend two minutes explaining how your project works: the framework, the test command, the naming conventions, the deployment target. You did the same thing yesterday, and the day before that.

Every Claude Code session starts with a fresh context window (the text Claude can see at once). Claude reads your files, infers what it can, and guesses the rest. Some of its guesses are good, but sometimes it runs npm test on a project that uses bun test, or writes camelCase in a codebase that uses snake_case. It may also commit directly to main when you always use branches.

CLAUDE.md is a file that Claude reads at the start of every session. Whatever you put in it becomes part of the conversation before you type a word, so you write your conventions, preferences and rules down once. What goes in that first file, and how do you know Claude is reading it?

Part 1 of 4 Learn

Let /init write the first draft

The quickest way to a first file is to let Claude write it. Type /init in a Claude Code session in your project. Claude reads the codebase and writes a starting CLAUDE.md with the build commands, test instructions and conventions it can find. If a CLAUDE.md already exists, /init suggests improvements instead of overwriting it.

That draft is a starting point. It can only write down what it finds in the code. You add the project’s purpose and the corrections you keep making, using the four sections further down.

Where CLAUDE.md lives

The file /init creates sits in the root of your project directory, at the same level as your package.json, Cargo.toml, or whatever marks the top of your project. If you would rather make it yourself, create a file called CLAUDE.md there:

touch CLAUDE.md

When Claude Code starts a session in that directory, it reads this file automatically and needs no configuration.

The project root is the right place for your first file, and three other places also work:

FileScopeUse it for
~/.claude/CLAUDE.mdEvery project on your machinePersonal preferences that apply everywhere
CLAUDE.md (or .claude/CLAUDE.md) in the project rootThis project, shared with your team through GitMost of your instructions
CLAUDE.local.md in the project rootThis project, just youPersonal notes for this project; add it to .gitignore, the file that lists what Git leaves out
CLAUDE.md in a subfolderThat part of the projectDifferent conventions for one package in a monorepo (one repository that holds several packages)

If two of them contradict each other, Claude may follow either one, so keep them consistent (Anthropic’s memory docs (opens in a new tab), checked 5 November 2026).

You can add a global file later, once you find yourself copying the same rules between projects.

Four sections for a first file

A first file is often either too short (a single line that says “use TypeScript”) or too long (a 2,000-line document that tries to cover every edge case).

A good first CLAUDE.md has four sections. Each one answers one thing Claude would otherwise guess: what the project is, which tools it uses, what to do or avoid, and which commands to run. The examples use a made-up Next.js project, so swap in your own stack. The examples name tools that project uses, such as Prisma, Zod and Conventional Commits; you don’t need to know them to follow this guide.

Project overview

One paragraph. What is this project, and what does it do? Claude can read your code but not your intentions, so a sentence of context prevents many misunderstandings.

# Project

This is a Next.js 14 app for managing restaurant reservations. It uses the App Router, Prisma with PostgreSQL, and Tailwind CSS. The API serves both the web frontend and a mobile app.

This tells Claude what kind of project this is, so it makes better decisions about everything else. Without it, Claude might treat your full-stack web app like a CLI tool, or your library like an application.

Tech stack and conventions

What frameworks, tools, and patterns does this project use? Be specific about the things Claude would get wrong by defaulting to the most common option.

## Stack

- **Framework:** Next.js 14 with App Router (not Pages Router)
- **Database:** PostgreSQL via Prisma ORM
- **Styling:** Tailwind CSS, no component library
- **Testing:** Vitest for unit tests, Playwright for e2e
- **Package manager:** pnpm (not npm or yarn)

## Conventions

- Use named exports, not default exports
- API routes return `{ data, error }` shape, never throw
- Components go in `src/components/[feature]/`
- Database queries go through service files in `src/services/`, never called directly from routes

The conventions section is the highest-value part of the file. Every time you’ve corrected Claude mid-session (“we use named exports”, “put that in the services folder”), that correction belongs in this section.

Rules

List what Claude should always or never do in this project, and keep each rule short, specific and testable.

## Rules

- Always run `pnpm test` before suggesting a commit
- Never modify files in `src/generated/` — these are auto-generated by Prisma
- Use `async/await`, not `.then()` chains
- All new API routes need input validation with Zod
- Commit messages follow Conventional Commits format

“Always run pnpm test before suggesting a commit” can be checked mechanically. “Write clean code” and “follow best practices” add no information, because Claude already tries to do both. A rule should change what Claude does compared to what it would do without it.

Common commands

The commands you use to build, test, lint, and deploy. Claude can often find these by reading your package.json or Makefile. Listing them stops it guessing wrong, or running a slow command when a fast one exists.

## Commands

- **Dev server:** `pnpm dev`
- **Run tests:** `pnpm test`
- **Run single test file:** `pnpm test -- src/path/to/test.ts`
- **Lint:** `pnpm lint`
- **Database migrations:** `pnpm prisma migrate dev`
- **Generate Prisma client:** `pnpm prisma generate`

This is especially useful if your project has non-obvious commands. If deploying requires three steps in a specific order, or if there’s a script that seeds the development database, put it here.

Copy the four-section starter

Copy this starter, replace the specifics with your project’s details, and save it as CLAUDE.md in your project root.

# Project

[One paragraph: what this project is and what it does.]

## Stack

- **Framework:** [your framework and version]
- **Language:** [language and any relevant version info]
- **Testing:** [test framework and runner]
- **Package manager:** [which one]

## Conventions

- [How you name things]
- [Where different types of files go]
- [Patterns you follow consistently]

## Rules

- [Things Claude should always do]
- [Things Claude should never do]
- [Project-specific constraints]

## Commands

- **Dev:** `[command]`
- **Test:** `[command]`
- **Build:** `[command]`
- **Deploy:** `[command]`

Fifteen to thirty lines is a good target for a first file. You can always add more later, and you will, once you start noticing the corrections you no longer have to make.

Check that it loaded, then that it works

Start a new Claude Code session and run /context all, which lists what Claude has loaded into the session. Your CLAUDE.md should be listed under Memory files (in fullscreen mode, plain /context collapses that list). If it isn’t there, Claude can’t see it: check the file is in the project root and named exactly CLAUDE.md (the name is case-sensitive on Linux).

Then ask Claude to do something your file covers. If you added a rule about test commands, ask it to run the tests. If you specified naming conventions, ask it to create a new component. You should see Claude follow your conventions without being told.

If it loaded and Claude still doesn’t follow an instruction, the instruction is usually too vague. “Follow the project conventions” tells Claude nothing. “Use named exports, not default exports” tells it exactly what to do. Claude treats CLAUDE.md as context, so it follows clear instructions consistently but isn’t forced to. Anything that must happen every time at a set point, such as after each edit, belongs in a hook: a command Claude Code runs automatically at that point (see the next section). Source: Anthropic’s memory docs (opens in a new tab), checked 5 November 2026.


Where other instructions belong: memory, rules, skills, hooks

CLAUDE.md is one of several places Claude Code keeps instructions and knowledge. If an instruction is in the wrong place, Claude may load it when it isn’t needed, or skip it when it is.

Put it inWhenHow
CLAUDE.md: the file this guide sets upFacts and rules Claude needs in every session: commands, conventions, project layoutYou write it
Auto memory: notes Claude Code writes for itselfYour preferences and corrections, and project context Claude can’t get from the codeClaude writes it. Say “remember that the API tests need a local Redis” and it saves a note
A rule file in .claude/rules/: an instruction file that can apply to only some filesInstructions for one part of the codebase, such as API code or testsYou write one file per topic; a paths line makes it load only for matching files
A skill: a set of instructions for a workflow, run with a slash commandA multi-step workflow you run now and then, such as a release checklist.claude/skills/<name>/SKILL.md, run with /<name>
A hookSomething that must happen every time at a set point, such as running the formatter after each editA command in .claude/settings.json that Claude Code runs automatically at that point

Auto memory is on by default in local sessions, so Claude Code may already be saving notes about your project. They stay on your machine and aren’t shared through Git.

Run /memory to see and edit these files, or to switch auto memory off. When you ask Claude to remember something, it goes into auto memory; to put it in CLAUDE.md instead, say “add this to CLAUDE.md”.

Keep task progress out of CLAUDE.md. “Currently working on the auth refactor” is stale by next Monday, and it would load in every session until you remember to delete it. Auto memory can note ongoing work and deadlines, and Claude updates those notes as things change.

For the technically curious: how Claude Code loads these files

Claude Code adds every CLAUDE.md it finds to the context, with the most specific read last. It reads the ones above your working directory when the session starts, and a subfolder's file when Claude first works on a file in that subfolder (Anthropic's memory docs (opens in a new tab), checked 5 November 2026).

Auto memory lives in ~/.claude/projects/<project>/memory/, with an index file called MEMORY.md. The first 200 lines or 25KB of MEMORY.md, whichever comes first, load at the start of every session, and Claude reads the other notes when it needs them.

Skills used to be called custom commands. A file in .claude/commands/ still works, but Anthropic now recommends skills for new work. A skill's folder can also hold supporting files, such as a template or a script. Project skills in .claude/skills/ can be committed so your whole team gets them; personal ones in ~/.claude/skills/ follow you across projects. Sources: Anthropic's memory (opens in a new tab) and skills (opens in a new tab) docs, checked 26 October 2026.

Try it on six things you might tell Claude.

Made-up example for illustration. The project and its instructions are invented.

Which file does it go in?

Six things you’ve had to tell Claude in a project. Choose where each one belongs, and you’ll see where the guide puts it.

  1. “Always run pnpm test before suggesting a commit.”

    CLAUDE.md. It’s a rule Claude needs in every session, and you can check it was followed.

  2. “Run the formatter after every edit.”

    A hook. Claude Code runs a hook’s command at that point every time, and Claude can skip a CLAUDE.md instruction.

  3. “Remember that I prefer short answers.”

    Auto memory. It’s your preference, and when you ask Claude to remember something, it goes into auto memory.

  4. “In the API folder only: every new route validates its input with Zod.”

    A rule file. It applies to one part of the codebase, and a paths line makes the rule file load only for files in the API folder.

  5. “Our twelve-step deploy procedure.”

    A skill. It’s a multi-step workflow, and a skill loads only when you run it.

  6. “We’re currently working on the auth refactor.”

    Auto memory. Task progress goes stale, and in CLAUDE.md it would load in every session until you deleted it. Auto memory can note ongoing work, and Claude updates those notes as things change.

Nothing placed yet.

This page sends nothing anywhere. Your choices stay in your browser.

How to read this

CLAUDE.md is one of several places Claude Code keeps instructions and knowledge. If an instruction is in the wrong place, Claude may load it when it isn’t needed, or skip it when it is.

CLAUDE.md
Facts and rules Claude needs in every session.
Auto memory
Your preferences and corrections, and project context Claude can’t get from the code. Claude writes it.
A rule file
Instructions for one part of the codebase, in .claude/rules/.
A skill
A multi-step workflow you run now and then.
A hook
Something that must happen every time at a set point.

Grow it from real corrections, and prune it

The best additions come from real sessions, when you notice a correction you keep making.

The pattern: you’re working with Claude when it does something wrong, and you correct it. Then ask yourself: will this come up again? If it will, add a line to CLAUDE.md; if it’s a one-off, don’t bother.

  • Review it monthly. Remove rules that no longer apply. A convention you’ve abandoned actively misleads Claude, because it will keep following it.
  • Keep it under 200 lines. That’s Anthropic’s target: longer files use more context and get followed less reliably. If it’s longer, you’re probably specifying things Claude can infer from your code, or things that belong in a rule file or a skill.
  • Use headings and bullet points. A well-structured file is easier for Claude to follow, just as it’s easier for a person to skim.
  • Run /doctor prompt-audit (Claude Code 2.1.283 or later). Claude checks your CLAUDE.md, rules and skills for outdated instructions, references to files or commands that no longer exist, and files that contradict each other. It proposes edits and changes nothing until you say so.

If you also use Cursor, Codex or Copilot

Other coding assistants read their own instruction file. AGENTS.md is an instruction file that several of them read:

ToolFile
Claude CodeCLAUDE.md, or AGENTS.md (see below)
CursorAGENTS.md, or .mdc files in .cursor/rules/
CodexAGENTS.md
GitHub Copilot.github/copilot-instructions.md, and AGENTS.md

If you use more than one, keep your shared instructions in AGENTS.md. Claude Code (version 2.1.277 or later) reads it when there’s no CLAUDE.md or CLAUDE.local.md in the project or the folders above it. If you want Claude-specific instructions as well, make a CLAUDE.md that starts with @AGENTS.md and add them below it. Running /init in a project that already has Cursor or Copilot rules pulls the relevant parts into the CLAUDE.md it writes. Sources: Anthropic’s AGENTS.md docs (opens in a new tab), Cursor (opens in a new tab), OpenAI (opens in a new tab), GitHub (opens in a new tab), Anthropic’s page checked 5 November 2026, the others 26 October 2026.

Part 2 of 4 Practise

Try it on your own work

  1. Run /init in a Claude Code session in your project.Result a CLAUDE.md in the project root with the commands and conventions Claude found.
  2. Add what /init couldn’t know: one paragraph on what the project is, and the corrections you’ve typed more than once, using the four sections above.Result a file of fifteen to thirty lines with an overview, stack and conventions, rules and commands.
  3. Start a new session and run /context all.Result CLAUDE.md is listed under Memory files.
  4. Ask Claude to do something one of your rules covers, such as running the tests.Result it uses your command without being told.
  5. Take three things you’ve had to tell Claude recently and decide where each belongs, using the table under “Where other instructions belong”.Result you’ve decided which one each goes in: CLAUDE.md, auto memory, a rule file, a skill or a hook.
  6. Run /memory.Result a list of your CLAUDE.md files and the auto memory folder, with the option to open any of them.
  7. A month later, prune the file. Run /doctor prompt-audit, or read the file yourself, and remove or update anything that’s out of date.Result no line in the file contradicts how the project works now.

Part 3 of 4 Check

Check yourself

You ran /init on a four-year-old project. The draft lists `npm test`, but your team switched to `bun test` last spring and nobody remembers why the `legacy/` folder is off limits. What do you do before relying on the file?

Correct the test command. Then add what Claude can’t see in the code: a paragraph on what the project is for, a rule such as “never edit legacy/”, and the conventions it keeps getting wrong. Add the corrections you’ve typed more than once.

You added a rule to CLAUDE.md, but Claude ignores it in a new session. What do you check first?

Run /context all and look under Memory files. If CLAUDE.md isn’t listed, Claude can’t see it: check the file’s location and name. If it is listed, make the rule more specific, and check that no other CLAUDE.md or rule file says the opposite.

You keep reminding Claude to run the formatter after every edit, and sometimes it forgets. Where does that instruction belong?

In a hook that runs after each file edit. Claude Code runs a hook’s command at that point every time, and Claude can skip a CLAUDE.md instruction.

Your CLAUDE.md has reached 450 lines. It includes a twelve-step deploy procedure, rules that only apply to the API folder, and a line saying to use Jest, though you moved to Vitest last year. What do you do with each?

Move the deploy procedure into a skill, so it loads only when you run it. Move the API rules into a file in .claude/rules/ with a paths line for the API folder. Change the Jest line to Vitest, or delete it if Claude can tell from the project.

Your team uses Cursor and you use Claude Code. Where do the shared project conventions go?

In AGENTS.md, which Cursor reads. Claude Code reads it too when there’s no CLAUDE.md or CLAUDE.local.md in the project or the folders above it. If you want Claude-only instructions as well, add a CLAUDE.md that starts with @AGENTS.md.

Part 4 of 4 Keep

Keep this

Add a line when a correction will come up again

  • When you correct Claude and it’ll come up again, add a line to CLAUDE.md.
  • Keep CLAUDE.md for what Claude needs every session, and move the rest to rule files, skills or hooks.
  • Let auto memory hold your preferences, and look through it with /memory now and then.
  • Once a month, prune CLAUDE.md or run /doctor prompt-audit.

After your next session, open CLAUDE.md and add the one correction you typed twice.

In the Members Library (opens in a new tab), members can get a ready-to-fill CLAUDE.md with the four sections, plus a worked example.