feat(cc-013): add auto memory companion repo with three exercises
Companion repo for CC-013. Covers triggering memory, structuring MEMORY.md with index and topic files, and proving cross-session persistence shapes Claude behavior. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
commit
eb5a4f0f6a
5 changed files with 551 additions and 0 deletions
173
exercises/03-cross-session.md
Normal file
173
exercises/03-cross-session.md
Normal file
|
|
@ -0,0 +1,173 @@
|
|||
# Exercise 03: Cross-Session Persistence
|
||||
|
||||
**Concept:** Auto Memory (CC-013)
|
||||
**Level:** Advanced
|
||||
**Time:** ~20 minutes
|
||||
**Builds on:** [Exercise 01](./01-trigger-memory.md) and [Exercise 02](./02-structure-memory.md)
|
||||
|
||||
---
|
||||
|
||||
## Objective
|
||||
|
||||
Prove that memory persists across fully closed sessions and silently
|
||||
shapes Claude's behavior, without you repeating any preferences.
|
||||
|
||||
This is the payoff exercise. You are not just creating memory files.
|
||||
You are watching them change how Claude writes code.
|
||||
|
||||
---
|
||||
|
||||
## The Scenario
|
||||
|
||||
You have a coding preference. You tell Claude once. You close Claude
|
||||
Code entirely. You reopen it. You ask Claude to write code. Without
|
||||
mentioning the preference, you check whether Claude followed it.
|
||||
|
||||
This is the pattern that makes auto memory genuinely useful: you
|
||||
teach Claude once, and it holds.
|
||||
|
||||
---
|
||||
|
||||
## Instructions
|
||||
|
||||
**Step 1:** In a fresh Claude Code session, register a preference
|
||||
you can test in code. Paste this prompt:
|
||||
|
||||
```
|
||||
Remember that I never use semicolons in TypeScript. No exceptions.
|
||||
Write this to the user preferences memory file.
|
||||
```
|
||||
|
||||
Claude will save it. Confirm the save.
|
||||
|
||||
**Step 2:** Close Claude Code completely.
|
||||
|
||||
Not just `/clear`. Exit the process entirely:
|
||||
|
||||
```
|
||||
/exit
|
||||
```
|
||||
|
||||
Or close the terminal window and open a new one.
|
||||
|
||||
**Step 3:** Reopen Claude Code in the same project directory.
|
||||
|
||||
```bash
|
||||
cd claude-code-auto-memory
|
||||
claude
|
||||
```
|
||||
|
||||
Do not mention the no-semicolons preference. Do not paste any context
|
||||
about your style. Just open it.
|
||||
|
||||
**Step 4:** Ask Claude to write a TypeScript function. Paste this:
|
||||
|
||||
```
|
||||
Write a TypeScript function called formatDate that takes a Date object
|
||||
and returns a string in YYYY-MM-DD format.
|
||||
```
|
||||
|
||||
Read the output carefully. Count the semicolons.
|
||||
|
||||
**Step 5:** Check whether memory was loaded.
|
||||
|
||||
```
|
||||
What TypeScript preferences do you have on file for me?
|
||||
```
|
||||
|
||||
Claude should list the no-semicolons rule and any preferences from
|
||||
earlier exercises, without you supplying them.
|
||||
|
||||
**Step 6:** Add a project-level memory about this session.
|
||||
|
||||
```
|
||||
Remember about this session: I completed all three auto memory exercises
|
||||
today. The project is a learning repo for CC-013. Next time, start by
|
||||
reading the exercise files to see what was covered.
|
||||
```
|
||||
|
||||
This creates a lightweight session log. Open a new session and verify
|
||||
Claude greets you with context about what was done.
|
||||
|
||||
---
|
||||
|
||||
## What a Strong Solution Looks Like
|
||||
|
||||
A strong result:
|
||||
|
||||
- The `formatDate` function contains no semicolons, even though you
|
||||
never mentioned the preference in this session
|
||||
- Claude lists your preferences accurately when asked in Step 5
|
||||
- The session note from Step 6 appears in memory and loads next session
|
||||
|
||||
A result that misses the point:
|
||||
|
||||
- Claude produces code with semicolons because the memory was not loaded
|
||||
- Claude says it has no preferences on file (likely a path or session issue)
|
||||
- The session note is never saved to a file
|
||||
|
||||
---
|
||||
|
||||
## Troubleshooting
|
||||
|
||||
**Claude does not follow the preference:** Check that you are in exactly
|
||||
the same directory as Step 1. Run `pwd` and compare. The project hash
|
||||
is path-specific.
|
||||
|
||||
**Memory shows nothing from earlier exercises:** If you used `/clear`
|
||||
instead of fully exiting and reopening, that may not have reset the
|
||||
session the same way. Try a full exit and reopen.
|
||||
|
||||
**The function has semicolons despite the rule:** This can happen if
|
||||
the memory file was saved but Claude did not load it. Ask Claude:
|
||||
"Read the memory directory and tell me every file in it." If it is
|
||||
empty, the save in Step 1 did not complete.
|
||||
|
||||
---
|
||||
|
||||
## Challenge
|
||||
|
||||
If you finish early or want to go further:
|
||||
|
||||
- **Challenge A:** Register three conflicting preferences across two sessions
|
||||
and see how Claude resolves them. Which one wins?
|
||||
- **Challenge B:** Delete one topic file manually from `~/.claude/projects/`
|
||||
and verify Claude no longer applies that preference.
|
||||
- **Challenge C:** Set up memory in a different project on your machine and
|
||||
confirm the two projects have separate, independent memory stores.
|
||||
|
||||
---
|
||||
|
||||
## Reflection
|
||||
|
||||
After completing this exercise, consider:
|
||||
|
||||
- What preferences or context would be most valuable to store in your
|
||||
real projects?
|
||||
- What is the difference between memory in CLAUDE.md (checked into git,
|
||||
shared with the team) and memory in the project memory store (local only)?
|
||||
- Where does auto memory break down, and when would you use CLAUDE.md instead?
|
||||
|
||||
There is no right answer to these questions. The reflection is for you.
|
||||
|
||||
---
|
||||
|
||||
## What You Learned
|
||||
|
||||
- **Memory accumulates progressively:** Each session leaves a trace.
|
||||
Claude becomes more tuned to your context over time.
|
||||
- **Silent behavior shaping:** You do not need to repeat preferences.
|
||||
They are loaded automatically and applied without prompting.
|
||||
- **Machine-local scope:** Everything in `~/.claude/projects/` stays
|
||||
on your machine. Moving to a new machine means rebuilding memory.
|
||||
This is a tradeoff worth knowing.
|
||||
|
||||
---
|
||||
|
||||
## What Is Next
|
||||
|
||||
You have now worked through all three exercises for Auto Memory.
|
||||
|
||||
Return to the article at https://fromaitochitta.com/cc-013 for
|
||||
the broader context, or explore related concepts in the
|
||||
Claude Code Memory and Instructions series.
|
||||
Loading…
Add table
Add a link
Reference in a new issue