claude-memory-bootstrap
NewSet up a Claude Code five-layer memory system (user / project / local / rules) for a project or workspace. Produces CLAUDE.md and companion files that follow the Less-is-More + Specific-over-Generic + WHY/WHAT/HOW + Progressive Disclosure principles. Trigger when the user says any of: - "set up a memory system" - "help me write CLAUDE.md" - "init a Claude config for this project" - "this project has no CLAUDE.md, build one" - "organise project rules for Claude" - 中文触发词: "建记忆系统"、"写 CLAUDE.md"、"初始化 Claude 配置"、"整理项目规范给 Claude"
Overview
Claude Code Five-Layer Memory System Bootstrap
Goal: give Claude perfect recall at the start of every new session, without
blowing the context budget.
Do this immediately on trigger
- Use
Read/lsto inventory the user's current working directory:
the top-level entries, any existing CLAUDE.md / AGENTS.md / README.md / package.json / pyproject.toml / main entry source files. Do not write blindly.
- Check whether
~/.claude/CLAUDE.mdalready exists; if it does, do not
overwrite — ask the user if anything needs adding.
- Check whether the target directory is a git repo (
ls .git); this decides
whether CLAUDE.local.md needs a .gitignore entry.
- Evaluate which of the five layers is missing for this project, and only
produce the missing ones.
The five layers (Claude Code official architecture)
| Layer | Path | Holds | Budget |
|---|---|---|---|
| 1. Enterprise policy | /Library/Application Support/ClaudeCode/CLAUDE.md (macOS) | Org-wide security / compliance | Skip for individuals |
| 2. User | ~/.claude/CLAUDE.md | Cross-project personal preferences (language, indent, test policy, background) | ~50 lines |
| 3. Project | <project>/CLAUDE.md (committed) | Team-shared project knowledge (stack, conventions, commands) | ~100 lines |
| 4. Local | <project>/CLAUDE.local.md (must be gitignored) | Machine-only info (test accounts, local URLs, current task) | ~50 lines |
| 5. Rules | <project>/.claude/rules/*.md with paths: frontmatter | Conditional rules loaded only when matching files are edited | Use when project-level >200 lines |
Loading order: outer → inner. Inner layers can override outer ones.
The four writing principles (non-negotiable)
Principle 1: Less is More
Every line is re-injected on every conversation. Redundancy is a recurring tax. Self-check: if you don't write this rule, will Claude do it correctly anyway? Yes → delete it.
Principle 2: Specific over Generic
- •❌ "Please write high-quality code."
- •✅ "Use
interfacefor object shapes; banany, useunknown+ type guards."
Principle 3: WHY / WHAT / HOW
After a critical rule, add one sentence of WHY. Claude that understands the reason will generalise correctly to situations the file doesn't list.
- service-layer code only `flush()`; routes do `commit() + refresh()`.
**WHY**: routes own the transaction boundary; a flush inside a service that's
reused by multiple routes would let one route commit another's half-finished
work.Principle 4: Progressive Disclosure
Reference detail docs with @path/to/doc.md instead of pasting them in. Keep the top file lean; let Claude load the deep ones only when needed.
Standard workflow
Step 1: Scan
ls -la <target>/
find <target> -maxdepth 3 \( -name "CLAUDE*.md" -o -name "AGENTS.md" -o -name "DESIGN.md" -o -name "spec.md" \) 2>/dev/null
test -f ~/.claude/CLAUDE.md && echo "user-level exists" || echo "user-level MISSING"
test -d <target>/.git && echo "is git repo" || echo "not git"Step 2: User layer (if missing)
Use AskUserQuestion to collect:
- Reply language (English / Chinese / mixed)
- Reply tone (concise / medium / detailed)
- Code comment language
- Indent preference (2 / 4 / tab)
- Test policy (never proactive / proactive for critical logic / always proactive)
- Technical background — decides whether Claude should use analogies
Then write ~/.claude/CLAUDE.md from references/user-claude-template.md.
Step 3: Project layer
Read the project skeleton (ls -la, key config files, entry source files). Generate <project>/CLAUDE.md from references/project-claude-template.md. Required sections:
- One-line project positioning
- Startup checklist (the 2-3 things Claude must do on entry)
- Task routing (only for multi-module projects)
- Tech stack (compact table)
- Hard constraints (real gotchas, each with WHY)
- Anti-patterns (explicit "do not do X")
- Project map +
@-references to deeper docs
Step 4: Local layer (optional)
If the project has test accounts, local URLs, current task notes, generate <project>/CLAUDE.local.md from references/local-claude-template.md, then:
# Git repos only
test -d .git && {
grep -q "^CLAUDE.local.md$" .gitignore 2>/dev/null || \
printf "\n# Claude Code local memory\nCLAUDE.local.md\n" >> .gitignore
}Step 5: Rules directory (only if project layer >200 lines)
Split topic-specific rules into .claude/rules/<topic>.md with paths: frontmatter so they load only when matching files are edited:
---
paths:
- "src/**/*.test.ts"
- "tests/**/*.ts"
---
# Testing conventions
...Verification checklist (run at the end)
- •[ ] User / project / local each holds only that layer's responsibilities
- •[ ] User layer ≤ 50 lines, project layer ≤ 100 lines, local layer ≤ 50 lines
- •[ ] All critical hard constraints are followed by a WHY sentence
- •[ ] Detail docs are
@-referenced, not pasted in - •[ ]
CLAUDE.local.mdis gitignored (if a git repo) - •[ ] No "write high-quality code" platitudes
- •[ ] No content that Claude would have done correctly by default
- •[ ] Anti-patterns section has at least 3 explicit "do not" rules
Common mistakes to avoid
| Mistake | Fix |
|---|---|
Putting test accounts in committed CLAUDE.md | Move to CLAUDE.local.md + gitignore |
| Putting "reply in Chinese" in project-level | Move to ~/.claude/CLAUDE.md (cross-project preference) |
| Adding a Makefile at the root of a multi-project workspace | Don't — workspace is not a repo, commands live in subprojects |
| Writing "code should be readable" | Delete, or replace with a specific rule (naming, length, comment format) |
| Listing every directory's purpose | Delete — ls reveals what files exist |
Reference templates (in references/)
- •
user-claude-template.md(+.zh-CN.md) — for~/.claude/CLAUDE.md - •
project-claude-template.md(+.zh-CN.md) — for<project>/CLAUDE.md - •
local-claude-template.md(+.zh-CN.md) — for<project>/CLAUDE.local.md - •
skill-creation-checklist.md(+.zh-CN.md) — for packaging other
workflows as Skills later
Maintenance
- •After 1-2 weeks of use, re-audit: which rules has Claude never violated?
Delete them — they're not earning their context cost.
- •Rules Claude has actively violated should get a more concrete WHY or counter-
example. Otherwise it'll keep violating them.
- •When business rules change (formulas, thresholds, org structure): update the
source-of-truth document first (PDF / spec), then sync to CLAUDE.md, then run the code to confirm nothing drifted.
Install & Usage
mkdir -p .claude/skillsmkdir -p .claude/skills && curl -o .claude/skills/claude-memory-bootstrap.md https://raw.githubusercontent.com/Steve-Tian/claude-memory-bootstrap/main/SKILL.md/claude-memory-bootstrapFrequently Asked Questions
What is claude-memory-bootstrap?
Set up a Claude Code five-layer memory system (user / project / local / rules) for a project or workspace. Produces CLAUDE.md and companion files that follow the Less-is-More + Specific-over-Generic + WHY/WHAT/HOW + Progressive Disclosure principles. Trigger when the user says any of: - "set up a memory system" - "help me write CLAUDE.md" - "init a Claude config for this project" - "this project has no CLAUDE.md, build one" - "organise project rules for Claude" - 中文触发词: "建记忆系统"、"写 CLAUDE.md"、"初始化 Claude 配置"、"整理项目规范给 Claude"
How to install claude-memory-bootstrap?
To install claude-memory-bootstrap, create the .claude/skills directory in your project, then run the curl command to download the skill file. Once installed, invoke it in Claude Code with /claude-memory-bootstrap.
What is claude-memory-bootstrap best for?
claude-memory-bootstrap is a community categorized under General. Created by Steve-Tian.