Claude Code/
Lesson

CLAUDE.md is the most important tool for giving Claude project knowledge, but it is not the only one. Claude Code also has an automatic memory system that complements CLAUDE.md. Understanding how they work together makes both more effective.

How auto-memory works

When you work with Claude Code on a project, Claude automatically saves useful information it discovers to a memory directory:

~/.claude/projects/{project-path}/memory.md

This happens behind the scenes. As Claude explores your codebase, runs commands, and learns about your project's patterns, it writes those learnings to its memory file. The next time you start a conversation in the same project, Claude loads this memory and starts with context from previous sessions.

Good to know
Auto-memory is personal to your machine. If you switch computers or wipe your home directory, the memory is gone. For important project knowledge, always put it in CLAUDE.md (which is version-controlled) rather than relying on auto-memory.

What gets saved to memory

Auto-memory captures things like:

  • Build system quirks it discovered (e.g., "this project needs --legacy-peer-deps for npm install")
  • Architecture patterns it identified (e.g., "all database access goes through the repositoryWhat is repository?A project folder tracked by Git that stores your files along with the complete history of every change, inside a hidden .git directory. pattern in src/repos/")
  • Error solutions it found (e.g., "TypeScript build fails if you forget to run codegen first")
  • Project-specific terminology (e.g., "a 'workflow' in this codebase means a scheduled job, not a CI pipelineWhat is pipeline?A sequence of automated steps (install, lint, test, build, deploy) that code passes through before reaching production.")

Telling Claude to remember something

You can explicitly ask Claude to save something to memory:

You: "Remember that our staging environment uses a different database
      URL than production, and we always need to run migrations there
      before deploying."

Claude: *saves this to memory for future sessions*

This is useful for context that is important but does not belong in CLAUDE.md, things that are personal to your workflow or temporary.

02

CLAUDE.md vs. Memory: when to use which

These two systems serve different purposes. Choosing the right one matters.

CLAUDE.mdMemory
ScopeWhole teamIndividual developer
Version controlCommitted to gitLocal to your machine
ContentTeam conventions and standardsPersonal discoveries and preferences
MaintenanceYou write and update it manuallyClaude writes it automatically
SharingEveryone on the team gets itOnly you benefit

Use CLAUDE.md for:

  • Tech stack and architecture decisions
  • Build, test, and deploy commands
  • Coding conventions the whole team follows
  • Project structure overview
  • Do/Don't rules that apply to everyone

Use memory for:

  • Personal workflow preferences ("I like verbose git commitWhat is commit?A permanent snapshot of your staged changes saved in Git's history, identified by a unique hash and accompanied by a message describing what changed. messages")
  • Temporary context ("we are migrating from Prisma to Drizzle this sprint")
  • Discoveries about the codebase that are not conventions ("the auth moduleWhat is module?A self-contained file of code with its own scope that explicitly exports values for other files to import, preventing name collisions. has a quirky initialization order")
  • Environment-specific notes ("my local DockerWhat is docker?A tool that packages your application and all its dependencies into a portable container that runs identically on any machine. setup uses port 5433 for Postgres")
03

User-level settings

The user-level CLAUDE.md at ~/.claude/CLAUDE.md is a middle ground between team CLAUDE.md and personal memory. Use it for preferences that apply across all your projects:

markdown
# ~/.claude/CLAUDE.md

## My preferences
- Keep responses concise, skip unnecessary explanations
- When suggesting changes, show the diff format
- Always run tests after making changes
- Use American English for comments and documentation

## My editor setup
- I use VS Code with Vim keybindings
- Terminal is iTerm2 with zsh
- I prefer to see file paths relative to project root

These preferences follow you from project to project without being imposed on your teammates.

AI pitfall
Auto-memory can accumulate outdated information. If Claude learned that "the project uses Jest" three months ago but you've since migrated to Vitest, the stale memory can cause Claude to generate Jest-style tests. Periodically review your memory files at ~/.claude/projects/ and delete outdated entries.
Edge case
If two developers on the same team have different user-level CLAUDE.md preferences (e.g., one prefers tabs, the other spaces), Claude will generate different code for each person, even on the same project. The project-level CLAUDE.md overrides user preferences for project-specific rules, but only if the rule is explicitly stated there.
04

Maintaining CLAUDE.md over time

A CLAUDE.md that was accurate six months ago might be misleading today. Here is how to keep it useful.

Review quarterly

Set a reminder to review your CLAUDE.md every few months. Check for:

  • Outdated stack references. Did you switch from Jest to Vitest? Update the commands.
  • Removed conventions. Did you drop the rule about CSS modules? Remove it.
  • New tools. Did you add a linterWhat is linter?A tool that scans your code for style violations, common mistakes, and suspicious patterns without running it. or formatter? Add the command.

Update after major changes

Certain events should immediately trigger a CLAUDE.md update:

  • Major dependencyWhat is dependency?A piece of code written by someone else that your project needs to work. Think of it as a building block you import instead of writing yourself. upgrade (e.g., Next.js 14 to 15), update the stack section
  • New team convention (e.g., adopted conventional commitsWhat is conventional commits?A commit message format (e.g., feat:, fix:, chore:) that standardizes history and enables automated tooling like changelogs.), add the rule
  • Architecture change (e.g., moved from RESTWhat is rest?An architectural style for web APIs where URLs represent resources (nouns) and HTTP methods (GET, POST, PUT, DELETE) represent actions on those resources. to GraphQLWhat is graphql?A query language for APIs where clients specify the exact shape of data they need in a single request, avoiding over-fetching and under-fetching.), update the structure section
  • New team member onboarding: if they needed something explained that Claude would too, add it

Pruning

Over time, CLAUDE.md files accumulate rules. Some become unnecessary:

  • Rules about tools you no longer use
  • Overly specific rules that Claude has learned through memory
  • Rules that duplicate what is now obvious from the codebase itself

Remove these. A shorter CLAUDE.md is a better CLAUDE.md because it leaves more context windowWhat is context window?The maximum amount of text an AI model can consider at once, including your conversation history and any files it has read. for your actual work.

EventCLAUDE.md actionMemory action
Major dependency upgradeUpdate stack sectionClears automatically over time
New team conventionAdd a Do/Don't ruleN/A (team-wide, use CLAUDE.md)
Personal workflow discoveryDon't addTell Claude to "remember this"
Temporary project contextDon't addTell Claude to "remember this"
Quarterly reviewRemove outdated rulesDelete stale memory files
05

Tips for maximum effectiveness

1. Test with fresh conversations

The best way to validate your CLAUDE.md is to start a brand new conversation and give Claude a task. If Claude makes a mistake that your CLAUDE.md should have caught, the instructions need improvement.

2. Be specific about what "right" looks like

Instead of "follow our coding style", show an example:

markdown
## API endpoint pattern
Every endpoint follows this structure:
1. Validate input with Zod schema
2. Check authorization
3. Execute business logic
4. Return standardized response

Example:
typescript

export async function createUser(req: Request) {

const input = CreateUserSchema.parse(req.body); // 1. validate

await requireAdmin(req); // 2. authorize

const user = await userService.create(input); // 3. execute

return ok({ user }); // 4. respond

}

3. Use the same language as your codebase

If your team calls things "services", do not call them "controllers" in CLAUDE.md. If your database tables are called "organizations" not "teams", use the correct term. Consistency reduces confusion.

4. Coordinate with your team

CLAUDE.md is committed to git. Treat it like any other team document:

  • Review changes in pull requests
  • Discuss new rules in team meetings
  • Let team members propose additions based on their own experiences with Claude

The best CLAUDE.md files reflect collective team knowledge, not just one person's preferences.