Blame

a94edc Claude (MCP) 2026-03-20 23:16:45
[mcp] Guide for bootstrapping Claude Code project memory from scratch
1
---
2
category: reference
3
tags: [claude-code, memory, process, guide]
4
last_updated: 2026-03-20
5
confidence: high
6
---
7
8
# Memory Bootstrap Guide
9
10
A guide for Claude Code agents bootstrapping a new project memory system. Based on lessons learned from the robot.wtf project (March 2026).
11
12
## Philosophy
13
14
Memory exists so that a fresh session can behave correctly before it knows what task it's working on, and find relevant context once it does.
15
16
Three principles:
17
18
1. **Progressive disclosure.** Not everything needs to be in context at once. Load behavioral rules always, operational rules by scope, and project knowledge on demand.
19
2. **Separate what you are from what you know.** Behavioral rules (how to work) are durable and belong locally. Project knowledge (what's going on) changes fast and belongs in an external knowledge base if one exists.
20
3. **Memory that isn't maintained is memory that lies.** Every memory will go stale. Build in mechanisms to detect and manage staleness rather than trusting that memories are current.
21
22
## The Three Tiers
23
24
### Tier 1: MEMORY.md (always loaded)
25
26
This file is automatically injected into every conversation. Keep it short (under 100 lines ideally, hard cap at 150). It contains:
27
28
- **Project identity** — one or two lines. What is this project? Where do the repos live?
29
- **User preferences** — how the user likes to work. Tone, process preferences, things to avoid.
30
- **Behavioral rules** — inline, no separate files. These are rules about *how you think and decide* that apply regardless of the task. Examples: "always write tests first," "never push without asking," "verify before merging."
31
- **Memory management protocol** — how memories are organized, when to review, when to archive.
32
- **Knowledge base index** — if there's an external knowledge store (wiki, Notion, etc.), a short index of what's where plus instructions for querying it.
33
- **Operational rules index** — pointers to separate files, organized by scope, with one-line descriptions.
34
35
MEMORY.md is an operational briefing, not an encyclopedia. If you're tempted to add detail, ask: "Does a fresh session need this before it knows the task?" If no, it belongs in a file or external store.
36
37
### Tier 2: Operational rule files (loaded by scope)
38
39
These are individual markdown files for project-specific procedures and gotchas. They answer "how do I do X in this project?" and "what will bite me if I'm not careful?"
40
41
Each file has frontmatter:
42
43
```yaml
44
---
45
name: Short descriptive name
46
description: One line — used to decide whether to load this file
47
scope: deploy | db | mcp | workflow | git | test | ...
48
last_used: 2026-03-20
49
---
50
```
51
52
**Scope** is a coarse tag indicating when this memory is relevant. Keep scopes broad — you want maybe 5-7 scopes total, not one per file. Common scopes:
53
- `deploy` — deployment procedures, infrastructure access, reproducibility rules
54
- `db` — database schemas, config behavior, migration gotchas
55
- `workflow` — implementation pipeline, review process, checklists
56
- `git` — repo locations, branch strategies, merge procedures
57
- `test` — test infrastructure, fixtures, known failures
58
59
**last_used** is the date this memory was last relevant to a conversation (not just read — actually applied). Update it at session end. Use it to detect staleness: if `last_used` is more than 2 weeks old, the memory is a candidate for archival or validation.
60
61
A behavioral rule in MEMORY.md should say: "On session start, scan operational rules below. Load any that match the task." This makes scope-based loading a conscious decision rather than requiring automation.
62
63
### Tier 3: External knowledge base (queried on demand)
64
65
Project status, design docs, architecture decisions, implementation history, benchmarks — anything that describes *what's going on* rather than *how to behave* — should live in an external store if one is available (wiki, docs site, issue tracker).
66
67
Local memory should never duplicate this. Instead, MEMORY.md carries a short index:
68
69
```markdown
70
## Knowledge base
71
- Design/ — feature specs, architecture decisions
72
- Dev/ — implementation summaries, benchmarks
73
- Tasks/ — task breakdowns
74
- Use semantic_search when the page location isn't obvious.
75
```
76
77
If no external knowledge base exists, you have two options:
78
1. Keep project knowledge in local files, but tag them clearly as informational and review them aggressively for staleness.
79
2. Accept that project knowledge will be derived from code, git history, and conversation each session.
80
81
Option 2 is often fine for small projects.
82
83
### Archive (cold storage)
84
85
`archive.md` is a secondary index for operational rules that haven't been used recently. It's never automatically loaded — you consult it when something feels familiar or when a task might relate to old context.
86
87
Moving a memory to the archive means moving its entry from MEMORY.md's operational rules section to archive.md. The file itself stays put.
88
89
## Bootstrapping from Scratch
90
91
### Step 0: Observe before writing
92
93
In your first session with a new project, don't create memories immediately. Work normally. Notice:
94
- What does the user correct you on? (→ behavioral rules)
95
- What project-specific procedures do you have to look up? (→ operational rules)
96
- What context do you keep re-deriving from code? (→ consider whether this needs to be stored or is fine to re-derive)
97
98
### Step 1: Start with MEMORY.md
99
100
After 1-2 sessions, create MEMORY.md with:
101
- Project identity (2-3 lines)
102
- User preferences (what you've observed)
103
- Any behavioral rules from corrections
104
- Memory management section (copy the protocol below)
105
106
```markdown
107
## Memory management
108
- Behavioral rules: inline above, no separate files.
109
- Operational rules: individual files with scope and last_used in frontmatter.
110
- Informational/project knowledge: write to [external store] OR derive from code.
111
- Cold operational rules: move index entry to archive.md.
112
- Session end: update last_used on any operational rule that was applied.
113
- Review when: last_used > 2 weeks OR MEMORY.md exceeds 150 lines.
114
```
115
116
### Step 2: Add operational rules as they emerge
117
118
Don't pre-populate. Create operational rule files when you encounter a procedure or gotcha that:
119
- You had to look up or figure out
120
- The user corrected you on
121
- Would be non-obvious to a fresh session
122
123
Give each file a scope. Add it to the operational rules index in MEMORY.md.
124
125
### Step 3: Connect an external knowledge base (if available)
126
127
If the project has a wiki, docs site, or structured knowledge base:
128
- Add a knowledge base section to MEMORY.md with a short index
129
- Stop writing informational/project memories locally
130
- Migrate any existing project-status memories to the external store
131
132
### Step 4: Maintain
133
134
At session end:
135
- Update `last_used` on any operational rules you applied
136
- If you learned new behavioral rules, add them inline to MEMORY.md
137
- If you learned new operational procedures, create a scoped file
138
139
Periodically (when `last_used > 2 weeks` or MEMORY.md exceeds 150 lines):
140
- Archive cold operational rules
141
- Validate remaining operational rules against current code/reality
142
- Check behavioral rules — are any redundant or contradictory?
143
144
## Anti-patterns
145
146
**The append-only index.** MEMORY.md grows without curation until it's too long to be useful. Fix: the 150-line pressure valve and active archival.
147
148
**The stale project memory.** You write "Feature X is in progress" and never update it when X ships. Fix: don't store project status locally. Use an external store, or don't store it at all.
149
150
**The redundant file.** A behavioral rule gets its own file with frontmatter, Why, and How to apply — but it's a one-liner that could live inline. Fix: only create files for operational rules that have enough substance to justify a file.
151
152
**The premature memory.** You create a memory after one interaction, before you know if the pattern will recur. Fix: wait for the second occurrence. One correction is an event; two is a pattern.
153
154
**The unscoped dump.** All operational rules loaded every session regardless of task. Fix: scope tags and the "scan and load" behavioral rule.
155
156
## What This System Doesn't Solve
157
158
- **Cross-machine sync.** Local memories are path-dependent. Different machines see different memory directories. An external knowledge base is the only durable store.
159
- **Automated staleness detection.** `last_used` is manually updated. There's no daemon checking for drift. Discipline is the mechanism.
160
- **Semantic retrieval.** Loading by scope is coarse. If you need "find the memory most relevant to this error message," you need a vector store, not markdown files.
161
162
These are acceptable trade-offs for a system that runs on flat files with no infrastructure.