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)
๊ฒฐ๋ก ๋ถํฐ: "200์ค"์ ๋ฒค๋๊ฐ ์ ์ํ ๋๋ฆฌ ์งํ์ผ ๋ฟ์ด๊ณ ์ค์ ๋น์ฉ ์งํ๋ ํ ํฐ ์๋ค. ์ค์ธกํ๋ฉด ๊ฐ์ 200์ค์ง๋ฆฌ ๋ฌธ์๊ฐ 2,300ํ ํฐ์ผ ์๋ 6,600ํ ํฐ์ผ ์๋ ์๋ค. ์กฐ๊ฑด๋ถ ๋ก๋ฉ์ ๋์ ํ๊ธฐ ์ ์ ์๊ธฐ ๊ท์น ํ์ผ์ ํ ํฐ ์๋ฅผ ๋จผ์ ์ฌ๋ ํธ์ด ์ ํํ๋ค.
1. ์ค์ธก: ๊ท์น ํ์ผ์ ํ ํฐ์ ์ค ์์ ๋น๋กํ์ง ์๋๋ค
์ด ๋๊ธ ์์ฑ ํ๊ฒฝ ์ธก์ ๊ธฐ์ค(tiktoken 0.13.0, o200k_base), ์ค์ ๊ท์นยท๊ฐ์ด๋ ํ์ผ ์ค์ธก๊ฐ์ด๋ค.
์งง์ ๊ท์น ํ์ผ์ ํ ํฐ/์ค์ด ๋ฌธ์๋ณด๋ค 3~4๋ฐฐ ๋๋ค. ์์ถ๋ฅ ์ด ๋ฎ์ ํ๊ตญ์ด ์ง์๋ฌธ์ ์ฒดํฌ๋ฆฌ์คํธ์ ํ๊ฐ ์์ด๋ฉด ๋ฐ๋๊ฐ ์ฌ๋ผ๊ฐ๊ณ , ์ฝ๋ยท๊ฐ์ด๋ ์์ฃผ ๋ฌธ์๋ 7~9๊น์ง ๋ด๋ ค๊ฐ๋ค. ์ฆ "๋ช ์ค์ธ๊ฐ"๋ณด๋ค "์ด๋ค ์ข ๋ฅ์ ํ ์คํธ์ธ๊ฐ"๊ฐ ๋น์ฉ์ ๊ฒฐ์ ํ๋ค.
2. 200์ค์ ํ ํฐ์ผ๋ก ํ์ฐํ๋ฉด
ํ๊ตญ์ด ๊ธฐ์ ๋ฌธ์ 41๊ฑด(150~320์ค ๊ตฌ๊ฐ)์ ๊ฐ์ ๋ฐฉ์์ผ๋ก ์ธก์ ํ ๋ถํฌ๋ค.
๊ฐ์ 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 ํ๋ก ํธ๋งคํฐ๋ฅผ ์ง์ํ์ง๋ ์๋๋ค. ํญ์ ์ฃผ์ ๋๋ ๊ท์น ํ์ผ๋ง ์๋ ๋๊ตฌ์์๋ ๊ฐ์ ํจ๊ณผ๋ฅผ ๋ผ ์ ์๋ค.
์ด ๊ตฌ์กฐ์์ ์ ์ ์ฃผ์ ์ "์ธ์ ๋ฌด์์ ์ฝ์์ง"๋ง ๋ด๊ณ , ์ค์ ๋น์ฉ์ ์กฐ๊ฑด์ด ๋ง์ ๋๋ง ๋ฐ์ํ๋ค.
์ฐธ๊ณ