The Claude Code Memory Stack: CLAUDE.md, Skills, Auto-Memory, and Session Resume
Claude Code's persistent context system has grown well beyond three documents. Today it operates as a five-layer memory stack — managed policy, personal and project CLAUDE.md files, on-demand Skills, AI-written auto-memory, and session resume — each layer serving a distinct purpose and loading at a different point in the session lifecycle.
Primary Focus
ai developmentAI Tools Covered
What You'll Learn
- ✓What is CLAUDE.md?
- ✓Crafting an Effective CLAUDE.md
- ✓Critical Rules
- ✓Structuring for Scalability
- ✓Quick Reference (READ FIRST)
- ✓Database & Deployment
Guide Curriculum
Understanding CLAUDE.md: Your Project's Blueprint
- •What is CLAUDE.md?12m
- •Crafting an Effective CLAUDE.md12m
Critical Rules
- **Database Queries**: Use `npm run convex:prod` (NEVER `export CONVEX_DEPLOYMENT=...`) - **Logging**: Use `lib/logger.ts` not `console.log` in production code - **Content**: ONLY use `/content` command for content operations - **Testing**: Always run `npm run playwright:cleanup` after tests
- •Critical Rules12m
Code Patterns
- Components: Use `cn()` for className merging, typed props - Mutations: Validate inputs, wrap in try/catch, return `{success, id/data}` - API Routes: Check `userId` with Clerk, proper HTTP status codes ```
- •Structuring for Scalability12m
Quick Reference (READ FIRST)
- Platform: vybecoding.ai (always lowercase) - Branch: main (single branch workflow) - Database: modest-lobster-37
- •Quick Reference (READ FIRST)12m
Database & Deployment
[details]
- •Database & Deployment12m
Testing
[details]
- •Testing12m
Security
[details] ```
- •Security12m
Memory Files: Persistent Context Across Sessions
- •How Memory Works12m
- •Types of Memory12m
- •The Memory Index12m
User
- [user_role.md](user_role.md) -- Backend engineer, new to React
- •User12m
Feedback
- [feedback_testing.md](feedback_testing.md) -- Use real DB in integration tests, not mocks
- •Feedback12m
Project
- [project_sprint.md](project_sprint.md) -- Sprint 7 completed, merge freeze Mar 5 ``` Keep `MEMORY.md` concise, ideally under 200 lines, with each entry succinctly described.
- •Project12m
Slash Commands: Automating Reusable Workflows
- •What Are Slash Commands?12m
- •Creating Your First Command12m
- •Advanced Command Patterns12m
Putting It All Together: The Context Stack in Practice
When you initiate a Claude Code session, the context stack loads in the following order: 1. **CLAUDE.md**: Provides project rules and conventions. 2. **MEMORY.md**: Loads indexed memories. 3. **Relevant Memories**: Loaded based on the conversation's context. 4. **Slash Commands**: Available for invocation as needed.
- •Before and After Context Documents12m
Summary: Key Takeaways
The three context layers—CLAUDE.md, Memory Files, and Slash Commands—work synergistically to enhance Claude's utility: | Layer | File | Scope | Purpose | |-------|------|-------|---------| | CLAUDE.md | Project root | All sessions | Project rules and conventions | | Memory | ~/.claude/projects/*/memory/ | Across sessions | Persistent preferences and context | | Commands | .claude/commands/ | On demand | Reusable workflows |
- •Getting Started Today12m
The Full Memory Stack: Beyond Three Documents
- •The Full Memory Stack: Beyond Three Documents12m
Preview: First Lesson
Understanding CLAUDE.md: Your Project's Blueprint
What is CLAUDE.md?
Think of CLAUDE.md as your project's personalized README for Claude. This markdown file, located at the root of your project, serves as a comprehensive guide that Claude reads at the start of every session. It outlines your project's architecture, coding conventions, and critical rules, ensuring that Claude's actions align with your specific requirements.
Example: With and Without CLAUDE.md
Without CLAUDE.md:
You: "Add a new API route for user profiles" Claude: *creates a generic Express.js route with console.log*
With CLAUDE.md:
You: "Add a new API route for user profiles" Claude: *creates a Next.js API route using Clerk auth, Convex queries, and lib/logger.ts—matching your exact stack*
With CLAUDE.md, Claude tailors its actions to your tech stack, authentication methods, and logging practices.
Start learning with this comprehensive guide
This guide includes:
About the Author
Hiram Clark is the founder and managing editor of vybecoding.ai and sets editorial direction for the guides and news published here. Articles are drafted with AI assistance and edited before publication. He works hands-on with the AI development tools, workflows, and infrastructure covered on the site.
Full Guide Content
Complete lesson text — start the interactive course above for exercises and progress tracking.
Module 1Understanding CLAUDE.md: Your Project's Blueprint
1.1What is CLAUDE.md?
Think of CLAUDE.md as your project's personalized README for Claude. This markdown file, located at the root of your project, serves as a comprehensive guide that Claude reads at the start of every session. It outlines your project's architecture, coding conventions, and critical rules, ensuring that Claude's actions align with your specific requirements.
Example: With and Without CLAUDE.md
Without CLAUDE.md:You: "Add a new API route for user profiles"
Claude: *creates a generic Express.js route with console.log*
With CLAUDE.md:
You: "Add a new API route for user profiles"
Claude: *creates a Next.js API route using Clerk auth, Convex queries, and lib/logger.ts—matching your exact stack*
With CLAUDE.md, Claude tailors its actions to your tech stack, authentication methods, and logging practices.
1.2Crafting an Effective CLAUDE.md
A well-crafted CLAUDE.md should include:
- Tech Stack and Architecture: Specify frameworks, databases, and authentication providers.
- Code Conventions: Define naming conventions, file structures, and import patterns.
- Critical Rules: Highlight non-negotiable practices, such as avoiding
console.login production. - Common Tasks: Describe deployment processes, testing protocols, and feature addition guidelines.
Real-World Example from vybecoding.ai
```markdown
Module 2Critical Rules
2.1Critical Rules
- Database Queries: Use
npm run convex:prod(NEVERexport CONVEX_DEPLOYMENT=...) - Logging: Use
lib/logger.tsnotconsole.login production code - Content: ONLY use
/contentcommand for content operations - Testing: Always run
npm run playwright:cleanupafter tests
Module 3Code Patterns
3.1Structuring for Scalability
As your project grows, so should your CLAUDE.md. Organize it with clear sections and a quick-reference header to ensure essential rules are easily accessible:
```markdown
Claude Code Development Guide
Module 4Quick Reference (READ FIRST)
4.1Quick Reference (READ FIRST)
- Platform: vybecoding.ai (always lowercase)
- Branch: main (single branch workflow)
- Database: modest-lobster-37
Module 5Database & Deployment
5.1Database & Deployment
[details]
Module 6Testing
6.1Testing
[details]
Module 7Security
7.1Security
[details]
```
Module 8Memory Files: Persistent Context Across Sessions
8.1How Memory Works
Memory files are stored at ~/.claude/projects/ and provide conversation-level context that persists across sessions. Unlike CLAUDE.md, which is project-wide, memory files capture personal and project-specific nuances that Claude recalls automatically.
Example: With and Without Memory
Without Memory:Session 1: "I'm a backend engineer, new to React"
Session 2: "How do I add a component?"
Claude: *explains from scratch, doesn't know your background*
With Memory:
Session 1: "I'm a backend engineer, new to React"
Claude: *saves to memory: user is backend engineer, new to React*
Session 2: "How do I add a component?"
Claude: *explains React components using backend analogies, skips basics they'd already know*8.2Types of Memory
Claude supports several memory types, each serving a unique purpose:
- User Memory: Captures your role, preferences, and expertise level.
- Feedback Memory: Records corrections and confirmed approaches.
- Project Memory: Maintains ongoing work context.
- Reference Memory: Points to external resources.
Each memory file includes frontmatter for clarity:
---
name: user_role
description: User's role and technical background
type: user
---
Backend engineer with 10 years of Go experience.
New to React and this project's frontend.
Frame frontend explanations using backend analogies.8.3The Memory Index
All memories are indexed in MEMORY.md, which Claude uses to decide which memories to load:
```markdown
Project Memory Index
Module 9User
9.1User
- user_role.md -- Backend engineer, new to React
Module 10Feedback
10.1Feedback
- feedback_testing.md -- Use real DB in integration tests, not mocks
Module 11Project
11.1Project
- project_sprint.md -- Sprint 7 completed, merge freeze Mar 5
``
Keep MEMORY.md` concise, ideally under 200 lines, with each entry succinctly described.
Module 12Slash Commands: Automating Reusable Workflows
12.1What Are Slash Commands?
Slash commands are markdown files located in .claude/commands/ that function as reusable prompt templates. They allow you to execute complex instructions with a simple command, streamlining repetitive tasks.
Example: With and Without Slash Commands
Without Slash Commands:You: "Check all TypeScript files for console.log statements, verify no any types exist, run the linter, check for security issues, then summarize findings in a table..."
With Slash Commands:
You: /code-review
Claude: *runs the full review workflow automatically*12.2Creating Your First Command
To create a command, save a markdown file in .claude/commands/:
# Code Review
Review the current changes for quality issues:
1. Run `npx tsc --noEmit` and report errors
2. Search for `console.log` in modified files
3. Search for `: any` type annotations
4. Check for hardcoded secrets or API keys
5. Verify error handling in new functions
Output a summary table:
| Check | Status | Details |
|-------|--------|---------|
Invoke it with /code-review in any session.
12.3Advanced Command Patterns
Commands can be parameterized, reference other files, and chain together for more complex workflows:
Parameterized Command (.claude/commands/deploy.md):
# Deploy
Deploy changes to production:
1. Run `npm run typecheck`
2. Run `npm run test:safe`
3. Commit with descriptive message
4. Push to main
5. Verify deployment at $1 (URL argument)
Invoke with: /deploy https://vybecoding.ai
# Sprint Status
Read `docs/sprints/current-sprint.md` and report:
- Stories completed vs total
- Blocked items and reasons
- Estimated completionModule 13Putting It All Together: The Context Stack in Practice
13.1Before and After Context Documents
- Each session starts from scratch.
- Repetitive instructions are necessary.
- Claude may repeat mistakes.
- Workflows are inconsistent.
- Claude understands your project from the outset.
- Preferences persist across sessions.
- Mistakes are corrected once and remembered.
- Workflows are standardized and repeatable.
The investment in creating these documents is minimal, yet the benefits are substantial. Every interaction with Claude becomes more efficient and tailored to your needs.
Module 14Summary: Key Takeaways
14.1Getting Started Today
- Create a
CLAUDE.mdat your project root with your tech stack and top 5 rules. - In your next Claude Code session, share something about yourself to initiate memory storage.
- Identify a frequently repeated workflow and convert it into a
.claude/commands/file. - Continuously iterate and refine your context documents based on real-world usage.
By leveraging these tools, you empower Claude to become a more effective collaborator, streamlining your development process and enhancing productivity.
Module 100The Full Memory Stack: Beyond Three Documents
100.1The Full Memory Stack: Beyond Three Documents
The Full Memory Stack: Beyond Three Documents
The three-document model (CLAUDE.md, Skills, memory files) is the foundation. But Claude Code in 2026 has a fuller memory stack — and understanding all five layers helps you build agents that maintain meaningful context across sessions, across projects, and across time.
The Five-Layer Memory Stack
Layer 1: CLAUDE.md (Project Rules)Loaded into every context window for the project. Covers constraints, commands, conventions, and tooling patterns. Scoped to the project directory.
- Optimal size: 1,000–3,000 words
- Decay rate: Low (review quarterly)
- Audience: Claude working in this specific project
Structured workflows in .claude/skills/. Loaded on demand via /skill-name. Covers multi-step procedures, tool sequences, decision trees.
- Optimal size: 200–800 words per skill
- Decay rate: Medium (update when workflow changes)
- Audience: Claude executing a specific type of task
Files in ~/.claude/projects/. Written by Claude during sessions when you say "remember this." Recalled at session start. Covers user preferences, project state, recurring facts.
- Optimal size: Unlimited (but prune regularly)
- Decay rate: Variable — actively prune stale entries
- Audience: Claude across all sessions for this project
/memory Command
Direct memory management via /memory in the Claude Code CLI. Lists current memories, shows what's loaded, lets you delete or edit entries.
/memory list # Show all active memories
/memory delete # Remove a specific memory
/memory search RAG # Find memories mentioning RAG
Use /memory list before starting a complex task to confirm Claude has the right context. Use /memory delete to remove stale or incorrect memories that might bias Claude's behavior.
Claude Code can resume a previous session with full context. Use claude --resume or /resume in the CLI. Session context includes the full conversation history, tool outputs, and file state from the previous run.
- Use case: Long research tasks, multi-day implementation work
- Limit: Sessions expire after 30 days of inactivity
- Gotcha: Resuming a session bypasses auto-memory loading (session memory supersedes)
Auto-Memory in Practice
Auto-memory is the most powerful layer for building agents that improve over time. When Claude learns something useful about your project, workflow, or preferences during a session, it can save that as a memory file.
What Claude saves automatically (if configured):- User preferences ("user prefers TypeScript over JavaScript")
- Project patterns ("this project uses 0-based indexing for module orders")
- Recurring facts ("the production DB ID is modest-lobster-37")
- Non-obvious decisions ("we decided to use soft-delete instead of hard-delete because of the audit requirement")
- Debugging solutions that aren't obvious from code ("if the Convex deploy fails with this error, run npx convex codegen first")
- External system mappings ("the Linear project INGEST is where pipeline bugs are tracked")
"Remember this for future sessions: [fact]"
"Save this to memory: [decision + reasoning]"
"Keep this context: [project state]"
Claude writes the memory to a structured file with metadata and updates the MEMORY.md index. You can verify with /memory list.
Avoiding Memory Bloat
Memory files accumulate over time. Bloated memory slows context loading and can introduce conflicting information.
Prune quarterly:- Run
/memory listto see all entries - Delete memories that are project-specific and the project is done
- Delete memories that conflict with current code state
- Consolidate multiple related memories into one
- Date-stamp important project-state memories ("as of April 2026, the schema uses...")
- Include a "why" for non-obvious decisions
- Don't save things that are evident from code (code is always fresher than memory)
The Session Resume Pattern for Long Tasks
For multi-day implementation tasks:
Session 1: Start the task, let Claude build context, complete Phase 1.claude "Design and implement the database schema for the billing system"
End of session: Claude saves progress notes to memory if configured.
Session 2: Resume with full context.
claude --resume "Continue from where we left off — implement the API layer on top of the schema"
Session resume is more reliable than re-establishing context via a fresh session for tasks with complex intermediate state. Use it for tasks that span more than 2 hours or involve more than 20 files.
The /memory Command Deep Dive
# See what's loaded in your current context
/memory list
# Search for specific memories
/memory search "production database"
# Edit a memory (opens in $EDITOR)
/memory edit
# Delete stale memories
/memory delete
# Export memories for sharing or backup
/memory export > project-memories-2026-04.md
# Import memories (e.g., from a teammate)
/memory import teammate-memories.md
The /memory command is your control plane for the auto-memory layer. Checking it before starting complex tasks ensures Claude has the right foundational context — and isn't working from outdated information that memory files might contain.