AI Skill Certs
Claude Code Configuration & Workflows·Task 3.3·Bloom: understand·Difficulty 2/5·8 min read·Updated 2026-06-07

Claude Code Token Efficiency with Path-Scoped Rules

Apply path-specific rules for conditional convention loading

SUBy Solomon UdohReviewed by Solomon UdohAI-assisted · human-reviewed
In short
Token efficiency with path-scoped rules is the practice of keeping conventions out of Claude Code's context window until they are relevant. Because a rule with a paths glob loads only when Claude reads a matching file, instructions for code you are not touching never consume tokens, leaving more of the context budget for the task at hand.

Why Claude Code token efficiency depends on what loads at launch

Claude Code token efficiency is decided almost entirely by one question: what gets loaded into the context window before you have even typed a prompt? Every Claude Code session begins by assembling a startup context, the system prompt, any auto memory, your CLAUDE.md files, and every unconditional rule, and all of it is loaded in full. Those tokens are spent for the whole session whether or not the instructions are relevant to what you are about to do. If half your configuration is about infrastructure and you are editing a stylesheet, that half is dead weight sitting in the window.

Path-scoped rules attack exactly this waste. Because a rule with a paths glob is injected only when Claude reads a file that matches, the conventions for code you are not touching never enter context at all. The result is a leaner startup and a context budget that holds far more of the thing you actually care about, the files, conversation, and command output of the task in front of you. This knowledge point is assessed at the understand level, so the goal is to be able to explain that relationship clearly: conditional loading is a token-efficiency mechanism, not just a tidiness one.

Token efficiency (path-scoped rules)
The reduction in context-window usage you get by loading conventions conditionally. A path-scoped rule consumes tokens only in sessions where Claude reads a matching file; in every other session it costs nothing, unlike CLAUDE.md and unconditional rules, which load in full at launch.

Every always-on instruction is a standing tax

It helps to see the startup context as a budget with a hard ceiling. CLAUDE.md files are loaded in full at the start of every conversation regardless of length, and they sit alongside the system prompt and any memory before your work even begins. Each line you add is a line that occupies the window all session long. That is the concrete reason the official sizing guidance exists: keep a CLAUDE.md under roughly two hundred lines, because longer files both cost more tokens and reduce how reliably Claude follows them.

The second half of that sentence is the part people underweight. Token efficiency is not only about cost; it is about quality. Model performance degrades as the context window fills, and a window crowded with irrelevant React rules while you debug a database migration is a window where the migration details have to compete for attention. So trimming what loads is doing two jobs at once: spending fewer tokens, and keeping the signal-to-noise ratio high enough that Claude actually heeds the instructions that matter right now.

How path-scoped rules trim the bill

Path scoping converts an always-on tax into a pay-per-use one. Take five bodies of convention, frontend, backend, tests, infrastructure, and security, and put each in a .claude/rules/ file with a paths glob. On any given session, only the rules whose globs match the files Claude reads are injected. Edit a component and you pay for the frontend rule; edit a Terraform module and you pay for the infrastructure rule; in neither case do you pay for the other four. The startup context shrinks to the system essentials, and the conventional weight arrives just-in-time.

Context budget: always-on versus path-scoped
Loading diagram...
With everything in CLAUDE.md, all conventions load at launch. With path-scoped rules, only the convention matching the file you touch enters context.
at launch
CLAUDE.md loads in full, every session
on match
path-scoped rules load only when relevant
0 tokens
cost of an unmatched scoped rule

The import trap: organisation is not savings

A common wrong turn is to break a giant CLAUDE.md into several files with @import and call it a token optimisation. It is not. Imported files are expanded into context the moment a session starts, right alongside the file that references them, so the token bill is identical to pasting their contents inline. Importing genuinely helps readability and removes duplication, but it does not defer a single token. The only built-in mechanism that actually lowers startup cost by loading instructions conditionally is the path-scoped rule. If a question frames @import as a way to shrink context, that framing is the error; the fix is to move the conditional material into a rule with a paths glob instead.

Worked example

A project keeps all of its conventions in one 700-line CLAUDE.md covering frontend, backend, tests, infrastructure, and security. A developer spends a session editing only Terraform files under infra/. They want to understand why the session feels sluggish and how to make it more token-efficient without losing any conventions.

First, account for what loads. At launch the entire 700-line CLAUDE.md enters the context window, on top of the system prompt and memory. For a session that touches nothing but Terraform, four of the five convention areas, frontend, backend, tests, and security, are pure overhead. They consume tokens for the whole session and add noise that competes with the infrastructure work for the model's attention.

Now restructure for efficiency without dropping anything. Split the five areas into five .claude/rules/ files, each with a matching paths glob: "**/*.{ts,tsx}" for frontend, "**/routers/**" for backend, "**/*.test.*" for tests, "infra/**/*.tf" for infrastructure, and a security glob for the sensitive paths. Keep only the genuinely universal facts, build commands, repo layout, in the slim root CLAUDE.md.

Re-run the same Terraform session against this layout. Now the startup context carries the small CLAUDE.md plus, once Claude reads a file under infra/, just the infrastructure rule. The other four rule files stay dormant and contribute zero tokens. You have not deleted a single convention; you have changed when each one loads. The session is leaner and the infrastructure rules face less competition for attention, which is the dual payoff path scoping is meant to deliver. The one judgement to keep in mind is that anything you consider non-negotiable at file-creation time may need to stay unconditional, since scoped rules trigger on reads, but everything else is a clear win for the context budget.

