/learn-rule Command
Capture a lesson from this session into permanent memory. The/learn-rule command is the core of the self-correction loop — every correction becomes a rule that prevents future mistakes.
Syntax
The Self-Correction Process
Identify the Lesson
What went wrong?
- What mistake was made?
- What should have happened instead?
- What would prevent this next time?
- Mistake: Edited src/utils.ts when user meant src/lib/utils.ts
- Should: Confirm full path before editing files with common names
Format the Rule
Use the standard learning format:Categories:
- Navigation — File paths, finding code
- Editing — Code changes, patterns
- Testing — Test approaches
- Git — Commits, branches
- Context — Memory, compaction
- Tools — MCP servers, CLI flags
- Prompting — How to ask Claude
- Architecture — Design decisions
Save to Database
The command saves the learning to SQLite:Indexed for FTS5 search: The rule is searchable via
/search and surfaces automatically via /replay.Learning Categories
Navigation
File paths and code location:Editing
Code changes and patterns:Testing
Test approaches and patterns:Git
Commits, branches, and workflows:Context
Memory and compaction:Tools
MCP servers and CLI:Example Flow
Database Schema
Learnings are stored with full-text search:Integration with Other Commands
With /wrap-up
Wrap-up suggests learnings to capture:With /replay
Replay surfaces past learnings:With /search
Search finds learnings by keyword:Best Practices
Capture Every Correction
Don’t skip corrections. Every mistake is a learning opportunity that compounds.
Be Specific
Vague rules don’t help. “Check file paths” is worse than “Confirm full path before editing files with common names”.
Use Right Category
Correct categorization helps
/replay surface relevant learnings.Update CLAUDE.md
Add critical learnings to CLAUDE.md so they load in every session.
Troubleshooting
Database writes failing
Database writes failing
If learnings aren’t saving:
-
Check database exists:
-
Initialize if missing:
-
Check permissions:
Learnings not surfacing in /replay
Learnings not surfacing in /replay
If past learnings don’t surface:
-
Check FTS5 index:
-
Rebuild index:
-
Verify search works:
CLAUDE.md getting too long
CLAUDE.md getting too long
If CLAUDE.md exceeds 150 lines:
- Keep only top 10-20 critical learnings in CLAUDE.md
- Let other learnings surface on-demand via
/replay - Split into modules if needed (see Split Memory)
Related Commands
/replay
Surface past learnings before starting work
/search
Search learnings database by keyword
/list
List all stored learnings
Learn Rule Skill
Deep dive on learning capture
Next Steps
- Learn about Self-Correction Loop
- Explore Database API
- Set up Learning Hooks