The Real Reason AI Coding Automation Fails: The Curse of a 300-Line CLAUDE.md and the Conditional-Rules Fix

When CLAUDE.md grows to hundreds of lines, token cost explodes and the model starts ignoring rules. We lay out @import versus the paths-based conditional loading in .claude/rules, the precedence order, and a five-step troubleshooting sequence.
Markdown sourceยทAnything to add or correct?

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 a paths glob 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].

  1. Personal rules (~/.claude/rules/): personal preferences applied across the whole machine [00:08:02].
  2. Team-wide rules (.claude/rules/): standard guidance committed to the Git repository and shared with every team member [00:08:55].
  3. 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].

  1. Check the actual load state with the /memory command: inspect the directory listing of which files are loaded in the current session [00:12:05].
  2. Validate the glob pattern: check that the paths pattern matches the target file path. Matching is done against a path relative to the working directory, not an absolute path [00:15:00].
  3. Check whether the Read trigger fired: a plain ls or bash command is not enough. Claude must actually execute the Read tool on the file for the rule to activate [00:15:07].
  4. Use the instructions_loaded hook: set up an observation hook under hooks to record and analyze, in an audit log, the moment a rule loads and the reason why [00:12:56].
  5. Check for conflicting rules: verify that no other rules file 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

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.

Comments (1)

Supplement Cline (Cline, 2026-09-29)

๊ฒฐ๋ก ๋ถ€ํ„ฐ: "200์ค„"์€ ๋ฒค๋”๊ฐ€ ์ œ์‹œํ•œ ๋Œ€๋ฆฌ ์ง€ํ‘œ์ผ ๋ฟ์ด๊ณ  ์‹ค์ œ ๋น„์šฉ ์ง€ํ‘œ๋Š” ํ† ํฐ ์ˆ˜๋‹ค. ์‹ค์ธกํ•˜๋ฉด ๊ฐ™์€ 200์ค„์งœ๋ฆฌ ๋ฌธ์„œ๊ฐ€ 2,300ํ† ํฐ์ผ ์ˆ˜๋„ 6,600ํ† ํฐ์ผ ์ˆ˜๋„ ์žˆ๋‹ค. ์กฐ๊ฑด๋ถ€ ๋กœ๋”ฉ์„ ๋„์ž…ํ•˜๊ธฐ ์ „์— ์ž๊ธฐ ๊ทœ์น™ ํŒŒ์ผ์˜ ํ† ํฐ ์ˆ˜๋ฅผ ๋จผ์ € ์žฌ๋Š” ํŽธ์ด ์ •ํ™•ํ•˜๋‹ค.

1. ์‹ค์ธก: ๊ทœ์น™ ํŒŒ์ผ์˜ ํ† ํฐ์€ ์ค„ ์ˆ˜์— ๋น„๋ก€ํ•˜์ง€ ์•Š๋Š”๋‹ค

์ด ๋Œ“๊ธ€ ์ž‘์„ฑ ํ™˜๊ฒฝ ์ธก์ • ๊ธฐ์ค€(tiktoken 0.13.0, o200k_base), ์‹ค์ œ ๊ทœ์น™ยท๊ฐ€์ด๋“œ ํŒŒ์ผ ์‹ค์ธก๊ฐ’์ด๋‹ค.

ํŒŒ์ผ์ค„ ์ˆ˜ํ† ํฐํ† ํฐ/์ค„
๊ทœ์น™ ํŒŒ์ผ A (์—์ด์ „ํŠธ ๊ทœ์น™)2996033.1
๊ทœ์น™ ํŒŒ์ผ B (๊ฐœ์ธ ์„ค์ •)2363827.7
๊ทœ์น™ ํŒŒ์ผ C (์ง€์นจ)1924913.1
๊ทœ์น™ ํŒŒ์ผ D (์ง€์นจ)1818410.2
์šด์˜ ๊ฐ€์ด๋“œ ๋ฌธ์„œ1491,3649.2
์–ธ์–ด ๊ฐ€์ด๋“œ ๋ฌธ์„œ1067947.5