Common misreadings to avoid

These two confusions both lead people to think they have made a session token-efficient when they have not.

Misconception

Splitting a large CLAUDE.md into several @import files reduces the tokens my configuration consumes.

What's actually true

Imported files expand into context at launch alongside the file that imports them, so the total token cost is unchanged. Imports help organisation, not efficiency. To actually keep conventions out of context until needed, use path-scoped rules with a paths glob.

Misconception

A path-scoped rule still costs its tokens every session; the paths field just labels which files it is about.

What's actually true

A scoped rule is loaded only when Claude reads a file matching its glob. In a session that never touches a matching file, the rule contributes zero tokens. That conditional loading is precisely what makes path scoping a token-efficiency tool rather than a labelling convenience.

When in a session the cost actually lands

A subtle but useful detail is when a scoped rule's tokens are spent within a session. Because the trigger is a matching read, the rule contributes nothing at launch and nothing while Claude works on unrelated files; its cost appears only at the moment Claude first reads a file the glob matches, and then it stays in context for the remainder of that session. So path scoping does not merely lower the average context cost across many sessions, it also defers the cost inside a single session until the convention becomes relevant. A long session that touches infrastructure only near the end carries no infrastructure rules through its first hour. This timing is what makes conditional loading feel free in practice: you pay for a convention exactly once you start doing the work it governs, and not a moment earlier.

What still loads no matter what

Path scoping is powerful, but it only trims one layer of the startup context, so it helps to know the floor it cannot move. Every session begins with an irreducible core: the system prompt that defines Claude's behaviour and tool use, a block of environment information, and the first slice of auto memory, the opening 200 lines or 25KB of MEMORY.md, whichever comes first. On top of that sit the CLAUDE.md files in scope, which load in full regardless of length, and any unconditional rules. None of that is affected by a paths glob. What path scoping removes is the conditional layer: the area-specific conventions that would otherwise load even when irrelevant.

That framing keeps expectations honest. Moving five rule sets behind globs will not zero out your startup context, because the system prompt, memory, and universal CLAUDE.md remain. It will, however, eliminate the conventions you are not using this session, which on a configuration-heavy project is frequently the largest movable chunk. Understanding the difference between the fixed floor and the conditional layer is what lets you predict, rather than guess, how much a refactor will actually save.

Managing the budget beyond rule scoping

Token efficiency is a portfolio of habits, and path scoping is one lever among several the tooling gives you. The context-window visualisation shows precisely what loads at startup and what each file read costs, which is the fastest way to see whether your configuration, not your conversation, is the thing filling the window. A custom status line can track usage continuously as a session runs, turning context pressure from an invisible problem into a number you watch. And once a session is underway, /clear between unrelated tasks resets the window entirely, while /compact summarises history when you approach the limit, both of which protect the budget that path scoping freed up at launch.

In a monorepo there is one more lever worth knowing: claudeMdExcludes lets you skip ancestor CLAUDE.md files or whole rules directories that belong to other teams, so their always-on instructions never enter your context in the first place. Put together, the discipline is layered, scope conditional conventions with globs, keep the universal CLAUDE.md lean, exclude what other teams impose, and clear or compact as you work. Path scoping is the piece this knowledge point isolates, but the exam expects you to see it as part of that larger context-budget picture.

How this shows up on the exam

At the understand level, expect questions that ask you to explain or predict context cost rather than write globs. A frequent setup contrasts two ways of organising the same conventions and asks which is more token-efficient, with @import dangled as a tempting but wrong answer because imports load at launch. Another setup describes a sluggish session full of irrelevant rules and asks what change reduces context usage; the answer is to move conditional conventions into path-scoped rules so only the relevant ones load. The throughline is always the same mechanism: what loads at launch is paid for all session, and path scoping is the only built-in way to defer that cost until a convention is actually relevant.

Check your understanding

Two teams store identical conventions. Team A keeps one 600-line CLAUDE.md. Team B splits the same content into five .claude/rules/ files, each with a paths glob for its area. During a session that edits only frontend components, which statement about token usage is correct?

People also ask

Do path-scoped rules save tokens in Claude Code?
Yes. A rule with a paths glob loads only when Claude reads a matching file, so conventions for code you are not touching stay out of the context window and cost nothing. Unconditional rules and CLAUDE.md load in full at the start of every session.
Why is my Claude Code context filling up?
Most startup bloat comes from large always-on configuration: a long CLAUDE.md, many unconditional rules, and imported files, all of which load in full at launch. Move conditional conventions into path-scoped rules and keep CLAUDE.md under about 200 lines to free up the budget.
Does @import reduce context usage?
No. Imported files are expanded into context at session start alongside the file that references them, so the token cost is the same as inlining them. Use path-scoped rules when you want a convention to stay out of context until it is relevant.

Watch and learn

Official Anthropic Academy lessons first, then hand-picked walkthroughs. Videos load only when you press play.

DIY Smart Code

Claude Code's Memory System: The Full Guide (Most Developers Miss 90% of This)

Why watch: Shows how conditional, path-scoped rules load only when relevant, directly demonstrating the token and context savings versus always-loaded instructions.

More videos for this concept

References & primary sources

Adaptive study

Master this concept with Archie

Practice it inside an adaptive study session. Archie, your Socratic AI tutor, tracks your mastery with Bayesian Knowledge Tracing and schedules the perfect next review.

Start studying