Claude Code - Project Memory with CLAUDE.md
Learn how to use the /init command and CLAUDE.md files to give Claude Code project context and improve code generation quality
In the previous chapter, we covered what Claude Code is and how to get started. We walked through installation, first-time setup and best practices for working with Claude Code. Now that we have Claude Code up and running, it’s time to give it proper context about your project.
Why Use CLAUDE.md?
Before making any code changes with Claude Code, you should initialize a CLAUDE.md file in your project root. This file acts as mini-documentation that Claude uses as context when making decisions about your code, leading to much better code generation that follows your project’s patterns.
The /init Command
Run this command to have Claude scan your entire codebase and create a structured CLAUDE.md file:
|
|
Claude will:
- Analyze your folder structure
- Examine package.json and dependencies
- Identify state management patterns
- Review existing documentation
- Generate a comprehensive CLAUDE.md file
The file is automatically added to session context, so Claude refers to it whenever making changes.
What Gets Included?
A typical CLAUDE.md file contains:
- Development commands (npm scripts)
- Architecture overview (frameworks, libraries, versions)
- Project structure (where files belong)
- Data architecture (APIs, databases, CMS)
- Styling conventions (CSS approach, design system)
- Testing setup (test frameworks, patterns)
- Development notes (coding standards, preferences)
Starting with a New Project
If you’re starting fresh with minimal code, the generated CLAUDE.md will be sparse. In this case:
-
Manually edit the file to outline:
- High-level project structure plans
- Tools, packages, and frameworks you’ll use
- Code style preferences
- Application summary
-
Update it as you go when things change
Adding Memories from Chat
Use the # symbol to add instructions directly from chat:
|
|
You’ll see options to save to:
- Project memory -
CLAUDE.md(tracked in git, shared with team) - Local project memory -
CLAUDE.local.md(personal, not tracked) - Global memory -
~/.config/claude/CLAUDE.md(applies to all projects)
Memory Types Explained
| Memory Type | File Path | Scope | Version Control | Use Case |
|---|---|---|---|---|
| Project | CLAUDE.md or ./.claude/CLAUDE.md |
Project-wide | ✓ Tracked & shared | Project-specific guidance: folder structure, naming conventions, frameworks |
| Local Project | CLAUDE.local.md |
Project-specific | ✗ Not tracked | Personal preferences for this project: your tooling, workflow preferences |
| Global User | ~/.claude/CLAUDE.md |
All projects | ✗ Not tracked | Personal guidance across all projects: coding style, global tools |
Visit Claude Code Memory Types for a comprehensive list of all supported memory types.
Accessing Memory Files
Use the /memory command to open and edit any memory file:
|
|
Select which file to edit (project, local, or global).
Keep It Updated
The CLAUDE.md file isn’t a “set and forget” document. Update it when:
- File/folder structure changes
- Dependencies are added or removed
- Coding standards evolve
- New patterns are established
If you don’t update it, Claude might not pick up on changes and could generate code that doesn’t match your current project structure.
Best Practices
- Always run
/initwhen bringing Claude Code into a project - Review the generated file and add missing information
- Be specific with folder locations and naming conventions
- Update regularly as your project evolves
- Commit to git so the team shares the same context
- Use
#in chat for quick memory additions during development
By maintaining a good CLAUDE.md file, you keep Claude aligned with your project’s architecture and coding style, resulting in cleaner, more appropriate code generation.
