Day 21 of 52 · about 20 min · Context
Split CLAUDE.md into rules that load when needed
A long CLAUDE.md costs context in every session, even when most of it covers files you aren’t touching. Rules that load only for matching files keep startup light and sit next to the work they are for.
You’ll finish with
- Two path-scoped rules in
.claude/rules/and a shorterCLAUDE.md - An
@pathimport, and why it doesn’t save context - A look at what auto memory saved, through
/memory
You’ll need
- The Day 21 kit, or your own project with a
CLAUDE.md(Day 1)
Before you start
Tell us about your setup and the steps change to fit it. Your answers stay in this browser, and you can change them at any time.
Which system are you on?
Commands differ between systems. Pick the one you’ll run Claude Code on.
The steps
One step at a time. When a step’s check matches, tick it and the next one opens.
Step 1 of 4: Move topic rules into .claude/rules/
Give each topic its own file that loads only for matching files.The code rules in
CLAUDE.mdonly matter when Claude touches code. Move them into.claude/rules/, one topic per file. Thepathslist makes a rule load only when Claude reads or edits a matching file..claude/rules/pricing.mdMarkdown--- paths: - "src/quote.js" --- # Pricing rules - `src/quote.js` stays pure: no file, network or console access. Input and output belong in `src/cli.js`. - Money is whole cents (integers) inside `src/quote.js`. Only `formatMoney` turns cents into text. - Round to the cent with `Math.round` at each step: each line, the discount, the VAT. - The discount comes off before VAT is added.acme-quotes/
- folder .claude
- folder rulesNew
- pricing.mdNewLoads with
src/quote.js - code-style.mdNewLoads with files in
src/andtest/
- settings.json
- CLAUDE.mdChangedCode rules moved out
- README.md
Without a paths list, a rule loads in every session like CLAUDE.md. Check it worked
Both rule files start with a
paths:list between two---lines.If it didn’t work
A rule seems to load in every session
Its frontmatter didn’t parse, so it counts as a rule without paths. Check the
---lines and quotes;claude --debugshows the error.Step 2 of 4: Import a file with @path
Point CLAUDE.md at an existing file instead of repeating it.Write
@and a path anywhere inCLAUDE.mdto pull in that file. Imports keepCLAUDE.mdshort to read, but the imported file still loads at launch, so only path rules save context.Changes to CLAUDE.md
Unchanged: # Acme QuotesRemoved: A command-line quote calculator for a small services business. It prices hoursRemoved: per role from a rate card, takes off an optional discount, adds VAT and printsRemoved: the total. Plain Node.js with no dependencies.Added: A command-line quote calculator for a small services business. Plain Node.jsAdded: with no dependencies. What it does and how to run it: @README.mdUnchanged: ## CommandsThe README now loads through an import. Relative paths start from the importing file. Start Claude Code and askWithout opening any files: how do I run the quote script directly with node, not npm?Check it worked
Claude answers with
node src/cli.js, which onlyREADME.mdmentions.Step 3 of 4: See what loads when
Check what loaded at launch, then trigger the pricing rule.In Claude CodeYou type: /context
What happens: Under Memory files,
CLAUDE.mdis listed. The path rules aren’t, because nothing has touchedsrc/yet.You type: Read src/quote.js, then list the project rules that apply to it.
What happens: Reading
src/quote.jsloads both rules, so Claude can list them.Launch loads CLAUDE.md. Path rules wait for a matching file. Check it worked
Claude lists the cents, rounding and discount rules from
pricing.md.Step 4 of 4: Review what auto memory saved
Open /memory to see your instruction files and Claude’s own notes.Claude also keeps its own notes per project, such as corrections you gave it. The first 200 lines of its
MEMORY.mdindex load in every session, so check them now and then.In Claude CodeYou type: /memory
What happens: Lists your
CLAUDE.mdfiles and has a switch for auto memory.What happens: Choose the option that opens the auto memory folder.
Memory notes are plain Markdown. Edit or delete anything wrong. Check it worked
You can read each note Claude saved. A new project may have none yet.
Finish · 4 of 4 steps to go
Instructions load when they matter
CLAUDE.md for what every session needs and give each topic a rule with paths.What you’ll have checked
CLAUDE.mdis shorter and importsREADME.md- The pricing rule loads after Claude reads
src/quote.js /memoryopens the auto memory folder
Lesson updates by email
Get lesson updates by email
Leave your email and we’ll tell you when we add or update a lesson.
Claude Code for your team
Want Claude Code set up across your team?
HorizonLux sets up and repairs Claude Code for teams: CLAUDE.md rules, hooks that enforce them and reviewed MCP servers. Book a free call to talk it through.
Related
Questions
Questions about Day 21
Should I use a rule or a nested CLAUDE.md?
Both target part of the project. A nested `CLAUDE.md` lives beside its code; rules keep every convention in `.claude/rules/`. Day 46 covers big repositories.
Sources
Checked against the official Claude Code docs on .
Independent resource, not affiliated with Anthropic. HorizonLux wrote this lesson; Claude Code is made by Anthropic.