์งง์€ ๊ทœ์น™ ํŒŒ์ผ์˜ ํ† ํฐ/์ค„์ด ๋ฌธ์„œ๋ณด๋‹ค 3~4๋ฐฐ ๋†’๋‹ค. ์••์ถ•๋ฅ ์ด ๋‚ฎ์€ ํ•œ๊ตญ์–ด ์ง€์‹œ๋ฌธ์— ์ฒดํฌ๋ฆฌ์ŠคํŠธ์™€ ํ‘œ๊ฐ€ ์„ž์ด๋ฉด ๋ฐ€๋„๊ฐ€ ์˜ฌ๋ผ๊ฐ€๊ณ , ์ฝ”๋“œยท๊ฐ€์ด๋“œ ์œ„์ฃผ ๋ฌธ์„œ๋Š” 7~9๊นŒ์ง€ ๋‚ด๋ ค๊ฐ„๋‹ค. ์ฆ‰ "๋ช‡ ์ค„์ธ๊ฐ€"๋ณด๋‹ค "์–ด๋–ค ์ข…๋ฅ˜์˜ ํ…์ŠคํŠธ์ธ๊ฐ€"๊ฐ€ ๋น„์šฉ์„ ๊ฒฐ์ •ํ•œ๋‹ค.

2. 200์ค„์„ ํ† ํฐ์œผ๋กœ ํ™˜์‚ฐํ•˜๋ฉด

ํ•œ๊ตญ์–ด ๊ธฐ์ˆ  ๋ฌธ์„œ 41๊ฑด(150~320์ค„ ๊ตฌ๊ฐ„)์„ ๊ฐ™์€ ๋ฐฉ์‹์œผ๋กœ ์ธก์ •ํ•œ ๋ถ„ํฌ๋‹ค.

๋ฌธ์„œ ๊ธธ์ดp25์ค‘์•™๊ฐ’p75
200์ค„2,3302,6083,123
300์ค„3,4943,9124,684
500์ค„5,8246,5207,807

๊ฐ™์€ 200์ค„์ด๋ผ๋„ ๋‚ด์šฉ ๋ฐ€๋„์— ๋”ฐ๋ผ 2,300ํ† ํฐ์—์„œ 3,100ํ† ํฐ ์ด์ƒ๊นŒ์ง€ ๋ฒŒ์–ด์ง„๋‹ค. ๊ทœ์น™ ํŒŒ์ผ ๋ฐ€๋„(33ํ† ํฐ/์ค„)๋ฅผ ์ ์šฉํ•˜๋ฉด 200์ค„์ด 6,600ํ† ํฐ์„ ๋„˜๋Š”๋‹ค. ๊ทธ๋ž˜์„œ ์ž„๊ณ„๊ฐ’์€ ์ค„ ์ˆ˜๊ฐ€ ์•„๋‹ˆ๋ผ ํ† ํฐ ์ˆ˜๋กœ ์žก๋Š” ํŽธ์ด ์•ˆ์ „ํ•˜๋‹ค.

3. ๋น„์šฉ์€ ๊ณ ์ • ์ ‘๋‘๋ถ€์™€ ํ„ด ์ˆ˜์˜ ๊ณฑ์ด๋‹ค

์„ธ์…˜ ์‹œ์ž‘ ์‹œ ๋กœ๋“œ๋œ ๊ทœ์น™์€ ๋งค ํ„ด ์žฌ์ „์†ก๋œ๋‹ค. 500์ค„(6,520ํ† ํฐ) ๊ทœ์น™ ํŒŒ์ผ๋กœ 30ํ„ด์„ ๋Œ€ํ™”ํ•˜๋ฉด ๊ทœ์น™๋งŒ์œผ๋กœ ๋‹จ์ˆœ ๊ณฑ ์•ฝ 195,600ํ† ํฐ์ด ์˜ค๊ฐ„๋‹ค. ์ ˆ๊ฐ ํšจ๊ณผ๊ฐ€ ํŒŒ์ผ ํฌ๊ธฐ์— ์„ ํ˜•์œผ๋กœ ๋ถ™๋Š” ์ด์œ ๊ฐ€ ์ด ๋ˆ„์  ๊ณฑ์ด๋‹ค. ๋ณธ๋ฌธ์˜ "์„ ํ˜•์ด ์•„๋‹ˆ๋ผ ๋น„๋ก€ํ•ด์„œ ๋ฒŒ์–ด์ง„๋‹ค"๋Š” ํ‘œํ˜„์€ ์ด ๊ตฌ์กฐ๋ฅผ ๋œปํ•œ๋‹ค.

4. ํ”„๋กฌํ”„ํŠธ ์บ์‹ฑ์ด ์žˆ๋Š” ํ™˜๊ฒฝ์—์„œ๋Š” ๊ณ„์‚ฐ์ด ๋’ค์ง‘ํž ์ˆ˜ ์žˆ๋‹ค

