Skip to content
Mastering Claude

Home / Fundamentals and the agent loop

Fundamentals and the agent loop10 minFondation

CLAUDE.md, the project's memory

CLAUDE.md is read automatically at the start of every session on the repository where it sits, and its rules are read as context, with no guarantee of strict enforcement.

CLAUDE.md is a text file placed at the root of a repository. Claude Code reads it automatically at the start of every session opened on that repository, without anyone needing to mention it. The file is delivered as a user message after the system prompt, not as part of the system prompt itself: Claude reads these rules and tries to follow them, with no strict guarantee of compliance. To block an action regardless of what Claude decides, a PreToolUse hook is needed rather than a line in CLAUDE.md.

What /init produces

The /init command runs a real analysis of the current repository, not the copying of a generic template. It scans the folder structure, the scripts declared in the configuration files and the conventions already in place, then proposes a first draft of CLAUDE.md from what it finds. This first draft still needs reviewing and trimming: a short file with absolute rules serves better than a long description of what the repository already contains anyway.

# Commands
npm test runs the test suite
npm run build produces the dist folder

# Conventions
React components live in src/components, one file per component

# Absolute rules
Never commit the dist folder
Always run npm run lint before a commit

A wider variant behind an environment variable

As of 2026-09-02, activating the environment variable CLAUDE_CODE_NEW_INIT=1 before running /init triggers an interactive walkthrough wider than just CLAUDE.md: it also covers skills, hooks and personal memory files, and offers to import the configuration of another agent detected in the repository, for example an AGENTS.md file already present. Without this variable, /init keeps its usual behaviour and produces only a CLAUDE.md.

Why a short file wins

A CLAUDE.md loaded in full at every session weighs on the context available for the rest of the task. The rules that really matter are the ones that, if absent, would waste time or produce an error: the exact command to run the tests, where the components live, what must never be committed. Everything else, the project's history or the full list of dependencies, is better placed in a file read on demand than in a memory loaded on every turn of the agent loop, and a dedicated command also makes it possible to check what is actually loaded in the current session, see the essential slash commands.

Figure 1

Two behaviours of /init

Scope covered by /initWhat gets analysedWhat gets proposed
Without CLAUDE_CODE_NEW_INIT=1The source code and the repository structureA CLAUDE.md file
With CLAUDE_CODE_NEW_INIT=1The repository, plus the skills, hooks and personal memory already presentAn interactive walkthrough that can import the configuration of another detected agent
The same command produces a different result depending on whether a specific environment variable is active at the moment it is run.
Calibrate it yourself

A developer runs /init in a repository where the environment variable CLAUDE_CODE_NEW_INIT=1 is active. Claude Code analyses the contents of the repository, engages an interactive walkthrough that asks questions about the skills and hooks present, then proposes a CLAUDE.md file to approve.

Write in one sentence what this situation establishes, and in one sentence what it does not establish.

What to remember
  • CLAUDE.md is read automatically at the start of every session on the repository where it sits, with no need to flag it.
  • The rules written in CLAUDE.md are read as context at the start of the session, with no guarantee of strict enforcement: what must be guaranteed goes through a hook instead.
  • The /init command genuinely analyses the current repository to produce a first draft, it is not a generic template being copied.
  • Activating CLAUDE_CODE_NEW_INIT=1 before /init triggers an interactive walkthrough that also covers skills, hooks and personal memory.
Do this now

Run /init in an existing repository, review the proposed CLAUDE.md file, and delete any line that describes what you could find by reading the code rather than an absolute rule or an exact command.

What still needs checking

These points depend on an interface or a rule that may have changed since this was written. Check them on your own screen before relying on them.

  • The exact date the CLAUDE_CODE_NEW_INIT=1 variant was introduced could not be found, only its presence as of 2026-09-02 is confirmed.
Check the source

Every datable claim in this lesson links here to the public text behind it. A source that does not open proves nothing.