Claude Code Context Memory: 3 Practical Fixes
In this article
Claude Code sometimes forgets project context between sessions, forcing you to re-explain your architecture, conventions, and goals. This guide covers three practical fixes to make Claude Code remember project context reliably, improving continuity and reducing repetitive setup.
What You'll Need
- Claude Code installed and authenticated (any recent version).
- Access to your project's root directory in a terminal.
- Basic familiarity with editing files (like README or config files).
Step-by-Step
Fix 1: Use a CLAUDE.md File
- Open your terminal and navigate to your project's root directory.
- Create a file named
CLAUDE.md(exact name and capitalization) in the root. - Add essential project context: a brief description, tech stack, architecture overview, coding conventions, and any critical commands (build, test, run).
- Keep it concise—aim for under 200 lines. Claude Code reads this file automatically at the start of each session.
- Place project-specific instructions in this root file. For subdirectories, you can add additional
CLAUDE.mdfiles, which are loaded when working in those folders. - Test it: start a new session and ask a question about your project's structure. Claude should reference the file's content.
Fix 2: Create a Custom Instructions File
- Create a file named
CLAUDE.mdin your home directory (~on Mac/Linux,%USERPROFILE%on Windows). - Add global preferences that apply to all your projects—e.g., “Always use TypeScript for new files,” or “Prefer functional components.”
- Save the file. Claude Code automatically loads this as a base instruction set for every session, regardless of project.
- Combine this with a project-level
CLAUDE.mdfor best results: the home file sets your style, the project file adds specifics.
Fix 3: Use the /memory Command (if available)
- In a Claude Code session, type
/memoryand press Enter. - Review the list of memory entries. If the command is unsupported, skip to the alternative below.
- Add a new memory entry with a key piece of context, like “The database is PostgreSQL, accessed via Prisma.”
- To recall a memory, simply ask Claude about it—it will automatically use stored memories.
- If
/memoryis not available, use the CLAUDE.md approach (Fix 1) instead, as it's the most reliable and widely supported method.
Common Mistakes
- Putting too much detail in CLAUDE.md—Claude may ignore or miss key points if it's overly long.
- Using wrong file name (like
claude.mdorCLAUDE.txt)—the file must be exactlyCLAUDE.md. - Placing project-specific info in the home CLAUDE.md, causing it to apply to all projects incorrectly.
- Forgetting to update CLAUDE.md when project conventions change.
Tips
- Use CLAUDE.md as a living document: update it whenever you make significant architectural decisions.
- Include examples in CLAUDE.md—showing a sample function or file structure helps Claude follow patterns.
- For large projects, break CLAUDE.md into sections with clear headings so Claude can quickly find relevant info.
- If you use multiple branches, keep CLAUDE.md in version control so all team members benefit.
Troubleshooting
If Claude still seems to forget context:
- Verify the file name is exactly
CLAUDE.md(case-sensitive). Usels -lato confirm. - Check that you're in the correct directory—Claude loads CLAUDE.md from the current working directory.
- Restart Claude Code completely after creating or editing CLAUDE.md.
- If using the home file, ensure it's in your actual home directory, not a subfolder.
- Try asking Claude directly: “What do you know about this project?” to see what it has loaded.
- If nothing works, check Claude Code's documentation for the latest supported memory features, as they may have changed.
Frequently Asked Questions
Does Claude Code automatically read CLAUDE.md?
Yes, Claude Code automatically loads CLAUDE.md from the project root at the start of each session, using it as context.
Can I have multiple CLAUDE.md files?
Yes, you can place CLAUDE.md files in subdirectories. Claude Code loads the root file and any subdirectory files relevant to the current working directory.
What's the difference between home and project CLAUDE.md?
The home CLAUDE.md applies globally to all projects, while the project CLAUDE.md is specific to that project. Both are loaded, with project-level taking precedence for conflicting instructions.
Is there a size limit for CLAUDE.md?
There's no strict limit, but keeping it under 200 lines is recommended to ensure Claude processes it effectively.
Will this work with Claude Code on Windows?
Yes, the same file structure works on Windows. Place the home CLAUDE.md in your user profile directory.
Can I use environment variables in CLAUDE.md?
Yes, you can reference environment variables, but they won't be expanded automatically. It's better to state the variable name and its purpose.