How to Set Up Memory Files in Claude Code for Persistent Context
Problem
I was working on a complex e-commerce project with Claude Code. Midway through implementing the checkout flow, Claude started suggesting patterns that contradicted decisions we’d made hours earlier. It forgot we were using Stripe, not PayPal. It proposed MongoDB queries for a PostgreSQL database. The context was gone.
This is the biggest frustration with Claude Code: losing context mid-task. Long sessions, complex projects — Claude just loses the thread.
Environment
- Claude Code CLI
- Complex multi-file project
- Long development sessions (2+ hours)
- Multiple context switches between files
What Happened
I’d start a session, explain the project structure, coding conventions, and current status. Claude would work great for a while. Then, as the session grew longer and we touched more files, Claude would:
- Forget earlier decisions (using Stripe, not PayPal)
- Miss established patterns (API response format)
- Propose solutions we’d already rejected
- Require constant re-explanation of project state
Each new session meant starting from scratch. I was wasting tokens on repetitive context-setting.
Then I discovered memory files.
Solution
Memory files are persistent reference files that Claude reads at the start of every session. Create a MEMORY.md file in your project root with project structure, conventions, current build status, and decisions made.
Here’s what I created:
# Project: E-commerce Platform
## Structure- /src/components - React components- /src/api - Backend routes- /src/utils - Shared utilities
## Conventions- Use TypeScript strict mode- Test files next to source files- API responses: { success, data?, error? }
## Current Status- Building checkout flow- Known issue: payment timeout on slow networks
## Decisions- 2024-01-15: Using Stripe over PayPal (lower fees)- 2024-01-20: PostgreSQL over MongoDB (relational data)Now Claude reads this file at session start. No more re-explaining. No more forgotten decisions.
Advanced Pattern: Daily Logs
The community shared an even better pattern: split memory into dated daily logs and a curated main file.
## Session Notes- Fixed race condition in cart component- Discovered: useEffect needs cleanup on unmount- TODO: Add error boundary to checkout
## Gotchas- Stripe webhook needs raw body, not parsed JSONThis prevents the main MEMORY.md from bloating. Raw notes go in daily logs; curated long-term context stays in MEMORY.md.
Reason
Why does this work?
Claude reads memory files at session start. It’s like having a briefing document that persists across sessions. Instead of burning tokens on context-setting, Claude starts with the project state already loaded.
The 200-line limit is real. As one Reddit user noted: “Memory is maximum 200 lines. Everything after that is not read.” This is why splitting into daily logs matters. Keep MEMORY.md lean and focused on long-term context.
It creates institutional memory. For long-running projects, you build up a knowledge base of decisions, gotchas, and patterns. New sessions start with all that context available.
Summary
Memory files solve Claude’s context loss by providing a persistent briefing document. The key practices:
- Create
MEMORY.mdin project root - Keep it under 200 lines (hard limit)
- Use dated daily logs for raw notes
- Curate main
MEMORY.mdfor long-term context - Update before compression events occur
No more forgotten decisions. No more wasted tokens on re-explanation. Just persistent context across sessions.
Final Words + More Resources
My intention with this article was to help others share my knowledge and experience. If you want to contact me, you can contact by email: Email me
Here are also the most important links from this article along with some further resources that will help you in this scope:
Oh, and if you found these resources useful, don’t forget to support me by starring the repo on GitHub!
Comments