Claude Code memory: full guide + copy-paste prompts
4 ways to write CLAUDE.md and cut tokens, plus 5 prompts you paste into Claude Code
黃志弘 Leo
Published 2026-04-17 · Updated 2026-10-09 · 1 readers
5 prompts to paste into Claude Code
Copy the 5 prompts below into Claude Code. It reads your CLAUDE.md, tells you what to change, and waits for your OK before touching anything. The article then explains why each one saves tokens and how it works.
Run a checkup on this project's CLAUDE.md. The goal is to cut context token use. Do it in this order:
1. Run `wc -l CLAUDE.md` and tell me the current line count
2. Scan for comments starting with # that are written for people (history, reasons, context)
(not the rules themselves, the ones explaining why a rule exists)
List them, then rewrite them as <!-- --> block comments
3. Find rules that only apply to one kind of file
(for example only to API code, front-end components, SQL migrations)
Split them into separate .claude/rules/xxx.md files, add a paths field in the YAML frontmatter bound to a glob
Delete the moved parts from the main CLAUDE.md
4. Check for long sections (git workflow, style guides) that belong in an external file pulled in with @path
5. After all the edits, run `wc -l CLAUDE.md` again and tell me the difference
List the plan before each step and wait for my OK. Follow the rules in https://code.claude.com/docs/en/memory.How long: Depends on how big your CLAUDE.md is, usually 10 - 30 minutes in one pass.
Scan my CLAUDE.md and rewrite every human-facing comment that starts with # (history, who decided what, why a rule exists, context written for people, not the rules themselves) as a <!-- --> block comment.
List the sections you found before changing anything and wait for my OK. When you are done, run `git diff CLAUDE.md` so I can check.Some rules in my CLAUDE.md only apply to certain kinds of files (only to src/api/, only to React components, only to SQL migrations).
Split those rules into separate files under .claude/rules/, each with YAML frontmatter:
---
paths:
- "the matching glob"
---
Delete the moved rules from the main CLAUDE.md. Give me the split plan first (which group becomes which file, what paths says) and wait for my OK.
Rule format: https://code.claude.com/docs/en/memoryRun `wc -l CLAUDE.md`. If it is over 200 lines, analyse it for me:
1. List the line count of every major section
2. Find the sections best moved out:
- History and context, wrap in HTML comments <!-- -->
- Tied to one kind of file, move to .claude/rules/
- Long examples / full workflows, move to docs/ and pull back with @path
3. Estimate how many lines are left after the cuts
Give me the list of suggestions first, I will pick which ones to do.Find the content in my CLAUDE.md that is long and applies across projects (git workflow, personal code style preferences, commit conventions).
Move it to external files and pull it into the main file with @path:
- Cross-project personal preferences: move to ~/.claude/xxx.md, use @~/.claude/xxx.md
- Project-level detail: move to docs/xxx.md, use @docs/xxx.md
List the sections you want to move and the target filenames first, then wait for my OK.Why CLAUDE.md affects your token use
There are two layers. At the model layer, Claude Code lets you set effort (five levels: low, medium, high, xhigh, max) or simply ask for shorter answers.
The other layer is context, meaning your CLAUDE.md. It loads in full at the start of every session, so the longer it is, the more tokens you spend before the conversation begins. That holds whichever model you use, so the 4 methods below apply to any version of Claude.
Long-lived CLAUDE.md files tend to keep instructions written for older models. In Claude Code 2.1.283 or later, run /doctor prompt-audit in a session. It flags instructions written for older models, references to files or commands that no longer exist, and rules that contradict each other, then proposes edits and changes nothing until you say so.
4 ways to write CLAUDE.md (each with before / after and why it saves)
Every rule here comes from Anthropic's official Claude Code memory docs, code.claude.com/docs/en/memory. The examples are copy-paste ready for your own CLAUDE.md.
<!-- --> block comments
Before (bad), those two history notes load every single time
# Rules
# 2025-08-15: added because Sarah kept getting her PRs rejected
# Do not delete, checked with the Compliance team
- Always include type annotations on exported functions
# Mike thinks we may drop this one later
- Prefer `import type` over `import { type }`After (good), both notes are stripped and Claude sees only the rules
# Rules
<!--
2025-08-15: added because Sarah kept getting her PRs rejected
Do not delete, checked with the Compliance team
-->
- Always include type annotations on exported functions
<!-- Mike thinks we may drop this one later -->
- Prefer `import type` over `import { type }`grep -n "^#" CLAUDE.md to find the human comments that start with # in your file today, and wrap them in <!-- -->.Note: Comments inside
``` code blocks are kept. Open the file with the /memory command and you still see them. The content written for people is not gone, it just does not enter Claude's context.
.claude/rules/ + paths for conditional loading (this one saves the most)
.claude/rules/*.md and add the YAML frontmatter paths field. The rules only load into context when Claude touches a file matching the glob. Front-end work does not load the API rules, API work does not load the front-end rules. Session start = 0 tokens.Before (bad), everything in the main CLAUDE.md, loaded every session
# CLAUDE.md (main file)
## API rules (50 lines)
- All endpoints must validate input with zod
- Use standard error response from src/api/errors.ts
- ... 47 more lines
## React rules (50 lines)
- Functional components only, no class components
- Tailwind only, no CSS modules
- ... 47 more lines
## DB rules (50 lines)
- Migrations must be reversible
- ... 48 more lines150 lines ≈ 1500 tokens, paid every session. Write front-end code and the back-end rules load anyway.
After (good), three files, loaded conditionally
# .claude/rules/api.md
---
paths:
- "src/api/**/*.ts"
---
- All endpoints must validate input with zod
- Use standard error response from src/api/errors.ts# .claude/rules/react.md
---
paths:
- "src/components/**/*.tsx"
- "src/pages/**/*.tsx"
---
- Functional components only, no class components
- Tailwind only, no CSS modules# .claude/rules/db.md
---
paths:
- "migrations/**/*.sql"
- "src/db/**/*.ts"
---
- Migrations must be reversibleDo it now: Go through your CLAUDE.md and find the rules tied to one kind of file (API only, React only, SQL only, tests only). Put each group in its own file under
.claude/rules/, write the matching glob in paths, then cut them from the main file.
The docs also say that past 200 lines Claude follows the rules less closely.
Typical reasons a file passes 200 lines (trim these first)
- “Why this project exists / how we did it back in v1” history, wrap it with method 1 in
<!-- --> - “Onboarding steps for new teammates”, move to
docs/onboarding.md - “Rules tied to one kind of file”, split out with method 2 into
.claude/rules/ - Long examples / full git workflow / DB schema notes, move to
docs/then pull them back in with@importfrom method 4
wc -l CLAUDE.md # how long it is now
grep -c "^#" CLAUDE.md # how many human comments start with #wc -l to confirm.
@path to split files (pairs with the structure from methods 2 and 3)
.claude/rules/ for conditional loading, which is where the real saving is).Typical usage
# Project Rules
- 2-space indent
- Run `npm test` before commit
- API handlers in src/api/handlers/
@~/.claude/my-personal-style.md # shared across projects
@docs/git-workflow.md # detail moved outThe docs say @path recurses at most 4 levels (A imports B, B imports C, up to 4 hops).
- Personal preferences shared across projects (home path
@~/...) - Modular structure in the main file, easy to move out later to
.claude/rules/
.claude/rules/.
Method 2 (.claude/rules/ + paths) > Method 3 (200 lines) > Method 1 (HTML comments) > Method 4 (@import does not save directly)
Want a result today: do method 1 first (easiest, 5 minutes), then method 2 (biggest saving, 30 minutes).
Going further: Skills save more than Rules
Anthropic has a third layer: Skills. Used in the right place it saves more than rules.
| Mechanism | When it loads into context | Best for |
|---|---|---|
| CLAUDE.md | Every session start (loaded in full) | Rules Claude needs every day |
.claude/rules/ + paths |
When Claude reads a file matching the glob | Rules tied to a specific kind of file |
| Skills | When you invoke it, or Claude decides it is relevant | Workflows you only need occasionally (complex tasks) |
Rule of thumb: always-on goes in CLAUDE.md, conditional goes in rules, on-demand goes in skills. Putting each at the right level is the saving.
Side by side: a bad CLAUDE.md vs a good one
The comparison below is illustrative. It shows you the structural difference, it is not measured token data.
The bad version
- One file, 600+ lines
- Long “Why this exists” sections written for people
- Every rule always resident (front-end rules load while you edit the back end)
- No import splitting
- Unverifiable instructions like “format code nicely”
6,000+ tokens burned at the top of context every session.
The good version
- Main file under 80 lines, only the rules needed daily
- History and context in
<!-- -->comments, never in context - Front-end and back-end rules split into
.claude/rules/*.md+ paths - Use
@docs/git-workflow.mdto pull in external detail - Concrete and checkable, like “Use 2-space indentation”
About 800 tokens at session start, and better adherence.
One clarification: CLAUDE.md ≠ auto memory
People searching for “Claude memory” mix these two up. The docs actually have a clear comparison table (excerpt):
| CLAUDE.md | Auto memory (built into recent Claude Code versions) | |
|---|---|---|
| Who writes it | You | Claude itself |
| Content | Rules and workflows | Preferences Claude picked up, debugging experience |
| Loading | Loaded in full every session | Loads the first 200 lines or 25KB of the MEMORY.md index each session |
| Best for | Code style, architecture, process | Build commands, debugging notes, preferences Claude learned itself |
They complement each other, neither replaces the other. Full comparison table in the docs
Where CLAUDE.md and MEMORY.md live
From the official docs (October 2026). When several of these exist, none overrides another: Claude reads all of them, and the ones closer to your working folder are read last.
- Personal CLAUDE.md:
~/.claude/CLAUDE.md. Just you, applied to every project - Project CLAUDE.md:
CLAUDE.mdor.claude/CLAUDE.mdat the project root. Shared with the team through version control - CLAUDE.local.md:
CLAUDE.local.mdat the project root. Just you, so add it to.gitignore - Company-wide CLAUDE.md: on Mac at
/Library/Application Support/ClaudeCode/CLAUDE.md, on Windows atC:\Program Files\ClaudeCode\CLAUDE.md. Deployed by IT, and individual settings cannot exclude it - Auto memory:
~/.claude/projects/<project>/memory/, withMEMORY.mdas the index and one file per memory. Claude writes it, and it stays on this machine
You don't need to hunt for the paths: run /memory in Claude Code to list these files, open any of them in your editor, and switch auto memory on or off. To see which files actually loaded in this session, run /context.
If a project only has an AGENTS.md for other coding agents and no CLAUDE.md, Claude Code 2.1.277 or later reads the AGENTS.md directly.
Want the full memory template system?
Claude Memory Framework is the open-source version I use myself, with 4 memory categories plus auto memory templates
See the Memory Framework →