---
name: claude-md-learning-loop
description: "Ilia Karelin's two-habit system for keeping CLAUDE.md current: after a fix, document the mistake and the correct approach; after a feature, document its file structure, approach and conventions. Also covers keeping CLAUDE.md to 100-200 lines, splitting into .claude/rules/, and pruning. Use when a fix just worked, a feature was just finished, Claude keeps repeating a mistake across sessions, or CLAUDE.md is stale or too long."
metadata:
author: "Ilia Karelin"
source: "https://prosperinai.substack.com/p/claude-md-learning-loop"
title: "Your CLAUDE.md Is Static. Your AI Forgot Everything Again."
note: "Text is Ilia's, unchanged, from \"The Two Moves\" to the end. Removed: the opening story, share/subscribe buttons, image placeholders and the lines introducing images that did not carry over. Added one framing line at the top (marked as Skillsync's)."
---
> Added by Skillsync: When the user finishes a fix or a feature, or asks for this, apply Ilia Karelin's two moves below to their CLAUDE.md.
## The Two Moves That Turn CLAUDE.md Into a Learning Loop
The system that I figured out so far consists of two habits.
The first is reactive. After Claude makes a mistake and you fix it, tell Claude to document the error and the correct approach in CLAUDE.md.
The second is proactive. After you finish implementing a feature, tell Claude to document the architecture, file structure, and conventions in CLAUDE.md.
Session 1, your CLAUDE.md is sparse. Generic rules. “Use TypeScript.” “Follow existing patterns.”
Session 20, it knows your database query patterns, your component naming conventions, which directories hold what, the three mistakes Claude keeps making and how to avoid them, and the architecture of every feature you’ve built.
## How to Document Mistakes in CLAUDE.md (Move 1)
Claude creates a new utility in src/utils/. Your project keeps utilities in lib/. You move it, explain the structure. Next session, another file in src/utils/.
After Claude corrects the mistake, tell it:
“That fix worked. Add to CLAUDE.md: All utilities go in `lib/`, not `src/utils/` — we keep `src/` for components only.”
That’s it. 30 seconds. One rule, with reasoning baked in. The generic version you can copy-paste after any fix:
”That fix worked. Add a rule to CLAUDE.md documenting what went wrong and the correct approach, so this mistake doesn’t happen in future sessions.”
Notice the rule includes why — “we keep src/ for components only.” Rules without reasoning get misapplied. “Don’t put files in src/utils/” is fragile; Claude might avoid creating utilities at all. “Utilities go in `lib/` because src/ is for components” gives Claude the context to apply it correctly.
One more thing: always tell Claude what to do instead, not just what to avoid. “Never use NSEvent.addGlobalMonitorForEvents” leaves Claude stuck (in my case). “Never use NSEvent.addGlobalMonitorForEvents — use CGEventTap instead” gives it a path forward.
Here’s another example from my project. Claude kept creating Swift files that wouldn’t compile because they weren’t registered in Xcode’s project file. After the second time, I told Claude:
“That fix worked. Add a rule to CLAUDE.md: When creating new Swift files, you must also update project.pbxproj with PBXBuildFile, PBXFileReference, PBXGroup, and PBXSourcesBuildPhase entries. Files created outside Xcode won’t compile otherwise.”
Never happened again.
## How to Document Implementations in CLAUDE.md (Move 2)
Let’s talk about the Move 2 now. You just spent 45 minutes building an authentication system with Claude. Next week, you need to extend it. New session. Claude has no idea how your auth system works — the same system it helped you build.
After finishing any implementation, tell Claude:
“We just finished implementing the auth system. Document the file structure, approach, and conventions in CLAUDE.md.”
The generic version:
”We just finished implementing [feature]. Document the file structure, approach, and conventions in CLAUDE.md.”
Here’s what Claude wrote in my project after we finished building a global hotkey system:
## Global Hotkey System
- Uses CGEventTap (not NSEvent.addGlobalMonitorForEvents — unreliable)
- Core: GlobalHotkeyManager.swift (CGEventTap engine)
- UI: SimpleHotkeyRecorder.swift (SwiftUI recorder)
- Requires Accessibility permissions
- Storage: UserDefaults key “GlobalHotkey”
5 lines. That took Claude about 15 seconds to write. The next session, when I needed to add a new keyboard shortcut, Claude already knew the architecture — which file handled what, which approach we’d chosen and why, and the edge case with modifier-only keys. Zero re-explaining.
Keep these entries short. A few bullet points per feature — file locations, key decisions, gotchas. If a feature needs deeper documentation, write it in a separate file and add a pointer: “For auth flow details, see docs/auth-architecture.md.” Claude will open that file when it’s working on auth. It won’t load it every session, which keeps your context budget lean.
## How to Organize a Growing CLAUDE.md
Your CLAUDE.md will grow. But it needs structure or it becomes noise.
CLAUDE.md can hit the wall fast. A global hotkey system, text shortcuts, a history feature, and a full UI redesign — all documented in one file. It is definitely useful but can get hard to scan.
Claude already has system prompt that has dozens of instructions, so keep the root CLAUDE.md between 100-200 lines. 300 is the upper limit — past that, Claude starts treating your instructions as background noise instead of rules. Think of it as the executive summary: project overview, critical rules, key conventions.
For everything else, drop focused .md files into .claude/rules/:
./CLAUDE.md ← Core rules, project overview (100-200 lines)
.claude/rules/conventions.md ← Naming, formatting, patterns
.claude/rules/architecture.md ← Feature docs, file structure maps
.claude/rules/mistakes.md ← Documented errors and fixes
Claude auto-loads every .md file in .claude/rules/ at session start — same priority as the root CLAUDE.md. No special syntax needed. Just drop files in and they’re included.
For deeper documentation that doesn’t need to load every session, use plain text pointers in your rules: “For payment flow details, see docs/payments.md.” Claude will open that file when it’s relevant, without burning context tokens on every startup.
The other half of this is pruning. Every few weeks, read through your CLAUDE.md and ask: does every line still earn its place? Merge rules that overlap. Delete ones that no longer apply. The goal is a curated control panel, not an ever-growing memory dump. If a rule hasn’t prevented a mistake in ten sessions, it’s probably noise.
## CLAUDE.md Day One vs Session 30: How Knowledge Compounds
Here’s what my actual CLAUDE.md looked like on day one:
# my-app
- Swift, SwiftUI, macOS app
- Use existing patterns when possible
- Check in before major changes
- Keep changes simple
A couple of sessions later:
# my-app
- Swift, SwiftUI, macOS app
- Use existing patterns when possible
- Check in before major changes
- Keep changes simple
## Global Hotkey System
- Uses CGEventTap for reliable global keyboard monitoring
- Core: GlobalHotkeyManager.swift, SimpleHotkeyRecorder.swift
- Requires Accessibility permissions
## Design System
- DesignSystem.swift: colors, spacing, typography, shadows
- Muted palette (soft blue-gray accent), adapts to light/dark
- .cardStyle(), .hoverEffect(), PrimaryButtonStyle
## History
- HistoryService.swift, HistoryView.swift
- Max 100 entries, newest first, UserDefaults persistence
and more...
These were all accumulated, one by one, over 1-2 sessions. I try to keep entres with just a few lines — short enough that the whole file stays under 200 lines. I haven’t had it happening yet, but if it ever gets too long, I’d move it to a separate file in .claude/rules/ and keep a one-line pointer here.
## Try It In Your Next Session
Open your CLAUDE.md right now. Add one thing from your last session that Claude should remember. Copy the two generic prompts from this post and use them for 10 sessions. Compare your CLAUDE.md to what it looked like before.
The payoff is a Claude that starts every session already knowing your project — the patterns, the mistakes, the architecture, the conventions. Not because it remembered. Because you taught it once and it never had to ask again.
## FAQ
Q: What’s the difference between CLAUDE.md and Claude Code’s auto-memory?
CLAUDE.md is a file you control. It lives in your project root, you decide what goes in, and Claude loads it at the start of every session. It’s your curated knowledge base. Claude Code auto-memory is Claude’s own note-taking system stored in ~/.claude/, where Claude writes notes to itself between sessions. Think of CLAUDE.md as the official onboarding doc and Claude Code auto-memory as Claude’s personal scratch notes. Both persist across sessions, but you’re the editor of CLAUDE.md.
Q: How long should CLAUDE.md be?
100-200 lines is the sweet spot. 300 is the upper limit — past that, Claude may down-rank your instructions. Split detailed sections into separate .md files under .claude/rules/ — Claude auto-loads everything in that directory at session start. Each file should be focused: conventions in one, architecture in another, mistakes in a third. And prune regularly. If a section gets noisy or a rule hasn’t mattered in weeks, cut it.
Q: Does updating CLAUDE.md every session slow you down?
Each update is a single prompt — about 30 seconds. You’re not writing documentation. You’re telling Claude to write it. The prompts from this post (”Add a rule to CLAUDE.md documenting what went wrong and the correct approach”) do the work for you. Over 30 sessions, that’s roughly 15 minutes invested. Compare that to the hours you’d spend re-explaining the same context if you didn’t.