Files
claude-plugins/claude-code/skills/claude-memory/SKILL.md

265 lines
6.5 KiB
Markdown
Raw Normal View History

2025-10-28 12:28:48 -05:00
---
name: Claude Code Memory Specialist
2025-10-28 12:48:17 -05:00
description: Optimize and troubleshoot Claude Code memory files (CLAUDE.md) for efficiency, token management, and team collaboration. Use PROACTIVELY after reading ANY CLAUDE.md file to suggest optimizations, when CLAUDE.md exceeds 200 lines, when starting work on projects, or when users mention "CLAUDE.md", "memory file", or "project context". NOT for initial setup - use /init command first.
2025-10-28 12:28:48 -05:00
---
# Claude Code Memory Optimization & Troubleshooting
## When to Use This Skill
Use this skill when:
2025-10-28 12:48:17 -05:00
- CLAUDE.md file exceeds 200 lines (bloat)
- After reading any CLAUDE.md to suggest improvements
- Memory files not loading correctly
- Managing token consumption
2025-10-28 12:28:48 -05:00
- Setting up memory hierarchy (project/user/subfolder)
- Organizing memory for team collaboration
Do NOT use this skill for:
- **Initial setup** - Use `/init` command instead
2025-10-28 12:48:17 -05:00
- Creating slash commands (use claude-commands skill)
2025-10-28 12:28:48 -05:00
- General Claude Code issues
**Important**: Always start with `/init` for initial project memory setup.
2025-10-28 12:48:17 -05:00
## Quick Reference
2025-10-28 12:28:48 -05:00
2025-10-28 12:48:17 -05:00
### Memory Hierarchy (Load Order)
2025-10-28 12:28:48 -05:00
```
2025-10-28 12:48:17 -05:00
1. Enterprise Policy ~/.claude/enterprise/CLAUDE.md (highest)
2. Project Memory ./CLAUDE.md or ./.claude/CLAUDE.md
3. User Memory ~/.claude/CLAUDE.md
4. Subfolder Memory ./subfolder/CLAUDE.md
2025-10-28 12:28:48 -05:00
```
2025-10-28 12:48:17 -05:00
Claude searches upward from current directory, loading all found.
2025-10-28 12:28:48 -05:00
2025-10-28 12:48:17 -05:00
### Target Size
**Goal**: 100-200 lines per CLAUDE.md (~400-800 tokens)
2025-10-28 12:28:48 -05:00
2025-10-28 12:48:17 -05:00
**Why**: Loaded in EVERY conversation. 500+ line files waste thousands of tokens.
2025-10-28 12:28:48 -05:00
2025-10-28 12:48:17 -05:00
## Core Principles
2025-10-28 12:28:48 -05:00
2025-10-28 12:48:17 -05:00
### 1. Progressive Disclosure Pattern
2025-10-28 12:28:48 -05:00
```markdown
2025-10-28 12:48:17 -05:00
# CLAUDE.md (Core - Always Loaded)
2025-10-28 12:28:48 -05:00
Quick reference, critical rules, imports
2025-10-28 12:48:17 -05:00
# docs/architecture.md (Loaded on Demand)
2025-10-28 12:28:48 -05:00
Detailed architecture information
```
2025-10-28 12:48:17 -05:00
**Token Savings**: 400 tokens (core) vs 2000+ tokens (everything embedded)
### 2. Use Specific, Emphatic Language
2025-10-28 12:28:48 -05:00
```markdown
# ❌ Weak
Use functional components
# ✓ Strong
IMPORTANT: ALL React components MUST be functional (no class components).
```
## Essential Structure
2025-10-28 12:48:17 -05:00
### Minimal Template (100-150 lines)
2025-10-28 12:28:48 -05:00
```markdown
# ProjectName
2025-10-28 12:48:17 -05:00
Brief description (1-2 sentences).
2025-10-28 12:28:48 -05:00
## Tech Stack
2025-10-28 12:48:17 -05:00
- Key technologies (3-5 items)
2025-10-28 12:28:48 -05:00
- See @docs/tech-stack.md for details
## Common Commands
```bash
npm run dev # Start development
npm test # Run tests
```
## Conventions
- 2-space indentation
- ESLint + Prettier
- See @docs/style-guide.md
## IMPORTANT Rules
- YOU MUST run tests before commits
- Never commit secrets
- Update docs with code changes
```
For complete templates, see [templates.md](templates.md)
## Common Problems (Quick Fixes)
| Problem | Quick Fix |
|---------|-----------|
2025-10-28 12:48:17 -05:00
| Memory not loading | Check filename: `CLAUDE.md` (case-sensitive) |
2025-10-28 12:28:48 -05:00
| Claude ignores rules | Add `IMPORTANT:` or `YOU MUST` |
| Too many tokens | Move details to @docs/ imports |
| Updates not working | Restart session or use `/memory` |
| Conflicting memories | Project wins over user (check hierarchy) |
For detailed troubleshooting, see [troubleshooting.md](troubleshooting.md)
## Optimization Quick Win
2025-10-28 12:48:17 -05:00
**Before (bloated - 1500 tokens)**:
2025-10-28 12:28:48 -05:00
```markdown
2025-10-28 12:48:17 -05:00
This project is a comprehensive platform built with React 18,
utilizing TypeScript for type safety, Node.js 20 for the backend,
Express 4.18 for API routes, PostgreSQL 15 for data persistence...
[extensive paragraphs explaining everything]
2025-10-28 12:28:48 -05:00
```
2025-10-28 12:48:17 -05:00
**After (lean - 300 tokens)**:
2025-10-28 12:28:48 -05:00
```markdown
2025-10-28 12:48:17 -05:00
Tech Stack: React 18 + Node.js 20 + PostgreSQL 15
2025-10-28 12:28:48 -05:00
See @docs/architecture.md for details
```
**Result**: 80% token reduction
For optimization patterns, see [patterns.md](patterns.md)
## File Locations
### Project (Team-Shared)
```bash
.claude/CLAUDE.md # Team standards (in git)
.claude/settings.json # Team configuration
```
### Personal (Not Shared)
```bash
.claude/CLAUDE.local.md # Personal overrides (gitignored)
~/.claude/CLAUDE.md # Global defaults
```
## Import Best Practices
### ✓ Do
```markdown
# CLAUDE.md
2025-10-28 12:48:17 -05:00
Quick reference
2025-10-28 12:28:48 -05:00
2025-10-28 12:48:17 -05:00
For architecture: @docs/architecture.md
For API details: @docs/api-reference.md
2025-10-28 12:28:48 -05:00
```
### ❌ Don't
```markdown
2025-10-28 12:48:17 -05:00
# Deep chains (max depth = 5)
@docs/a.md → @docs/b.md → @docs/c.md → @docs/d.md → @docs/e.md
2025-10-28 12:28:48 -05:00
```
**Rules**:
- Max import depth: 5 levels
- No circular references
2025-10-28 12:48:17 -05:00
- Keep chains flat, not deep
2025-10-28 12:28:48 -05:00
## Quick Update Methods
### Method 1: # Shortcut (Fastest)
2025-10-28 12:48:17 -05:00
```
Press # at input start → type update → auto-adds to CLAUDE.md
2025-10-28 12:28:48 -05:00
```
### Method 2: /memory Command
2025-10-28 12:48:17 -05:00
```
/memory → Opens management interface
2025-10-28 12:28:48 -05:00
```
### Method 3: Direct Edit
```bash
vim CLAUDE.md
# Then ask Claude to reload
```
## Emphasis Techniques
For critical rules:
```markdown
IMPORTANT: [Critical rule]
YOU MUST [mandatory action]
NEVER [forbidden action]
**Bold** for emphasis
ALL CAPS for maximum attention
```
2025-10-28 12:48:17 -05:00
## Testing Effectiveness
2025-10-28 12:28:48 -05:00
```markdown
2025-10-28 12:48:17 -05:00
# Add temporary marker
2025-10-28 12:28:48 -05:00
**MEMORY TEST: If you see this, memory loaded correctly**
# Ask Claude: "What's the first line of your memory?"
# Should see marker, then remove it
```
2025-10-28 12:48:17 -05:00
## Team Setup Pattern
2025-10-28 12:28:48 -05:00
```bash
# .gitignore
.claude/CLAUDE.local.md # Personal only
.claude/settings.local.json # Personal settings
2025-10-28 12:48:17 -05:00
# .claude/CLAUDE.md (in git - team standards)
2025-10-28 12:28:48 -05:00
# Team Standards
@docs/architecture.md
@docs/conventions.md
IMPORTANT: All team members follow these standards.
## Git Workflow
1. Feature branch from develop
2. PR requires 2 approvals
3. Squash merge
## NEVER
- Commit directly to main
- Merge without tests passing
```
For team workflows, see [workflows.md](workflows.md)
2025-10-28 12:48:17 -05:00
## Compression Techniques
1. **Bullet Points > Paragraphs** (50% more efficient)
2. **Commands > Explanations** (show `npm test`, not prose)
3. **Imports > Embedding** (`@docs/api.md` = 5 tokens vs 2000)
4. **Examples > Theory** (concrete beats abstract)
### Decision Tree
```
Needed in 80%+ sessions?
→ YES: Keep in CLAUDE.md
2025-10-28 12:28:48 -05:00
2025-10-28 12:48:17 -05:00
Needed occasionally?
→ YES: Put in @docs/, reference from CLAUDE.md
Needed rarely?
→ NO: Omit, use web search or direct read
```
## Additional Resources
**Need more?**
- [Memory Templates](templates.md) - Ready-to-use CLAUDE.md templates
2025-10-28 12:28:48 -05:00
- [Troubleshooting Guide](troubleshooting.md) - Detailed problem-solution guide
- [Optimization Patterns](patterns.md) - Advanced token-saving techniques
- [Team Workflows](workflows.md) - Collaboration strategies
- [Official Documentation](https://docs.claude.com/en/docs/claude-code/memory)
2025-10-28 12:48:17 -05:00
💡 **Tip**: Measure regularly using `wc -l CLAUDE.md` (target: 100-200 lines)
2025-10-28 12:28:48 -05:00
---
**Remember**: Practice what we preach - keep memory lean (100-200 lines), be specific not vague, use imports for details, emphasize critical rules, test effectiveness.