The Real Reason AI Coding Automation Fails: The Curse of a 300-Line CLAUDE.md and the Conditional-Rules Fix
AI coding agents raise developer productivity dramatically. But the moment you use one in practice, you hit a wall: the token cost bomb and the drop in instruction compliance.
Put your TypeScript conventions, React component rules, API route guidance, and security guidelines all into a project configuration file called CLAUDE.md, and the file quickly runs past several hundred lines. The official documentation warns that once a file exceeds 200 lines, the model's rule compliance rate drops sharply [00:00:34].
You start a single documentation edit session, and several hundred lines of coding rules are loaded into context wholesale, while the instructions that actually matter get ignored [00:01:13]. Tokens are spent and the density of the output falls. To solve this you have to understand and apply the conditional rules and file reference structures that Claude Code provides.
Original video: Claude Code Introduction E23
1. Static integration (@ import) versus dynamic loading (paths)
When CLAUDE.md becomes bloated, the approaches split in two. One does not save tokens. The other genuinely does.
The @ mention import (static integration)
You write a file path such as @README.md or @package.json inside CLAUDE.md to merge instructions [00:05:13].
- Reference depth is supported up to 5 levels
[00:05:48]. - It is loaded into context unconditionally at session start. Splitting and managing files becomes easier, but the token cost itself does not go down
[00:06:57].
In short, this is a solution to management convenience, not to cost. Merely having split your rules across files does not relieve the context pressure.
.claude/rules/ and the paths frontmatter (dynamic conditional loading)
The mechanism that actually saves tokens lives here [00:07:20].
- Distribute markdown files by topic (for example
testing.md,security.md) in the.claude/rules/directory, and specify apathsglob pattern in YAML at the top of the file[00:03:08]. - Instead of always loading at session start, the rule is activated dynamically at the moment the AI actually reads a file matching the pattern, such as
src/api/*/.ts[00:02:56]. - During unrelated work (for example editing a sentence in the README), unnecessary rules do not occupy context, so token cost drops sharply and instruction compliance rises
[00:02:56].
The decisive difference is when loading happens. Static integration stacks everything at startup; conditional loading injects only the rule in question, at the moment it is needed. The larger the project, the more this gap grows: not linearly, but proportionally.
2. Rule precedence and monorepo/team sharing strategy
When rules conflict across several layers, Claude Code's loading precedence works as follows [00:08:34].
- Personal rules (
~/.claude/rules/): personal preferences applied across the whole machine[00:08:02]. - Team-wide rules (
.claude/rules/): standard guidance committed to the Git repository and shared with every team member[00:08:55]. - How precedence behaves: personal rules load first, and the team project rules that load later sit closer in context, so the team standard overrides the personal preference
[00:08:34].
In multi-repository or monorepo environments, when you need to synchronize company-wide security rules or standard guides, using symbolic links lets you update everything in one place [00:09:47].
3. A five-step checklist when rules do not apply
After applying conditional rules, "why isn't the rule I wrote taking effect?" is a common situation. Checking in the following order narrows the cause down quickly [00:14:21].
- Check the actual load state with the
/memorycommand: inspect the directory listing of which files are loaded in the current session[00:12:05]. - Validate the glob pattern: check that the
pathspattern matches the target file path. Matching is done against a path relative to the working directory, not an absolute path[00:15:00]. - Check whether the Read trigger fired: a plain
lsor bash command is not enough. Claude must actually execute the Read tool on the file for the rule to activate[00:15:07]. - Use the
instructions_loadedhook: set up an observation hook underhooksto record and analyze, in an audit log, the moment a rule loads and the reason why[00:12:56]. - Check for conflicting rules: verify that no other
rulesfile contains the exact opposite instruction[00:14:46].
Conclusion: precise context design is the real competitive edge
In an era where agents flood the market, stuffing every instruction into the prompt leaves nothing but a cost bomb and degraded quality as side effects.
A design like .claude/rules/ and the paths frontmatter — injecting the minimum necessary context only at the moment it is needed — is what turns an AI tool into a genuine productivity weapon. Writing fewer rules is not a virtue. Rules being read precisely, at the exact moment they are required, is design.
References
- Original video: 새로운 시작 (neosarchizo) channel — Claude Code Introduction E23
- The
[00:00:34]timestamps in the body refer to positions in the original video - Detailed rule behavior may change with Claude Code updates, so check the official documentation for the currently deployed version
How to install the document skills used above
This guide references Claude Code rules. If you also want the document tooling, the official Anthropic skill repository is available:
/plugin marketplace add anthropics/skills
/plugin install document-skills@anthropic-agent-skills
The repository exposes skills/docx, skills/pdf, skills/pptx, and skills/xlsx as open source. Keep in mind that document skills follow progressive disclosure: roughly 100 tokens of metadata per skill are always resident, the SKILL.md body stays under 5k tokens and loads only on trigger, and scripts load only when they are actually needed. That structure is the same principle this article recommends for project rules.
AI Knowledge Hub
Comments (1)
To start with the conclusion: "200 lines" is only a proxy metric offered by the vendor, and the real cost metric is the number of tokens. Measured, the same 200-line document can be 2,300 tokens or 6,600 tokens. Before adopting conditional loading, it's more accurate to first measure the token count of your own rules file.
1. Measurement: a rules file's tokens aren't proportional to its line count
These are the actual measured values of rules/guide files in this comment's environment (tiktoken 0.13.0, o200k_base).
The tokens/line of short rules files is 3–4 times higher than that of documents. When Korean instructions with low compressibility are mixed with checklists and tables, density rises; code- and guide-heavy documents drop to 7–9. In other words, "what kind of text is it" determines the cost, more than "how many lines it is."
2. Converting 200 lines into tokens
This is the distribution obtained by measuring 41 Korean technical documents (150–320 lines) the same way.
Even for the same 200 lines, it ranges from 2,300 tokens to over 3,100 depending on content density. Applying the rules-file density (33 tokens/line), 200 lines exceeds 6,600 tokens. So it's safer to set the threshold by token count rather than line count.
3. Cost is the product of the fixed prefix and the number of turns
Rules loaded at session start are resent every turn. A 500-line (6,520-token) rules file over a 30-turn conversation means roughly 195,600 tokens move back and forth for the rules alone. That cumulative product is why the savings effect attaches linearly to file size. The body's phrase "not linear but proportional" refers to this structure.
4. In environments with prompt caching, the calculation can flip
Conditional loading reduces total tokens but breaks the stability of the prefix. Always-loaded fixed rules keep a repeating prefix intact and can be processed cheaply via cache. Conversely, if rules are attached and detached each turn, the prefix changes, the cache is invalidated, and it may be billed at the more expensive miss-token rate. Therefore the savings verdict should be made with "cache-miss tokens," not "total tokens." Cache support and minimum prefix length differ by runtime, so checking your tool's documentation is necessary.
5. The blind spot of Read-triggered conditional loading
There's a flaw that follows from the body's point 3 (rule activation occurring at file Read time). It's the path of creating without reading. Work that creates a new component or module from scratch isn't preceded by reading an existing file, so the rules needed at that moment may not load. Scaffolding rules like naming, directory structure, and forbidden patterns are safer placed in an always-loaded file rather than under a paths condition, or else the procedure should explicitly read a reference file before generation. This behavior needs re-confirmation in the currently deployed version.
6. Alternative patterns in tools that don't support conditional loading
Not every agent supports the paths frontmatter. Even in tools that have only always-injected rules files, the same effect can be achieved.
In this structure, the static injection carries only "what to read when," and the actual cost is incurred only when the condition is met.
References