Why Does Claude Code Forget Things Between Sessions? (And How to Fix It)
Problem
I kept running into this frustrating situation with Claude Code:
# Session 1 (Monday morning)Me: "I prefer functional components with hooks, never use class components"Claude: "Got it! I'll remember that for future code."[I continue working, close the session]
# Session 2 (Tuesday morning)Me: "Create a new component for the user profile"Claude: [Creates a class component with componentDidMount()]Me: "I told you yesterday I prefer functional components!"Claude: "I apologize, I don't recall that conversation."Every time Claude said “I’ll remember this” or “I’ve noted that,” it would forget by the next session. I searched Reddit and found dozens of other developers dealing with the same issue:
# From r/ClaudeCode discussionUser1: "Claude will say 'I'll remember this' and then forget. Every time."User2: "I've stopped believing when Claude says it'll keep something in mind."User3: "Is there a way to make Claude actually remember preferences?"The problem was clear: Claude Code has no persistent memory between sessions.
Environment
- Claude Code (latest version)
- Working across multiple sessions
- Looking for session-to-session context retention
What happened?
I needed Claude to remember my coding preferences across days or weeks of work. Here’s what I tried:
First attempt: Just telling Claude explicitly
Me: "Here are my preferences:- Use functional components, never classes- Prefer TypeScript over JavaScript- Follow atomic design pattern- Always write tests first (TDD)
Please remember these for all future sessions."
Claude: "Absolutely! I've noted all these preferences and will keep them in mind for our future work together."Next day:
Me: "Create a new button component"Claude: [Creates JavaScript class component without tests]Second attempt: Asking Claude to summarize
Me: "Before we finish, can you write a summary of what you learned about my preferences?"
Claude: "Sure! Here's what I'll remember:- You prefer functional components- You use TypeScript- You follow atomic design- You want TDD approach
I'll keep this in mind for next time!"Next day:
Me: "Continue working on the dashboard"Claude: "I'd be happy to help! What's the project about?"Same problem. The verbal commitment meant nothing.
How to solve it?
The issue is that Claude Code sessions are completely isolated. When a session ends, all context is wiped. The only way to achieve persistent memory is to force Claude to write important information to disk before the session ends.
I found the solution in a Reddit discussion: implement a write-before-speak rule. If Claude says it will remember something, it must first write that thing to a file.
Step 1: Create memory files
First, I set up dedicated files for different types of memory:
# Create memory directorymkdir -p ~/.claude/memory
# Create memory filestouch ~/.claude/memory/user-preferences.mdtouch ~/.claude/memory/project-context.mdtouch ~/.claude/memory/decisions.mdtouch ~/.claude/session-journal.mdStep 2: Add write-before-speak rule
I created a rule file that forces Claude to write before claiming to remember:
# Persistent Memory Rule
CRITICAL: When user shares preferences, context, or decisions:1. STOP responding immediately2. Write the information to the appropriate file: - User preferences → ~/.claude/memory/user-preferences.md - Project context → ~/.claude/memory/project-context.md - Decisions made → ~/.claude/memory/decisions.md3. THEN continue the conversation
NEVER say "I'll remember" or "I've noted" without actually writing to a file.
At session start:1. Read all memory files2. Confirm what you remember3. Ask if anything needs updatingStep 3: Test the new system
Here’s what happened when I tried again:
# Session 1Me: "I prefer functional components with hooks, never use class components"
Claude: [Reads the memory-persistence rule] [Uses Write tool to update ~/.claude/memory/user-preferences.md] "Got it! I've saved that to your preferences file. You can see I wrote it to disk, so it'll persist across sessions."
# What Claude wrote:```markdown title=".claude/memory/user-preferences.md"# User Preferences
Last updated: 2025-02-05
## React Preferences- Use functional components with hooks- NEVER use class components- Prefer hooks over HOCs
## Language- TypeScript over JavaScript- Strict mode enabled
## Testing- TDD approach: write tests first- 80% minimum coverage# Session 2 (next day)Claude: [At session start, automatically reads ~/.claude/memory/user-preferences.md] "Good morning! I can see from your preferences file that you prefer functional components with hooks and follow TDD. Ready to continue!"
Me: "Create a new user profile component"
Claude: [Creates functional component with TypeScript, includes tests] "Here's your functional component with hooks. I also wrote the tests first following your TDD preference."It worked! The key difference: Claude actually wrote to disk before claiming to remember.
Step 4: Add automated memory loading
I created another rule to auto-load memory at session start:
# Auto-Load Memory Rule
When a new session starts:1. Read ~/.claude/memory/user-preferences.md2. Read ~/.claude/memory/project-context.md3. Read ~/.claude/memory/decisions.md4. Summarize what you remember5. Ask: "Is anything outdated? Should I update any of these files?"Step 5: Practical example - project context
Here’s my actual project context file:
# Project Context: E-commerce Backend
## Tech Stack- Node.js with Express- PostgreSQL database (v15)- Redis for caching- Docker deployment on AWS
## Coding Standards- Use async/await, never callbacks- All routes must have error handling- Follow RESTful conventions- Write tests before implementation (TDD)- 80% minimum test coverage
## Current Focus- Migrating from monolith to microservices- API response time must be < 200ms- Must maintain backward compatibility
## Recent Decisions- 2025-01-15: Chose Redis over Memcached for pub/sub support- 2025-01-20: Adopted GraphQL for new features (REST still used for legacy)- 2025-02-01: Implemented service mesh with IstioNow when I start a new session, Claude reads this and immediately understands:
- What tech stack I’m using
- What my coding standards are
- What I’m currently working on
- What decisions we’ve made
No more repeating context every session.
The reason
Claude Code forgets between sessions because:
- No built-in persistent memory: Each conversation is completely isolated
- Misleading language: When Claude says “I’ll remember,” it means within the current session only
- Session isolation: When you close a conversation, all context is wiped
The write-before-speak pattern works because:
- Disk persists: Files survive session endings
- Explicit action: Writing forces Claude to actually save, not just claim it will
- Auto-loading: Rules ensure Claude reads memory at session start
Without this system:
- You repeat yourself constantly
- Claude forgets your project structure
- Previous decisions are lost
- You waste time re-explaining context
With file-based memory:
- Claude reads your preferences at session start
- Important decisions are documented
- Project context persists
- You get continuity across weeks or months
Summary
In this post, I showed how to fix Claude Code’s memory problem using a file-based memory system with write-before-speak rules. The key point is that Claude has no persistent memory by default—you must force it to write important information to disk before claiming to remember it.
The solution:
- Create dedicated memory files (preferences, context, decisions)
- Add a rule that forces writes before “I’ll remember” statements
- Auto-load memory files at session start
Now Claude actually remembers across sessions, and I don’t waste time repeating context.
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