Skip to content

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 discussion
User1: "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:

Terminal window
# Create memory directory
mkdir -p ~/.claude/memory
# Create memory files
touch ~/.claude/memory/user-preferences.md
touch ~/.claude/memory/project-context.md
touch ~/.claude/memory/decisions.md
touch ~/.claude/session-journal.md

Step 2: Add write-before-speak rule

I created a rule file that forces Claude to write before claiming to remember:

.claude/rules/memory-persistence.md
# Persistent Memory Rule
CRITICAL: When user shares preferences, context, or decisions:
1. STOP responding immediately
2. 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.md
3. 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 files
2. Confirm what you remember
3. Ask if anything needs updating

Step 3: Test the new system

Here’s what happened when I tried again:

# Session 1
Me: "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:

.claude/rules/auto-load-memory.md
# Auto-Load Memory Rule
When a new session starts:
1. Read ~/.claude/memory/user-preferences.md
2. Read ~/.claude/memory/project-context.md
3. Read ~/.claude/memory/decisions.md
4. Summarize what you remember
5. Ask: "Is anything outdated? Should I update any of these files?"

Step 5: Practical example - project context

Here’s my actual project context file:

.claude/memory/project-context.md
# 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 Istio

Now 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:

  1. No built-in persistent memory: Each conversation is completely isolated
  2. Misleading language: When Claude says “I’ll remember,” it means within the current session only
  3. Session isolation: When you close a conversation, all context is wiped

The write-before-speak pattern works because:

  1. Disk persists: Files survive session endings
  2. Explicit action: Writing forces Claude to actually save, not just claim it will
  3. 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:

  1. Create dedicated memory files (preferences, context, decisions)
  2. Add a rule that forces writes before “I’ll remember” statements
  3. 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