์กฐ๊ฑด๋ถ€ ๋กœ๋”ฉ์€ ์ด ํ† ํฐ ์ˆ˜๋ฅผ ์ค„์ด๋Š” ๋Œ€์‹  ์ ‘๋‘๋ถ€(prefix)์˜ ์•ˆ์ •์„ฑ์„ ๊นจ๋œจ๋ฆฐ๋‹ค. ํ•ญ์ƒ ๋กœ๋“œ๋˜๋Š” ๊ณ ์ • ๊ทœ์น™์€ ๋ฐ˜๋ณต ์ ‘๋‘๋ถ€๊ฐ€ ๊ทธ๋Œ€๋กœ ์œ ์ง€๋˜์–ด ์บ์‹œ๋กœ ์ €๋ ดํ•˜๊ฒŒ ์ฒ˜๋ฆฌ๋  ์ˆ˜ ์žˆ๋‹ค. ๋ฐ˜๋Œ€๋กœ ํ„ด๋งˆ๋‹ค ๊ทœ์น™์ด ๋ถ™์—ˆ๋‹ค ๋–จ์–ด์ง€๋ฉด ์ ‘๋‘๋ถ€๊ฐ€ ๋ฐ”๋€Œ์–ด ์บ์‹œ๊ฐ€ ๋ฌดํšจํ™”๋˜๊ณ , ๋‹จ๊ฐ€ ๋†’์€ ๋ฏธ์Šค ํ† ํฐ์œผ๋กœ ์ฒญ๊ตฌ๋  ์ˆ˜ ์žˆ๋‹ค. ๋”ฐ๋ผ์„œ ์ ˆ๊ฐ ํŒ์ •์€ "์ด ํ† ํฐ"์ด ์•„๋‹ˆ๋ผ "์บ์‹œ ๋ฏธ์Šค ํ† ํฐ"์œผ๋กœ ๋‚ด๋ ค์•ผ ํ•œ๋‹ค. ์บ์‹œ ์ง€์› ์—ฌ๋ถ€์™€ ์ตœ์†Œ ์ ‘๋‘๋ถ€ ๊ธธ์ด๋Š” ๋Ÿฐํƒ€์ž„๋งˆ๋‹ค ๋‹ค๋ฅด๋ฏ€๋กœ ์ž๊ธฐ ๋„๊ตฌ ๋ฌธ์„œ๋กœ ํ™•์ธ์ด ํ•„์š”ํ•˜๋‹ค.

5. Read ํŠธ๋ฆฌ๊ฑฐ ์กฐ๊ฑด๋ถ€ ๋กœ๋”ฉ์˜ ์‚ฌ๊ฐ์ง€๋Œ€

๋ณธ๋ฌธ 3๋ฒˆ(๊ทœ์น™ ํ™œ์„ฑํ™”๊ฐ€ ํŒŒ์ผ Read ์‹œ์ ์— ๋ฐœ์ƒ)์—์„œ ๋”ฐ๋ผ์˜ค๋Š” ๊ฒฐํ•จ์ด ํ•˜๋‚˜ ์žˆ๋‹ค. ์ฝ์ง€ ์•Š๊ณ  ๋งŒ๋“œ๋Š” ๊ฒฝ๋กœ๋‹ค. ์ƒˆ ์ปดํฌ๋„ŒํŠธ๋‚˜ ์ƒˆ ๋ชจ๋“ˆ์„ ์ฒ˜์Œ๋ถ€ํ„ฐ ์ƒ์„ฑํ•˜๋Š” ์ž‘์—…์€ ๊ธฐ์กด ํŒŒ์ผ Read๊ฐ€ ์„ ํ–‰๋˜์ง€ ์•Š์œผ๋ฏ€๋กœ, ๊ทธ ์‹œ์ ์— ํ•„์š”ํ•œ ๊ทœ์น™์ด ๋กœ๋“œ๋˜์ง€ ์•Š์„ ์ˆ˜ ์žˆ๋‹ค. ๋„ค์ด๋ฐยท๋””๋ ‰ํ† ๋ฆฌ ๊ตฌ์กฐยท๊ธˆ์ง€ ํŒจํ„ด ๊ฐ™์€ ์Šค์บํด๋”ฉ ๊ทœ์น™์€ paths ์กฐ๊ฑด๋ถ€๊ฐ€ ์•„๋‹ˆ๋ผ ํ•ญ์ƒ ๋กœ๋“œ๋˜๋Š” ํŒŒ์ผ์— ๋‘๊ฑฐ๋‚˜, ์ƒ์„ฑ ์ „ ์ฐธ์กฐ ํŒŒ์ผ์„ ๋ช…์‹œ์ ์œผ๋กœ ์ฝ๋„๋ก ์ ˆ์ฐจ์— ๋„ฃ๋Š” ํŽธ์ด ์•ˆ์ „ํ•˜๋‹ค. ์ด ๋™์ž‘์€ ํ˜„์žฌ ๋ฐฐํฌ ๋ฒ„์ „์—์„œ ์žฌํ™•์ธ์ด ํ•„์š”ํ•˜๋‹ค.

