memory-management
Optimizes Claude Code's native auto-memory management. Keeps MEMORY.md as a concise index under 200 lines with topic-based file organization and grep-first recall. Use when setting up memory for a new project or improving existing memory structure.
Front matter
name: memory-management
description: Optimizes Claude Code's native auto-memory management. Keeps MEMORY.md as a concise index under 200 lines with topic-based file organization and grep-first recall. Use when setting up memory for a new project or improving existing memory structure.Memory Management Skill for Claude Code
Add this to your project's CLAUDE.md to optimize how Claude manages its native auto-memory.
Core Principle
MEMORY.md is an INDEX, not a dump.
The first 200 lines of MEMORY.md are loaded into the system prompt at session start. Everything beyond line 200 is invisible until manually read. Topic files are never auto-loaded—Claude must read them on-demand.
Rule: MEMORY.md must NEVER exceed 200 lines.
Memory Architecture
~/.claude/projects/<project>/memory/
├── MEMORY.md # Index only (< 200 lines)
├── debugging.md # Bug solutions, error patterns
├── architecture.md # System design, module relationships
├── patterns.md # Code conventions, style decisions
├── commands.md # Build, test, deploy commands
├── gotchas.md # Known issues, workarounds
├── dependencies.md # Package notes, version constraints
└── decisions.md # Why we chose X over YMEMORY.md Template
# Project Memory Index
<!-- LINE COUNT: Keep under 200 lines -->
## Quick Commands
- Dev: `[command]`
- Test: `[command]`
- Build: `[command]`
- Deploy: See →debugging.md
## Key Entry Points
- Main: `[path]`
- Config: `[path]`
- Types: `[path]`
## Topic Pointers
- Debugging solutions → `debugging.md`
- Architecture notes → `architecture.md`
- Code patterns → `patterns.md`
- Known issues → `gotchas.md`
## Active Context
- Current work: [brief description]
- Blocked by: [if any]
- Next: [priority items]
## Core Patterns (only critical ones)
- [Pattern 1]: [one-line description]
- [Pattern 2]: [one-line description]Memory Operations
When to Write to MEMORY.md (Index)
- New critical command discovered
- Key file location identified
- New topic file created (add pointer)
- Major project pattern established
When to Write to Topic Files
- Bug solution found →
debugging.md - Architecture decision made →
architecture.md - Code convention established →
patterns.md - Gotcha/workaround discovered →
gotchas.md - Dependency note needed →
dependencies.md
Topic File Format
## [Topic/Date]
**Context:** When this applies
**Problem:** What went wrong
**Solution:** What fixed it
**Command:** `[if applicable]`Line Count Enforcement
Before writing to MEMORY.md:
wc -l ~/.claude/projects/*/memory/MEMORY.mdIf approaching 200 lines:
- Identify detailed entries that belong in topic files
- Move content to appropriate topic file
- Replace with pointer:
→ See [topic].md - Verify line count < 200
Grep Optimization
Fast Memory Search
# Search all memory files for a term
grep -r "search_term" ~/.claude/projects/<project>/memory/
# Search with context
grep -B2 -A2 "error" ~/.claude/projects/<project>/memory/debugging.md
# Find which file contains a memory
grep -l "redis" ~/.claude/projects/<project>/memory/*.mdBefore Reading Topic Files
Instead of reading entire files, grep first:
# Find relevant section
grep -n "auth" debugging.md
# Then read specific lines
sed -n '15,30p' debugging.mdMemory Audit
# Line counts across all memory files
wc -l ~/.claude/projects/<project>/memory/*.md
# Find largest files (candidates for splitting)
ls -lS ~/.claude/projects/<project>/memory/Recall Patterns
Start of Session
MEMORY.md is already in context. For deeper info:
"What do I know about [topic]?"
→ grep topic files
→ read relevant sections onlyMid-Session Recall
# Quick search before reading
grep -l "keyword" *.md
# Read only matching fileCross-Reference
When documenting, link related topics:
## Auth Fix (2024-02-26)
**Solution:** Reset Redis connection pool
**Related:** See →gotchas.md#redis-timeoutsMemory Hygiene
Weekly Audit
- Check MEMORY.md line count
- Review topic files for outdated content
- Consolidate duplicate entries
- Update pointers if files renamed
Pruning Rules
- Remove entries older than 90 days if not referenced
- Merge similar entries
- Delete solved gotchas that are now fixed in code
- Archive completed project phases
Archive Pattern
## [ARCHIVED] Old Feature
<!-- Kept for historical reference, low priority -->Anti-Patterns (Avoid)
❌ Dumping everything into MEMORY.md ❌ Exceeding 200 lines in MEMORY.md ❌ Storing code snippets (use file paths instead) ❌ Duplicate entries across files ❌ Reading entire topic files when grep suffices ❌ Forgetting to add pointers for new topic files
Quick Reference
| Action | Location | Format |
|---|---|---|
| Add command | MEMORY.md | - Name: \cmd\`` |
| Add file path | MEMORY.md | - Role: \path\`` |
| Add bug fix | debugging.md | Full context block |
| Add pattern | patterns.md | Convention + example |
| Add gotcha | gotchas.md | Problem + workaround |
| Add decision | decisions.md | Options + rationale |
Explicit Save Commands
Tell Claude directly:
- "Remember that we use pnpm, not npm"
- "Save to debugging.md: auth breaks if Redis is cold"
- "Add to patterns.md: all API routes use zod validation"
- "Update MEMORY.md: new deploy command is X"
This skill ensures Claude maintains efficient, organized memory that loads fast and stays under the 200-line system prompt limit.
Source: written by One Giant Leap.
Related entries
There are more like this in the members library
The Claude Code library holds 13,843 entries. Members can search all of them by meaning and read every one in full.