Lance Martin's Claude Diary
Table of content

Lance Martin is a software engineer at LangChain who created Claude Diary, a plugin that gives Claude Code the ability to learn from experience and update its own memory. The idea: humans refine their skills through reflection, so agents should too.
Background
- PhD from Stanford in computational biology
- 5+ years leading perception teams at UberATG, IKE, and Nuro (self-driving vehicles)
- Early hire at LangChain focused on open source and applied ML
- Created LangChain Academy (35+ lessons on agents) and RAG From Scratch (450k+ views on FreeCodeCamp)
The Problem with Agent Memory
Most agents are stateless across sessions. They forget what they learned, repeat the same mistakes, and never adapt to your preferences. Martin noticed this gap after extensive work on context engineering.
His solution draws from the CoALA paper (Sumers et al. 2023), which proposes three memory types:
| Memory Type | Purpose | Example |
|---|---|---|
| Procedural | Instructions that steer behavior | CLAUDE.md rules |
| Episodic | Examples of desired behavior | Past session logs |
| Semantic | Task-relevant facts | Project-specific context |
Claude Diary focuses on procedural memory, turning session experiences into persistent rules.
How Claude Diary Works
The plugin adds two slash commands:
/diary captures what happened in a session:
- What was accomplished
- Design decisions made
- Challenges encountered
- User preferences observed
- PR feedback received
Entries save to ~/.claude/memory/diary/YYYY-MM-DD-session-N.md.
/reflect analyzes diary entries for patterns:
- Identifies violations of existing CLAUDE.md rules
- Detects recurring mistakes
- Synthesizes insights into one-line bullets
- Proposes updates to
~/.claude/CLAUDE.md
The reflection process tracks processed entries in processed.log to avoid duplicate analysis.
# Manual diary entry
/diary
# Automatic via PreCompact hook
# Triggers before context compaction
What It Learns
After a month of use, Martin’s CLAUDE.md accumulated rules about:
| Category | Example Rules |
|---|---|
| Git workflow | Use atomic commits, specific branch naming |
| Testing | Run targeted tests first for quick feedback |
| Code patterns | Prefer composition over inheritance |
| Token efficiency | Compress verbose explanations |
| PR feedback | Address reviewer comments systematically |
Each rule is a single imperative line. The system strengthens weak rules when they’re violated and adds new rules when patterns emerge.
Architecture
The system follows the generative agents framework:
- Observations - Raw session conversations recorded as diary entries
- Reflection - Pattern identification across multiple entries
- Retrieval - Rules loaded into future sessions via CLAUDE.md
Martin kept reflection manual (not fully automated) so users can review proposed changes before committing them to CLAUDE.md.
Context Engineering Background
Claude Diary emerged from Martin’s broader work on context engineering, which he defines as populating an LLM’s context window with the right information at each step.
Four strategies from his framework:
| Strategy | Method |
|---|---|
| Write context | Save scratchpads and memories for later |
| Select context | Retrieve relevant information via RAG |
| Compress context | Summarize long trajectories |
| Isolate context | Split work across sub-agents |
Claude Diary implements the “write context” strategy for procedural memory specifically.
Key Takeaways
| Principle | Implementation |
|---|---|
| Agents should learn | Build feedback loops from sessions to instructions |
| Memory needs structure | Separate procedural, episodic, and semantic |
| Reflection beats logging | Transform experiences into actionable rules |
| Manual review matters | Let humans approve memory updates |
Links
- Claude Diary blog post
- claude-diary on GitHub
- Context Engineering for Agents
- LangChain Academy
- RAG From Scratch
Next: Harper Reed’s LLM Codegen
Get updates
New guides, workflows, and AI patterns. No spam.
Thank you! You're on the list.