CertSafari
    Anthropic Claude Certified Architect – Foundations (CCAR-F)· Lessons

    Domain 3 · Lesson 13/30

    Modular CLAUDE.md with @imports and .claude/rules/

    Configure CLAUDE.md files with appropriate hierarchy, scoping, and modular organization

    9 min read
    3.33% of exam
    3 sources
    Published 4 Oct 2026
    Docs as of 30 Sep 2026

    What you will be able to do

    • Use @path imports to pull standards files and AGENTS.md into a CLAUDE.md
    • Split a monolithic CLAUDE.md into topic files under .claude/rules/, scoped with paths: frontmatter
    • Choose between per-directory CLAUDE.md files and central path-scoped rules for a monorepo

    1.Why one big CLAUDE.md stops working

    Teams tend to keep adding to the project CLAUDE.md until it covers everything: style, testing, API design, deployment, every package. The documentation gives a size target, and that target has a cost behind it. A long file takes up context in every session and makes Claude follow it less reliably.

    There are two separate tools for modularity, and they do different jobs. @imports keep the files tidy and reusable, but everything they reference is still loaded at launch. Path-scoped rules in .claude/rules/ also save context, because each one loads only when Claude works with files that match it. Whichever you use, group instructions under headers and bullets, because organized sections are easier for Claude to follow than dense paragraphs.

    Checkpoint 1 of 6· Check yourself

    Which change actually reduces how much CLAUDE.md content is in context at session start?

    Sources1

    2.The @import syntax

    Inside a CLAUDE.md, @ followed by a path pulls that file's contents in. You can import inline in a sentence or as a list item. A path starting with ~ points into your home directory, which lets a committed project file reference a personal file that each developer keeps for themselves.

    Imports inline, as list items, and from the home directorymarkdown
    See @README for project overview and @package.json for available npm commands for this project.
    
    # Additional Instructions
    - git workflow @docs/git-instructions.md
    
    # Individual Preferences
    - @~/.claude/my-project-instructions.md

    If an import points at a file outside your working directory, Claude Code asks you to approve external imports. The most common real-world use is a repository that already has an AGENTS.md shared with other AI coding tools. You don't need to duplicate it. Import it, then add the Claude-specific lines below the import.

    A CLAUDE.md that imports a shared AGENTS.md and adds Claude-only instructionsmarkdown
    @AGENTS.md
    
    ## Claude Code
    
    Use plan mode for changes under `src/billing/`.

    The difference between an import and an instruction written in words matters. A sentence like "read AGENTS.md first" doesn't load anything. Claude sees the file only if it decides to open it. The @AGENTS.md import guarantees the content is loaded, and keeping that import never causes Claude to read AGENTS.md twice.

    Checkpoint 2 of 6· Check yourself

    A CLAUDE.md contains only the sentence "Follow the conventions in AGENTS.md." What does Claude get at session start?

    Checkpoint 3 of 6· Exam question

    Two engineers on the same team report that Claude behaves inconsistently: one gets careful adherence to a 'always run the linter before committing' rule, while the other says Claude never mentions the linter at all, even in the same repository on the same branch. Before assuming the rule text is unclear, what is the fastest way to confirm whether the inconsistency is actually a memory-loading problem?

    Sources1

    3.Per-package CLAUDE.md files in a monorepo

    In a monorepo, the root CLAUDE.md holds what applies everywhere, such as coding standards and commit conventions. Each package then gets its own CLAUDE.md for the conventions of its stack.

    Instructions suited to a monorepo root CLAUDE.mdmarkdown
    Run package scripts from the package directory, not the monorepo root.
    Prefix commit subjects with the package name, for example `api: add rate limiting`.
    Never edit files under packages/*/generated/. Run `npm run codegen` in the package instead.

    A per-package file lives alongside its code, so the people who own that directory maintain its conventions, and the instructions are versioned with the code. Because import syntax works in any CLAUDE.md, a package maintainer can use @ to pull in only the shared standards files that apply to their package. For example, the API package's CLAUDE.md might import an API-conventions document that the web package has no use for. The sources show the per-package files and the import syntax separately, not one combined example. The pattern simply relies on the maintainer knowing which standards their package needs. If there are packages you never work in, claudeMdExcludes can skip their CLAUDE.md files altogether.

    Excluding every package's CLAUDE.md while keeping the rootjson
    {
      "claudeMdExcludes": [
        "**/packages/web/**"
      ]
    }

    Checkpoint 4 of 6· Check yourself

    Why is a per-package CLAUDE.md a good fit when each package has its own maintainers?

    Sources2

    4.Topic files in .claude/rules/

    Instead of one long file, .claude/rules/ holds one markdown file per topic. The documentation's example has code-style.md, testing.md and security.md next to the main .claude/CLAUDE.md. Rules files are committed like CLAUDE.md, and a user-level ~/.claude/rules/ exists for personal rules. A rule without frontmatter applies broadly. Adding a paths: field restricts it to files that match the given globs.

    A rule that loads only when Claude works with API TypeScript filesmarkdown
    ---
    paths:
      - "src/api/**/*.ts"
    ---
    
    # API Development Rules
    
    - All API endpoints must include input validation
    - Use the standard error response format
    - Include OpenAPI documentation comments

    Checkpoint 5 of 6· Fill the gap

    Which frontmatter field scopes this rule to matching files?

    ---
     ? :
      - "src/**/*.{ts,tsx}"
      - "lib/**/*.ts"
      - "tests/**/*.test.ts"
    ---

    Rules and per-directory CLAUDE.md files overlap, so choose deliberately.

    Per-directory CLAUDE.md versus path-scoped rules
    ApproachFile locationLoads whenUse when
    Per-directory CLAUDE.mdInside the directory, alongside its codeAt launch when started from that directory, or on demand when Claude reads a file thereDirectory owners maintain their own conventions; instructions are versioned with the code
    Path-scoped rule in .claude/rules/Central .claude/ at the repo rootWhen Claude works with a file matching the rule’s paths: globYou want all conventions in one place, or the same rule applies to many scattered paths

    Checkpoint 6 of 6· Check yourself

    A test-naming convention applies to test files scattered across twenty directories. Where should it go?

    Sources13

    Exam traps

    Each one states something that sounds right. Open it to see what is actually true.

    1. 1.Breaking CLAUDE.md into @imported files shrinks what loads into context at launch.Why is that wrong?

      Imported files load at launch too. Only path-scoped rules defer loading until Claude works with matching files.

      Covered in Why one big CLAUDE.md stops working

    2. 2.Writing "read AGENTS.md" in CLAUDE.md is as good as importing it.Why is that wrong?

      A reference in words only works if Claude decides to open the file. An @AGENTS.md import loads it reliably and never causes a double read.

      Covered in The @import syntax

    Practise it for real

    Replace part of a long CLAUDE.md with a path-scoped rule and confirm what loads

    1. 1.Create .claude/rules/api.md with paths: frontmatter set to "src/api/**/*.ts" and move your API instructions into it

      Why: Path-scoped rules load only when Claude works with matching files

      You should see: The API instructions are no longer part of the project CLAUDE.md

    2. 2.Start a session and run /context, checking the list under Memory files

      Why: /context shows which memory files actually loaded

      You should see: Your project CLAUDE.md is listed. If a file you expected is missing, Claude can't see it

    3. 3.Run /memory

      Why: It lists memory file locations across user and project scopes and lets you open each one

      You should see: You can tell user-level files from project-level files and open either in your editor

    Stuck? Get a nudge

    If a rule never seems to apply, check that its paths: glob actually matches the files Claude is working on.

    Sources

    Every claim above is drawn from one of these pages, quoted as it was written on the date shown.

    1. 1.
      “Size: target under 200 lines per CLAUDE.md file. Longer files consume more context and reduce adherence.”
      ↩︎ Why one big CLAUDE.md stops working
      “Organized sections are easier for Claude to follow than dense paragraphs.”
      ↩︎ Why one big CLAUDE.md stops working
      “Claude Code asks you to approve external imports”
      ↩︎ The @import syntax
      “A CLAUDE.md that already imports AGENTS.md | Your CLAUDE.md, with AGENTS.md included through the import”
      ↩︎ The @import syntax
      “Glob patterns that scope the rule to matching files. Accepts a YAML list or a comma-separated string”
      ↩︎ Topic files in .claude/rules/
      “Imports help you organize a long file but don’t reduce its context cost, because imported files also load at launch.”
      ↩︎ Exam trap 1
      “Keeping the import never makes Claude read AGENTS.md twice, whichever Project instructions value you use.”
      ↩︎ Exam trap 2
      “Imports help you organize a long file but don’t reduce its context cost, because imported files also load at launch.”
      ↩︎ Prediction
      “Move instructions that matter for only part of the codebase into path-scoped rules, which load only when Claude works with matching files.”
      ↩︎ Checkpoint
      “A CLAUDE.md that tells Claude in words to read AGENTS.md: Claude sees AGENTS.md only if it decides to open the file.”
      ↩︎ Checkpoint
    2. 2.
      “Root CLAUDE.md: instructions that apply everywhere, such as coding standards and commit conventions”
      ↩︎ Per-package CLAUDE.md files in a monorepo
      “Directory owners maintain their own conventions; instructions are versioned with the code”
      ↩︎ Per-package CLAUDE.md files in a monorepo
      “You want all conventions in one place, or the same rule applies to many scattered paths”
      ↩︎ Checkpoint
    3. 3.
      “Topic-scoped instructions, optionally path-gated”
      ↩︎ Topic files in .claude/rules/

    Spotted a mistake, or was something unclear? Tell us.