The single most powerful pattern—your CLAUDE.md trains itself through corrections
“80% of my code is written by AI, 20% is spent reviewing and correcting it.” — Andrej Karpathy
The self-correction loop optimizes for this ratio. Every correction becomes a rule that prevents future mistakes. After 50 sessions, Claude barely needs correcting.
User: You edited the wrong fileClaude: I edited src/utils.ts when you meant src/lib/utils.ts.[LEARN] Navigation: Confirm full path before editing files with common names.Should I add this?User: yesClaude: Added to LEARNED section. I'll confirm paths before editing from now on.
## Self-Correction ProtocolWhen the user corrects me or I make a mistake:1. Acknowledge specifically what went wrong2. Propose a concise rule: `[LEARN] Category: One-line rule`3. Wait for approval before adding to LEARNED section### LEARNED<!-- Auto-populated through corrections -->
The LEARNED section starts empty and grows as you work together.
Organize rules by category for easier maintenance:
Navigation
Code Quality
Testing
Git
Rules about finding and accessing files
[LEARN] Navigation: Confirm full path before editing files with common names[LEARN] Navigation: Check parent directory exists before mkdir[LEARN] Navigation: Use Glob to find files, not assumptions
Rules about code style and quality
[LEARN] Code Quality: Remove console.log before committing[LEARN] Code Quality: Prefer existing patterns over new abstractions[LEARN] Code Quality: Run typecheck after interface changes
Rules about test practices
[LEARN] Testing: Run tests after each file change, not in batch[LEARN] Testing: Test edge cases explicitly, not just happy path[LEARN] Testing: Mock external APIs in unit tests
Rules about version control
[LEARN] Git: Run quality gates before commit[LEARN] Git: Use conventional commit format[LEARN] Git: Check for uncommitted changes before branch switch
User: You forgot to run the testsClaude: You're right. I made changes without verifying them.[LEARN] Testing: Run relevant tests after each file changeShould I add this to LEARNED?
Test failed: Expected camelCase, got snake_caseClaude: The test failed because I used snake_case instead of camelCase.[LEARN] Code Quality: Project uses camelCase for all identifiersShould I add this?
Don’t add learnings for one-off issues. Only capture patterns that will recur.
[LEARN] Navigation: Use Glob to find files, never assume locations[LEARN] Navigation: Confirm parent directory exists before mkdir[LEARN] Navigation: Check full path before editing files with common names like utils.ts[LEARN] Navigation: Verify file exists before Read, handle gracefully if not
Testing Learnings
[LEARN] Testing: Run tests after each file change, not in batch at end[LEARN] Testing: Test error cases explicitly, not just happy paths[LEARN] Testing: Mock external dependencies (APIs, databases) in unit tests[LEARN] Testing: Check test coverage increased, not decreased
Git Learnings
[LEARN] Git: Run lint + typecheck + test before commit[LEARN] Git: Use conventional commit format: type(scope): message[LEARN] Git: Check for uncommitted changes before branch operations[LEARN] Git: Never commit console.log, debugger, or TODO comments
Quality Learnings
[LEARN] Quality: Read existing code before writing new patterns[LEARN] Quality: Prefer existing patterns over new abstractions[LEARN] Quality: Remove unused imports after refactoring[LEARN] Quality: Update tests when interface changes