Refinement for context size
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
---
|
||||
name: Claude Code Memory Specialist
|
||||
description: Optimize and troubleshoot Claude Code memory files (CLAUDE.md) for efficiency, token management, and team collaboration. Use PROACTIVELY when memory isn't loading, context is bloated, optimizing existing memory files, or when users mention "CLAUDE.md", "memory file", or "project context". NOT for initial setup - use /init command first.
|
||||
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.
|
||||
---
|
||||
|
||||
# Claude Code Memory Optimization & Troubleshooting
|
||||
@@ -8,59 +8,52 @@ description: Optimize and troubleshoot Claude Code memory files (CLAUDE.md) for
|
||||
## When to Use This Skill
|
||||
|
||||
Use this skill when:
|
||||
- Troubleshooting memory files that aren't loading
|
||||
- Optimizing bloated CLAUDE.md files (>200 lines)
|
||||
- Managing token consumption in project memory
|
||||
- CLAUDE.md file exceeds 200 lines (bloat)
|
||||
- After reading any CLAUDE.md to suggest improvements
|
||||
- Memory files not loading correctly
|
||||
- Managing token consumption
|
||||
- Setting up memory hierarchy (project/user/subfolder)
|
||||
- Debugging why Claude isn't following instructions
|
||||
- Organizing memory for team collaboration
|
||||
|
||||
Do NOT use this skill for:
|
||||
- **Initial setup** - Use `/init` command instead
|
||||
- Creating slash commands (use claude-command-expert skill)
|
||||
- Creating slash commands (use claude-commands skill)
|
||||
- General Claude Code issues
|
||||
|
||||
**Important**: Always start with `/init` for initial project memory setup.
|
||||
|
||||
## Quick Reference: Memory Hierarchy
|
||||
## Quick Reference
|
||||
|
||||
### Memory Hierarchy (Load Order)
|
||||
```
|
||||
1. Enterprise Policy ~/.claude/enterprise/CLAUDE.md (highest priority)
|
||||
2. Project Memory ./CLAUDE.md or ./.claude/CLAUDE.md
|
||||
3. User Memory ~/.claude/CLAUDE.md
|
||||
4. Subfolder Memory ./subfolder/CLAUDE.md
|
||||
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
|
||||
```
|
||||
|
||||
**Lookup Order**: Claude searches upward from current directory, loading all CLAUDE.md files found.
|
||||
Claude searches upward from current directory, loading all found.
|
||||
|
||||
### Target Size
|
||||
**Goal**: 100-200 lines per CLAUDE.md (~400-800 tokens)
|
||||
|
||||
**Why**: Loaded in EVERY conversation. 500+ line files waste thousands of tokens.
|
||||
|
||||
## Core Principles
|
||||
|
||||
### 1. Target Size: 100-200 Lines
|
||||
|
||||
**Why**: Each CLAUDE.md loaded consumes tokens in every conversation.
|
||||
### 1. Progressive Disclosure Pattern
|
||||
|
||||
```markdown
|
||||
# ❌ Bad (500+ lines)
|
||||
Extensive documentation embedded inline
|
||||
|
||||
# ✓ Good (150 lines)
|
||||
Core info + imports for details
|
||||
```
|
||||
|
||||
### 2. Progressive Disclosure Pattern
|
||||
|
||||
```markdown
|
||||
# CLAUDE.md (Core - always loaded)
|
||||
# CLAUDE.md (Core - Always Loaded)
|
||||
Quick reference, critical rules, imports
|
||||
|
||||
# docs/architecture.md (Loaded on demand)
|
||||
# docs/architecture.md (Loaded on Demand)
|
||||
Detailed architecture information
|
||||
|
||||
# docs/style-guide.md (Loaded on demand)
|
||||
Comprehensive coding standards
|
||||
```
|
||||
|
||||
### 3. Use Specific, Emphatic Language
|
||||
**Token Savings**: 400 tokens (core) vs 2000+ tokens (everything embedded)
|
||||
|
||||
### 2. Use Specific, Emphatic Language
|
||||
|
||||
```markdown
|
||||
# ❌ Weak
|
||||
@@ -72,15 +65,15 @@ IMPORTANT: ALL React components MUST be functional (no class components).
|
||||
|
||||
## Essential Structure
|
||||
|
||||
### Minimal Template (100 lines)
|
||||
### Minimal Template (100-150 lines)
|
||||
|
||||
```markdown
|
||||
# ProjectName
|
||||
|
||||
Brief description.
|
||||
Brief description (1-2 sentences).
|
||||
|
||||
## Tech Stack
|
||||
- Key technologies
|
||||
- Key technologies (3-5 items)
|
||||
- See @docs/tech-stack.md for details
|
||||
|
||||
## Common Commands
|
||||
@@ -106,7 +99,7 @@ For complete templates, see [templates.md](templates.md)
|
||||
|
||||
| Problem | Quick Fix |
|
||||
|---------|-----------|
|
||||
| Memory not loading | Check filename case: `CLAUDE.md` |
|
||||
| Memory not loading | Check filename: `CLAUDE.md` (case-sensitive) |
|
||||
| Claude ignores rules | Add `IMPORTANT:` or `YOU MUST` |
|
||||
| Too many tokens | Move details to @docs/ imports |
|
||||
| Updates not working | Restart session or use `/memory` |
|
||||
@@ -116,15 +109,17 @@ For detailed troubleshooting, see [troubleshooting.md](troubleshooting.md)
|
||||
|
||||
## Optimization Quick Win
|
||||
|
||||
**Before (bloated)**:
|
||||
**Before (bloated - 1500 tokens)**:
|
||||
```markdown
|
||||
This project is a comprehensive platform built with React, Node.js, Express,
|
||||
PostgreSQL... [extensive paragraph explaining everything]
|
||||
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]
|
||||
```
|
||||
|
||||
**After (lean)**:
|
||||
**After (lean - 300 tokens)**:
|
||||
```markdown
|
||||
Tech Stack: React + Node.js + PostgreSQL
|
||||
Tech Stack: React 18 + Node.js 20 + PostgreSQL 15
|
||||
See @docs/architecture.md for details
|
||||
```
|
||||
|
||||
@@ -151,38 +146,33 @@ For optimization patterns, see [patterns.md](patterns.md)
|
||||
### ✓ Do
|
||||
```markdown
|
||||
# CLAUDE.md
|
||||
Quick reference content
|
||||
Quick reference
|
||||
|
||||
For detailed architecture: @docs/architecture.md
|
||||
For API reference: @docs/api-reference.md
|
||||
For architecture: @docs/architecture.md
|
||||
For API details: @docs/api-reference.md
|
||||
```
|
||||
|
||||
### ❌ Don't
|
||||
```markdown
|
||||
# CLAUDE.md
|
||||
@docs/a.md → @docs/b.md → @docs/c.md → @docs/d.md → @docs/e.md → @docs/f.md
|
||||
# Max depth is 5, avoid deep chains
|
||||
# Deep chains (max depth = 5)
|
||||
@docs/a.md → @docs/b.md → @docs/c.md → @docs/d.md → @docs/e.md
|
||||
```
|
||||
|
||||
**Rules**:
|
||||
- Max import depth: 5 levels
|
||||
- No circular references
|
||||
- Use relative paths for project files
|
||||
- Keep import chains flat, not deep
|
||||
- Keep chains flat, not deep
|
||||
|
||||
## Quick Update Methods
|
||||
|
||||
### Method 1: # Shortcut (Fastest)
|
||||
```bash
|
||||
# Press # at input start
|
||||
# Type your update
|
||||
# Auto-adds to appropriate CLAUDE.md
|
||||
```
|
||||
Press # at input start → type update → auto-adds to CLAUDE.md
|
||||
```
|
||||
|
||||
### Method 2: /memory Command
|
||||
```bash
|
||||
/memory
|
||||
# Opens memory management interface
|
||||
```
|
||||
/memory → Opens management interface
|
||||
```
|
||||
|
||||
### Method 3: Direct Edit
|
||||
@@ -194,7 +184,6 @@ vim CLAUDE.md
|
||||
## Emphasis Techniques
|
||||
|
||||
For critical rules:
|
||||
|
||||
```markdown
|
||||
IMPORTANT: [Critical rule]
|
||||
YOU MUST [mandatory action]
|
||||
@@ -203,25 +192,24 @@ NEVER [forbidden action]
|
||||
ALL CAPS for maximum attention
|
||||
```
|
||||
|
||||
## Testing Memory Effectiveness
|
||||
## Testing Effectiveness
|
||||
|
||||
### Quick Test
|
||||
```markdown
|
||||
# Add temporary marker to CLAUDE.md
|
||||
# Add temporary marker
|
||||
**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
|
||||
```
|
||||
|
||||
## Team Setup Example
|
||||
## Team Setup Pattern
|
||||
|
||||
```bash
|
||||
# .gitignore
|
||||
.claude/CLAUDE.local.md # Personal only
|
||||
.claude/settings.local.json # Personal settings
|
||||
|
||||
# .claude/CLAUDE.md (in git)
|
||||
# .claude/CLAUDE.md (in git - team standards)
|
||||
# Team Standards
|
||||
|
||||
@docs/architecture.md
|
||||
@@ -241,14 +229,36 @@ IMPORTANT: All team members follow these standards.
|
||||
|
||||
For team workflows, see [workflows.md](workflows.md)
|
||||
|
||||
## Resources
|
||||
## Compression Techniques
|
||||
|
||||
- [Memory File Templates](templates.md) - Ready-to-use CLAUDE.md templates
|
||||
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
|
||||
|
||||
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
|
||||
- [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)
|
||||
|
||||
💡 **Tip**: Measure regularly using `wc -l CLAUDE.md` (target: 100-200 lines)
|
||||
|
||||
---
|
||||
|
||||
**Remember**: Practice what we preach - keep memory lean (100-200 lines), be specific not vague, use imports for details, emphasize critical rules, test effectiveness.
|
||||
|
||||
Reference in New Issue
Block a user