Task statement 3.3 · Claude Code configuration and workflows

Apply path-specific rules for conditional convention loading

In the monorepo, tests sit beside their code in every package, while Terraform lives only under packages/infra/terraform/. Each set of conventions must reach Claude when it works on those files, and stay out of context otherwise.

Why it's tested

The tempting fix is a CLAUDE.md in each directory, because that works for one folder. It loads only when Claude reads files in its own directory, so the test conventions get copied into every package and drift apart. The root CLAUDE.md avoids copies, but the conventions then cost tokens in every session, including the many that never use them. A skill avoids that cost, but it loads on demand, so nothing applies automatically.

KnowledgeHow a rule with paths loads

A rule is a Markdown file in .claude/rules/. Its optional YAML frontmatter can hold a paths field that lists glob patterns. A glob is a filename pattern in which * matches any characters within one folder name and ** matches any number of folders, so **/*.test.tsx matches every .test.tsx file at any depth. A rule without paths loads at launch, but a rule with paths waits until Claude reads a file whose path from the repository root matches a glob. A frontend-only session therefore never loads the Terraform conventions, which cuts irrelevant context and token usage.

  1. At launch, rules without paths load with CLAUDE.md.
  2. Rules with paths wait.
  3. Claude reads packages/api/src/orders.test.ts.
  4. Claude Code checks that path against every glob.
  5. Each matching rule loads into context.
repo/
├── .claude/rules/            testing.md · api-conventions.md · terraform.md · security.md
├── packages/web/src/         Button.tsx · Button.test.tsx
├── packages/api/src/         orders.ts · orders.test.ts
└── packages/infra/terraform/ main.tf

Interactive · choose the file Claude reads

Diagram of four rule files with glob path patterns, showing which ones load when Claude reads a given file in the monorepo FILE CLAUDE IS READING — none selected — packages/web/src/Button.test.tsx packages/api/src/orders.test.ts packages/api/src/orders.ts packages/infra/terraform/main.tf match path from the repository root, checked against every glob RULES IN .claude/rules/ testing.md paths: ["**/*.test.tsx", "**/*.test.ts"] No snapshot tests, mock at the network boundary idle loads not loaded api-conventions.md paths: ["packages/api/**/*"] Validate input at the edge, use the standard error envelope idle not loaded loads terraform.md paths: ["packages/infra/terraform/**/*"] Remote state only, every resource carries the cost-centre tag idle not loaded loads security.md (no paths field) Never log credentials — applies to everything, always loaded always

Choose the file Claude reads, and see which rules load with it.

Matches **/*.test.tsx, so the testing rule loads in packages/web. The API and Terraform rules stay out of context.

Matches **/*.test.ts and packages/api/**/*, so two rules load. The same testing rule now covers a second package.

Matches packages/api/**/* only. It is not a test file, so the testing rule does not load.

Matches packages/infra/terraform/**/*. Test and API conventions cost no tokens in this session.

Globs match the path of the file Claude reads, not the launch directory. The testing rule loads for tests in both packages/web/ and packages/api/, which a CLAUDE.md inside one package cannot do. security.md has no paths, so it always loads.

More precise than the guide. The guide says a path-scoped rule loads when Claude is editing a matching file. The docs say it triggers when Claude reads one, which normally happens before an edit (checked 2026-10-01). Exam answer: the rule loads when Claude edits a matching file.

KnowledgeThree places a convention can live

Three mechanisms can hold a convention, and they differ in what makes them load. A subdirectory CLAUDE.md is tied to one directory, so it suits files that share a folder, like Terraform. A paths rule is tied to what the file is, so it suits one file type spread across the codebase, like tests. A skill loads when a developer invokes it or Claude judges it relevant, so it suits an on-demand task, not a standard that must always hold.

Subdirectory CLAUDE.md
packages/infra/CLAUDE.md

Loadson reading a file in its directory

Rule with paths
paths: ["**/*.test.tsx"]

Loadson reading a matching file, anywhere

Skill
/release-checklist

Loadswhen invoked or judged relevant

More precise than the guide. Skills now accept paths too: Claude then loads the skill automatically only when working with matching files (checked 2026-10-01). Skills are still meant for task-specific workflows. Exam answer: a .claude/rules/ rule with a paths glob, for conventions that must apply automatically by file type.

SkillMoving the test conventions into a rule

Claude writes packages/api/src/orders.test.ts with snapshot tests, which the team banned. The ban sits in packages/web/CLAUDE.md, which loads only when Claude reads files in packages/web/, and this session never did. The fix moves the conventions into one rule whose globs match tests in every package. The guide's paths: ["terraform/**/*"] works the same way, but it matches a root-level terraform/ folder, so here the glob names the full path.

# .claude/rules/testing.md
---
paths: ["**/*.test.tsx", "**/*.test.ts"]
---
- No snapshot tests. Assert on rendered text or role.

# .claude/rules/terraform.md
---
paths: ["packages/infra/terraform/**/*"]
---
Ask one question: which files does this convention apply to?
Files in one directoryA CLAUDE.md there, or a rule whose glob names it.
One file type, many directoriesA rule whose paths glob matches the type.
Every fileThe root CLAUDE.md, or a rule without paths.
Takeaway
  • Globs match from the repository root, so **/*.test.tsx finds tests in every package.
  • A subdirectory CLAUDE.md covers one folder and a skill waits to be needed.
  • A paths rule costs no tokens until Claude reads a matching file.

check yourself

0 / 3 answered

Every package in the monorepo has its own Dockerfile, and the platform team wants the same Docker conventions (pinned base-image digests, a non-root user) applied whenever Claude works on any of them. A new package is added most months. Most sessions never touch a Dockerfile, and nobody should have to invoke anything.What is the most maintainable way to deliver these conventions?

Select one.

The root CLAUDE.md holds 150 lines of Terraform conventions for packages/infra/terraform/ and 40 lines of test conventions. Test files live in both packages/web and packages/api. Most sessions are frontend work, yet every one loads all 190 lines. Each convention must still apply automatically wherever it is relevant.Which TWO changes best cut that context cost while keeping each convention automatic?

Select two.

A teammate added .claude/rules/api.md with paths: ["src/api/**/*.ts"]. The session was launched at the repository root. After Claude read and edited packages/api/src/handlers/orders.ts, /context lists .claude/rules/security.md, which has no paths field, but not api.md.What is the most likely root cause?

Select one.

sources

  1. Claude Code Docs, "How Claude remembers your project", "Path-specific rules": the paths frontmatter field, the glob pattern table, "Rules without a paths field are loaded unconditionally", path-scoped rules "trigger when Claude reads files matching the pattern, not on every tool use", and subdirectory CLAUDE.md files that load when Claude reads files in those subdirectories. Checked 2026-10-01.
  2. Claude Code Docs, "Extend Claude with skills", frontmatter reference: a skill's paths field, with which "Claude loads the skill automatically only when working with files matching the patterns", and full skill content that loads only when invoked. Checked 2026-10-01.
  3. The paths: ["terraform/**/*"] and **/*.test.tsx examples, "editing matching files", and test files spread throughout a codebase: Claude Certified Architect — Foundations Exam Guide v1.0, Domain 3.3 and Sample Question 6. The monorepo layout is this course's Scenario 2 detail.