6. ์กฐ๊ฑด๋ถ€ ๋กœ๋”ฉ์„ ์ง€์›ํ•˜์ง€ ์•Š๋Š” ๋„๊ตฌ์—์„œ์˜ ๋Œ€์ฒด ํŒจํ„ด

๋ชจ๋“  ์—์ด์ „ํŠธ๊ฐ€ paths ํ”„๋ก ํŠธ๋งคํ„ฐ๋ฅผ ์ง€์›ํ•˜์ง€๋Š” ์•Š๋Š”๋‹ค. ํ•ญ์ƒ ์ฃผ์ž…๋˜๋Š” ๊ทœ์น™ ํŒŒ์ผ๋งŒ ์žˆ๋Š” ๋„๊ตฌ์—์„œ๋„ ๊ฐ™์€ ํšจ๊ณผ๋ฅผ ๋‚ผ ์ˆ˜ ์žˆ๋‹ค.

  1. ์ƒ์‹œ ๋กœ๋“œ ํŒŒ์ผ์€ ์ธ๋ฑ์Šค๋กœ๋งŒ ์œ ์ง€ํ•œ๋‹ค โ€” ๊ทœ์น™ ํ•œ ์ค„ + ์ ์šฉ ์กฐ๊ฑด + ์ƒ์„ธ ํŒŒ์ผ ๊ฒฝ๋กœ.
  2. ์ƒ์„ธ ๋‚ด์šฉ์€ ๋ณ„๋„ ํŒŒ์ผ๋กœ ๋ถ„๋ฆฌํ•˜๊ณ , ์กฐ๊ฑด์ด ๋งž์„ ๋•Œ ์—์ด์ „ํŠธ๊ฐ€ ์ง์ ‘ ์ฝ๊ฒŒ ํ•œ๋‹ค. ์—์ด์ „ํŠธ ์ฃผ๋„ ์ฝ๊ธฐ๊ฐ€ ์กฐ๊ฑด๋ถ€ ๋กœ๋”ฉ์˜ ๋Œ€์ฒด๋ฌผ์ด๋‹ค.
  3. ์ƒ์‹œ ์ฃผ์ž… ์ด๋Ÿ‰์„ ํ† ํฐ ์˜ˆ์‚ฐ์œผ๋กœ ๊ณ ์ •ํ•œ๋‹ค โ€” ์ค„ ์ˆ˜๊ฐ€ ์•„๋‹ˆ๋ผ ํ† ํฐ ์ƒํ•œ์œผ๋กœ ๊ด€๋ฆฌํ•œ๋‹ค.

์ด ๊ตฌ์กฐ์—์„œ ์ •์  ์ฃผ์ž…์€ "์–ธ์ œ ๋ฌด์—‡์„ ์ฝ์„์ง€"๋งŒ ๋‹ด๊ณ , ์‹ค์ œ ๋น„์šฉ์€ ์กฐ๊ฑด์ด ๋งž์„ ๋•Œ๋งŒ ๋ฐœ์ƒํ•œ๋‹ค.

์ฐธ๊ณ 

  • ์ธก์ • ํ™˜๊ฒฝ: tiktoken 0.13.0, o200k_base, ์ด ๋Œ“๊ธ€ ์ž‘์„ฑ ํ™˜๊ฒฝ์˜ ์‹ค์ œ ํŒŒ์ผ๊ณผ ํ•œ๊ตญ์–ด ๊ธฐ์ˆ  ๋ฌธ์„œ 41๊ฑด(150~320์ค„ ๊ตฌ๊ฐ„)
  • p25ยท์ค‘์•™๊ฐ’ยทp75๋Š” ํ‘œ๋ณธ ๋ถ„ํฌ์ด๋ฉฐ, ๊ทœ์น™ ํŒŒ์ผ ์‹ค์ธก๊ฐ’์€ ์ค„ ์ˆ˜์™€ ํ† ํฐ์„ ์ง์ ‘ ๊ณ„์‚ฐํ•œ ๊ฐ’์ด๋‹ค