A CLAUDE.md file is the persistent project brief Claude Code loads automatically at the start of every session, capturing stack conventions, build and test commands, and patterns that Claude Fable 5, Opus 5, and Sonnet 5 would otherwise need re-explaining each time. It sits within a memory hierarchy of project, user, and modular files, supports @path imports for splitting large files, and updates through the /init, /memory, and # workflows.
This guide is for developers configuring Claude Code for a new or existing repository. You will create a persistent memory file, configure modular rules, and verify context loading across sessions. For full AI-native lifecycle orchestration, see Design.
When you drop Claude Code into a repository without context and ask for a small change, it can pick the wrong package manager, scaffold a component that ignores your folder conventions, or re-ask which test runner you use. The model lacks your team’s context. A CLAUDE.md file fixes that: it serves as the persistent project brief Claude reads at the start of every session, eliminating guesswork and enforcing your stack conventions.
CLAUDE.md is a markdown file that Claude Code automatically loads into context at startup. It acts as persistent memory that helps Claude understand your project’s specific requirements, coding standards, and common workflows.
Key benefits:
Provides persistent context across sessions.
Stores team knowledge in version control.
Loads automatically on startup.
Supports hierarchical organization for complex projects.
To initialize Claude Code in your project, follow these steps:
Navigate to your project directory:
Terminal window
cdREPOSITORY_PATH
Replace REPOSITORY_PATH with the path to your local git repository.
Start Claude Code:
Terminal window
claude
Initialize CLAUDE.md:
Terminal window
/init
Review and customize the generated configuration. Claude analyzes your project and generates an initial CLAUDE.md file.
The /init command generates a starting template, but repository-specific instructions provide better guidance. To generate a CLAUDE.md based on your actual codebase, run the following prompt in Claude Code:
Contains module-specific context located in subdirectories:
Component patterns and UI library conventions
Service architecture and database query conventions
Module dependencies and internal libraries
Local subproject test and build commands
Location: ./.claude/rules/*.md
Contains topic-specific rules committed to version control that keep the root CLAUDE.md concise. Each rule file can specify matching paths in a frontmatter paths field using glob patterns:
---
paths:
- "src/app/api/**"
---
- Validate every request body with a Zod schema.
- Return errors as { error: string } with the appropriate status code.
Scoped rules load only when Claude edits matching files. Rules without a paths field load unconditionally in every session.
When you find Claude repeatedly violating a pattern in one directory, add a scoped rule under .claude/rules/:
For large projects, keep the root CLAUDE.md concise and import specialized files with the @path/to/file directive. Unprefixed bullet lists do not import content; only the @ prefix triggers an import.
The following example demonstrates root configuration imports:
CLAUDE.md with @path imports
# Main Project Configuration
See @README.md for the project overview and @package.json for available commands.
## Architecture
High-level system design and principles live here...
## Detailed Conventions
- Frontend conventions @frontend/CLAUDE.md
- Backend conventions @backend/CLAUDE.md
- Infrastructure runbooks @infra/CLAUDE.md
- Testing rules @tests/CLAUDE.md
Imports accept relative and absolute paths. Relative paths resolve against the file containing the import statement, not your working directory. The @ directive inside fenced code blocks remains inert. To share global instructions across git worktrees, import from your home directory (for example, @~/.claude/my-conventions.md).
When your root CLAUDE.md exceeds 300 lines, use the following prompt to refactor it into modular files: