Skip to content

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 shorter CLAUDE.md
  • An @path import, 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.

0 of 4 steps done0%
  1. 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.md only matter when Claude touches code. Move them into .claude/rules/, one topic per file. The paths list 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/ and test/
      • 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 --debug shows the error.

  2. 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 in CLAUDE.md to pull in that file. Imports keep CLAUDE.md short to read, but the imported file still loads at launch, so only path rules save context.

    Changes to CLAUDE.md

    Unchanged: # Acme Quotes
    Removed: A command-line quote calculator for a small services business. It prices hours
    Removed: per role from a rate card, takes off an optional discount, adds VAT and prints
    Removed: the total. Plain Node.js with no dependencies.
    Added: A command-line quote calculator for a small services business. Plain Node.js
    Added: with no dependencies. What it does and how to run it: @README.md
    Unchanged: ## Commands
    The README now loads through an import. Relative paths start from the importing file.
    Start Claude Code and ask
    Without 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 only README.md mentions.

  3. Step 3 of 4: See what loads when

    Check what loaded at launch, then trigger the pricing rule.
    In Claude Code

    You type: /context

    What happens: Under Memory files, CLAUDE.md is listed. The path rules aren’t, because nothing has touched src/ yet.

    You type: Read src/quote.js, then list the project rules that apply to it.

    What happens: Reading src/quote.js loads 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.

  4. 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.md index load in every session, so check them now and then.

    In Claude Code

    You type: /memory

    What happens: Lists your CLAUDE.md files 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

Keep CLAUDE.md for what every session needs and give each topic a rule with paths.

What you’ll have checked

  • CLAUDE.md is shorter and imports README.md
  • The pricing rule loads after Claude reads src/quote.js
  • /memory opens 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.

We’ll email you when we add or update a lesson. We use your email only for this. Privacy policy

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.

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.