|
| 1 | +# Trim CLAUDE.md |
| 2 | + |
| 3 | +Measure CLAUDE.md size, identify bloat, and extract verbose sections into reference docs or kaizen system files — leaving compact pointers behind. |
| 4 | + |
| 5 | +CLAUDE.md is loaded into every conversation. Every line costs context. This skill keeps it lean. |
| 6 | + |
| 7 | +## When to use |
| 8 | + |
| 9 | +- CLAUDE.md exceeds ~250 lines |
| 10 | +- A section has grown verbose during development (common after adding policies or procedures) |
| 11 | +- After adding a new feature that introduced a large CLAUDE.md section |
| 12 | +- Periodic maintenance (every ~10 PRs) |
| 13 | + |
| 14 | +## The Process |
| 15 | + |
| 16 | +### Step 1: Measure |
| 17 | + |
| 18 | +```bash |
| 19 | +# Total size |
| 20 | +wc -l CLAUDE.md |
| 21 | + |
| 22 | +# Per-section breakdown |
| 23 | +awk '/^## /{if(section) printf "%3d lines: %s\n", NR-start, section; section=$0; start=NR} END{printf "%3d lines: %s\n", NR-start+1, section}' CLAUDE.md |
| 24 | +``` |
| 25 | + |
| 26 | +**Target:** CLAUDE.md under 250 lines. If it's under 200, probably fine — don't trim for the sake of trimming. |
| 27 | + |
| 28 | +### Step 2: Classify each section |
| 29 | + |
| 30 | +For each section over ~15 lines, ask: |
| 31 | + |
| 32 | +| Question | If yes → | |
| 33 | +|----------|----------| |
| 34 | +| Is this kaizen enforcement? (hooks, verification, workflow, policies learned from incidents) | `.claude/kaizen/{name}.md` | |
| 35 | +| Is this a reference lookup? (architecture, procedures, recipes) | `docs/{name}.md` | |
| 36 | +| Is this an interactive workflow with decision points? | `.claude/skills/{name}/SKILL.md` | |
| 37 | +| Is this routing data? (trigger phrases → skills, key files, quick context) | **Keep in CLAUDE.md** | |
| 38 | +| Is this a short rule or policy? (< 3 lines per item) | **Keep in CLAUDE.md** | |
| 39 | + |
| 40 | +### Step 3: Decide what stays |
| 41 | + |
| 42 | +**Always keep in CLAUDE.md** (agents need this in every conversation): |
| 43 | +- Quick Context — project orientation |
| 44 | +- Cases overview — core concept |
| 45 | +- Key Files — navigation |
| 46 | +- Skill trigger mappings — routing data (which phrases invoke which skills) |
| 47 | +- Short policies — rules that fit in 1-2 lines each |
| 48 | +- Database — query recipes |
| 49 | +- Development — build/run commands |
| 50 | +- Git Remotes — tiny, always needed |
| 51 | + |
| 52 | +**Extract from CLAUDE.md** (agents only need when doing specific tasks): |
| 53 | +- Detailed procedures (merging, deploying, IPC messaging) |
| 54 | +- Verbose policies with sub-bullets and examples |
| 55 | +- Architecture diagrams and layer tables |
| 56 | +- Verification checklists |
| 57 | +- Philosophical content (zen aphorisms) |
| 58 | + |
| 59 | +### Step 4: Extract |
| 60 | + |
| 61 | +For each section being extracted: |
| 62 | + |
| 63 | +1. **Create the target file** with the full content, properly titled |
| 64 | +2. **Replace in CLAUDE.md** with a 2-3 line pointer: |
| 65 | + ```markdown |
| 66 | + ## Section Name |
| 67 | + |
| 68 | + **Read [`path/to/file.md`](path/to/file.md)** when [trigger condition]. |
| 69 | + |
| 70 | + Key points: [1-2 most important rules that agents should always remember]. |
| 71 | + ``` |
| 72 | +3. **Verify** the pointer's path is correct and the file exists |
| 73 | + |
| 74 | +### Step 5: Verify |
| 75 | + |
| 76 | +```bash |
| 77 | +# Check final size |
| 78 | +wc -l CLAUDE.md |
| 79 | + |
| 80 | +# Check all internal links resolve |
| 81 | +grep -oE '\[.*?\]\((.*?)\)' CLAUDE.md | grep -oE '\(.*?\)' | tr -d '()' | while read link; do |
| 82 | + [ -f "$link" ] || echo "BROKEN: $link" |
| 83 | +done |
| 84 | +``` |
| 85 | + |
| 86 | +## Classification guide: kaizen vs not |
| 87 | + |
| 88 | +**Belongs in `.claude/kaizen/`** if the content: |
| 89 | +- Was learned from kaizen incidents (policies #11-17, verification discipline) |
| 90 | +- Enforces the kaizen workflow (skill chain, reflection triggers) |
| 91 | +- Would make sense if kaizen were extracted as a standalone system |
| 92 | +- Is referenced by kaizen hooks or skills |
| 93 | + |
| 94 | +**Does NOT belong in `.claude/kaizen/`** if the content: |
| 95 | +- Is general engineering practice (TDD, dependency management) |
| 96 | +- Is project infrastructure (merging, deploying, database) |
| 97 | +- Is domain-specific (vertical architecture, IPC messaging) |
| 98 | + |
| 99 | +When in doubt: if removing kaizen from the project would make this content irrelevant, it belongs in kaizen. If it would still be useful, it belongs elsewhere. |
| 100 | + |
| 101 | +## Anti-patterns |
| 102 | + |
| 103 | +- **Extracting too aggressively.** Short sections (< 10 lines) don't need extraction — the pointer overhead isn't worth it. |
| 104 | +- **Losing routing data.** Skill trigger phrases MUST stay in CLAUDE.md. If agents can't see them, they won't invoke skills correctly. |
| 105 | +- **Creating skills for passive content.** Reference docs are not skills. Only create a skill if the content is an interactive workflow with decision points. |
| 106 | +- **Putting general dev practices in kaizen.** "Declare all dependencies" is not kaizen-specific. Keep it in CLAUDE.md. |
0 commit comments