memory-instructions
# Claude Code Memory & Instructions System
What this skill does
# Claude Code Memory & Instructions System
Complete guide to CLAUDE.md, project instructions, auto-memory, and rules.
## CLAUDE.md — Project Instructions
### Purpose
CLAUDE.md files contain natural-language instructions that Claude Code loads as system context. They tell Claude about your project's conventions, build commands, architecture, and preferences.
### Hierarchy (All Additive)
```
Enterprise/Managed CLAUDE.md (highest priority, cannot be overridden)
└── User ~/.claude/CLAUDE.md (personal preferences, all projects)
└── Project ./CLAUDE.md (project conventions)
└── Project ./.claude/CLAUDE.md (additional project instructions)
└── Local ./CLAUDE.local.md (personal, gitignored)
└── Directory path/CLAUDE.md (scoped to that directory)
```
All levels are loaded and combined. Lower levels cannot override enterprise settings.
### Additional Syntax
- `@path/file.md` — Import additional files into CLAUDE.md context
- Keep under 200 lines for optimal context cost
### What to Include
```markdown
# Project Instructions
## Build & Test Commands
- Install: `pnpm install`
- Dev: `pnpm dev`
- Build: `pnpm build`
- Test: `pnpm test`
- Single test: `pnpm test -- path/to/test.ts`
- Lint: `pnpm lint`
- Type check: `pnpm typecheck`
## Code Conventions
- Language: TypeScript strict mode
- Style: Prettier + ESLint
- Imports: Use absolute paths from `@/`
- Components: Functional React with hooks
- State: Zustand for global, React Query for server
## Architecture
- Monorepo: Turborepo with packages in `packages/`
- API: Next.js API routes in `src/app/api/`
- Database: PostgreSQL with Prisma ORM
- Auth: NextAuth.js with Keycloak provider
- Deployment: Kubernetes on AWS EKS
## Key Files
- `prisma/schema.prisma` — Database schema
- `src/lib/auth.ts` — Auth configuration
- `src/lib/db.ts` — Database client
## Important Context
- We use pnpm, never npm or yarn
- Always run tests before committing
- Follow conventional commits format
- Never commit .env files
```
### What NOT to Include
- Secrets or API keys
- User-specific paths (use `settings.local.json` instead)
- Temporary instructions (use conversation context)
- Overly detailed documentation (link to docs instead)
## Rules System
Rules in `.claude/rules/` are like scoped CLAUDE.md files.
### Global Rules (no frontmatter)
```markdown
# Git Rules
- Use conventional commits
- Never force push to main
```
### Path-Scoped Rules
```markdown
---
paths:
- "**/*.ts"
- "**/*.tsx"
---
# TypeScript Rules
- Use strict mode
- Prefer interfaces over type aliases for objects
- Max function length: 50 lines
```
### Rule File Organization
```
.claude/rules/
├── architecture.md # Global — project structure
├── code-style.md # Scoped — *.ts, *.tsx, *.js, *.jsx
├── docker-k8s.md # Scoped — Dockerfiles, *.yaml
├── git-workflow.md # Global — commit conventions
├── testing.md # Scoped — *.test.*, *.spec.*
├── research.md # Global — web research tools
├── self-healing.md # Global — error capture protocol
└── lessons-learned.md # Global — auto-growing error log
```
## Auto-Memory System
### How It Works
Claude Code automatically saves important discoveries and patterns to persistent memory files.
### Memory Location
```
~/.claude/projects/<project-hash>/memory/
├── MEMORY.md # Auto-loaded into context (keep under 200 lines)
├── debugging.md # Topic-specific notes
├── patterns.md # Recurring patterns
└── architecture.md # Architecture decisions
```
### MEMORY.md (Auto-Loaded)
```markdown
# Project Memory
## Build System
- Uses pnpm workspaces with Turborepo
- `pnpm -w` for root-level operations
## Database
- PostgreSQL on port 5433 (non-standard)
- Run `pnpm db:migrate` after schema changes
## User Preferences
- Always use bun for running scripts
- Prefers functional style over OOP
```
### What Gets Auto-Saved
- Stable patterns confirmed across interactions
- Key architectural decisions
- Important file paths
- User preferences for workflow
- Solutions to recurring problems
### What Does NOT Get Saved
- Session-specific context
- Unverified information
- Anything duplicating CLAUDE.md
- Speculative conclusions
### Manual Memory Commands
```
# User says:
"Remember that we always use bun, not npm"
→ Claude saves to MEMORY.md
"Forget the instruction about yarn"
→ Claude removes from MEMORY.md
"Always run lint before committing"
→ Claude saves preference
# Slash commands:
/memory # View memories
/memory add <text> # Add entry
/memory clear # Clear all
```
### Disabling Auto-Memory
```bash
export DISABLE_AUTOMEMORY=1
```
or in settings.json:
```json
{ "autoMemory": false }
```
## Self-Healing Loop
The lessons-learned system creates a continuously improving knowledge base:
```
Tool call fails
→ PostToolUse hook captures error
→ Appends to .claude/rules/lessons-learned.md
→ Claude fixes the issue
→ Claude updates entry: Status → RESOLVED, adds Fix + Prevention
→ Next session loads lessons-learned.md as a rule
→ Claude doesn't repeat the mistake
```
### Lessons-Learned Format
```markdown
### Error: Git push rejected
- **Tool:** Bash
- **Status:** RESOLVED
- **Fix:** Use `git pull --rebase` before pushing
- **Prevention:** Always pull before push
```
## Settings Hierarchy
```
Enterprise managed settings (cannot be overridden)
└── User settings (~/.claude/settings.json)
└── Project settings (.claude/settings.json)
└── Local overrides (.claude/settings.local.json)
```
### Merge Behavior
- Arrays: concatenated (allow lists combine)
- Objects: deep merged (later values override)
- Primitives: later values override
- Enterprise settings: always win
## Best Practices
1. **Keep CLAUDE.md focused** — Build commands, conventions, architecture
2. **Use rules for enforcement** — Path-scoped rules for file-type conventions
3. **Let auto-memory learn** — Don't manually duplicate auto-saved info
4. **Review lessons-learned** — Promote patterns to permanent rules
5. **Scope rules narrowly** — Docker rules shouldn't load for TypeScript work
6. **Version control CLAUDE.md** — It's project documentation
7. **Gitignore settings.local.json** — Personal overrides stay local
Related in AI Agents
skill-development
IncludedComprehensive meta-skill for creating, managing, validating, auditing, and distributing Claude Code skills and slash commands (unified in v2.1.3+). Provides skill templates, creation workflows, validation patterns, audit checklists, naming conventions, YAML frontmatter guidance, progressive disclosure examples, and best practices lookup. Use when creating new skills, validating existing skills, auditing skill quality, understanding skill architecture, needing skill templates, learning about YAML frontmatter requirements, progressive disclosure patterns, tool restrictions (allowed-tools), skill composition, skill naming conventions, troubleshooting skill activation issues, creating custom slash commands, configuring command frontmatter, using command arguments ($ARGUMENTS, $1, $2), bash execution in commands, file references in commands, command namespacing, plugin commands, MCP slash commands, Skill tool configuration, or deciding between skills vs slash commands. Delegates to docs-management skill for official documentation.
reprompter
IncludedTransform messy prompts into well-structured, effective prompts — single or multi-agent. Use when: "reprompt", "reprompt this", "clean up this prompt", "structure my prompt", rough text needing XML tags and best practices, "reprompter teams", "repromptception", "run with quality", "smart run", "smart agents", multi-agent tasks, audits, parallel work, anything going to agent teams. Don't use when: simple Q&A, pure chat, immediate execution-only tasks. See "Don't Use When" section for details. Outputs: Structured XML/Markdown prompt, quality score (before/after), optional team brief + per-agent sub-prompts, agent team output files. Success criteria: Single mode quality score ≥ 7/10; Repromptception per-agent prompt quality score 8+/10; all required sections present, actionable and specific.
adaptive-compaction
IncludedAdaptive add-on policy and recovery layer that decides WHEN to compact, prune, snapshot, or fork -- replacing fixed-percent auto-compaction across Claude Code, Codex, and MCP-capable hosts. Trigger on auto-compact timing or damage: "when should I compact", "is it safe to compact now or start a fresh session", "auto-compact fires too early/mid-task", "switching to an unrelated task but the window still has space", "context rot", "answers get worse the longer the session runs", "the agent forgot the plan or my decisions after it summarized", "add a layer on top that manages context without changing the agent", raising autoCompactWindow to give the policy room, or installing/tuning a cross-tool compaction policy or PreCompact hook -- even when "compaction" is never said but the problem is context-window pressure or post-summarization memory loss. Do NOT use to summarize a conversation, build RAG, write a summarization prompt (decides WHEN not HOW), or answer max-context-length trivia.
agent-skill-creator
IncludedCreate cross-platform agent skills from workflow descriptions. Activates when users ask to create an agent, automate a repetitive workflow, create a custom skill, or need advanced agent creation. Triggers on phrases like create agent for, automate workflow, create skill for, every day I have to, daily I need to, turn process into agent, need to automate, create a cross-platform skill, validate this skill, export this skill, migrate this skill. Supports single skills, multi-agent suites, transcript processing, template-based creation, interactive configuration, cross-platform export, and spec validation.
llm-wiki
IncludedUse when building or maintaining a persistent personal knowledge base (second brain) in Obsidian where an LLM incrementally ingests sources, updates entity/concept pages, maintains cross-references, and keeps a synthesis current. Triggers include "second brain", "Obsidian wiki", "personal knowledge management", "ingest this paper/article/book", "build a research wiki", "compound knowledge", "Memex", or whenever the user wants knowledge to accumulate across sessions instead of being re-derived by RAG on every query.
skill-master
IncludedAgent Skills authoring, evaluation, and optimization. Create, edit, validate, benchmark, and improve skills following the agentskills.io specification. Use when designing SKILL.md files, structuring skill folders (references, scripts, assets), ingesting external documentation into skills, running trigger evals, benchmarking skill quality, optimizing descriptions, or performing blind A/B comparisons. Keywords: agentskills.io, SKILL.md, skill authoring, eval, benchmark, trigger optimization.