Claude Architect · 강의

단일형 규칙과 모듈형 규칙

컨텍스트와 토큰을 절약하도록 거대한 CLAUDE.md를 나눕니다

레슨 4/413개 단계

단일형 규칙과 모듈형 규칙은(는) CoddyKit의 무료 Claude Architect 강의입니다. 이것은 4개 중 4번째 강의입니다. 아래에서 전체 강의를 무료로 읽을 수 있으며, 내장 코드 에디터와 24/7 AI 튜터와 함께 브라우저에서 직접 실습할 수 있습니다. 이 강의는 Claude Architect 학습 경로의 일부이며, 진행 상황이 웹과 CoddyKit 앱에 동기화됩니다. Claude Architect 강의에는 총 4개의 강의가 포함되어 있습니다.

이 강의의 일부는 아직 번역되지 않았으며 영어로 표시됩니다.

The Monolith Problem

A single giant CLAUDE.md feels tidy, but every token in it is loaded into the context window on every single request of every session.

If your file holds 4,000 lines covering the backend, the iOS app, CSS conventions, and your release checklist, Claude pays that cost even when it is only fixing one CSS rule. That wasted context crowds out the code and history that actually matter.

This lesson is about splitting a monolith into modular rules that load only when relevant.

Why Modular Saves Tokens

The win is simple: load rules on demand instead of always.

  • A monolithic CLAUDE.md ships its entire body with every turn.
  • Modular rule files in .claude/rules/ can declare which paths they apply to, so they load only when you edit a matching file.

Less always-on text means more room for the task, and fewer tokens billed per request. This directly serves Domain 5: Context Management & Reliability.

The CLAUDE.md Hierarchy

Before splitting, know the layers Claude Code reads from:

  • User-level ~/.claude/CLAUDE.md — personal, NOT shared via VCS. New teammates never see it.
  • Project-level ./CLAUDE.md or .claude/CLAUDE.md — shared via version control, so the whole team gets it.
  • Directory-level — a CLAUDE.md scoped to a subtree, loaded when you work inside it.

Team-wide rules belong at project level. Anything in user-level is invisible to others.

Modularize With @path Imports

The first splitting tool is the @path import. Keep a lean CLAUDE.md that pulls in detail files only where needed.

This keeps the top-level file readable and lets you reuse standards across projects. Note: an imported file still loads when the importing CLAUDE.md loads — imports organize content, they do not gate it by path.

# CLAUDE.md (project root)

## Project Overview
NestJS backend + single-file HTML dashboard.

## Coding Standards
@./standards/coding-style.md
@./standards/git-workflow.md

## Testing
@./standards/testing.md

Path-Scoped Rules Files

The real token saver is .claude/rules/ files with YAML frontmatter. A paths glob tells Claude Code to load the rule only when you edit a file that matches.

Editing a .tsx component? The React rule loads. Touching only SQL? It stays out of context entirely. This is conditional loading versus the monolith's always-on cost.

---
paths:
  - "src/**/*.tsx"
  - "src/**/*.jsx"
---

# React Component Rules
- Use function components and hooks; no class components.
- Co-locate tests as `*.test.tsx` next to the component.
- Keep components under 200 lines; extract subcomponents otherwise.

What Stays in the Core File

Not everything should be path-scoped. The core CLAUDE.md should keep rules that apply everywhere, every time:

  • Project overview and architecture summary.
  • How to build, run, and deploy.
  • Cross-cutting safety rules (e.g. "never run the OTA deploy without explicit approval").

Push domain-specific detail — language conventions, per-framework patterns, subsystem quirks — out into path-scoped rules. Core = universal; rules = situational.

A Suggested File Layout

A clean modular layout separates the always-on core from the on-demand rules and standards:

The lean root file orients Claude; rules/ files activate by path; standards/ files are imported where relevant. New teammates get all of it through VCS.

project/
  CLAUDE.md                  # lean: overview + build/deploy + safety
  .claude/
    rules/
      react.md               # paths: src/**/*.tsx
      sql.md                 # paths: **/*.sql
      api.md                 # paths: src/api/**
  standards/
    coding-style.md          # @-imported from CLAUDE.md
    testing.md

User vs Project Scope, Revisited

When you split, decide scope deliberately. A rule a teammate must follow belongs in a project-level file or .claude/rules/, checked into VCS.

A purely personal preference — your editor habits, your local shortcuts — belongs in user-level ~/.claude/CLAUDE.md. Putting a shared standard there is a classic mistake: it silently fails to reach the rest of the team.

Lost-in-the-Middle Risk

There is a reliability reason to split too, not just cost. Models attend most to the start and end of context and least to the middle — the "lost-in-the-middle" effect.

A 4,000-line monolith buries critical rules in that low-attention middle. Smaller, path-scoped files keep each rule near the top of what loads, so the instructions that apply right now are far more likely to be followed.

Editing Rules Safely

You don't have to hand-edit these files blindly. Inside Claude Code, /memory opens and edits CLAUDE.md and persists the change across sessions.

Be careful with /compact: it compresses the running context and can make specific numbers, dates, and thresholds vague. It is not a substitute for structurally splitting your rules — compaction summarizes the conversation, modular files reduce what loads in the first place.

# Inside an interactive Claude Code session
/memory          # open CLAUDE.md to add or refine a rule (persists)
/compact         # compress context — may blur exact numbers/dates

Migration Strategy

To split an existing monolith without losing rules:

  • Keep universal rules (overview, build, deploy, safety) in the core CLAUDE.md.
  • Group the rest by domain — one rule file per language or subsystem.
  • Add a paths glob to each so it loads only on matching edits.
  • Import shared standards with @path where they apply broadly.
  • Verify nothing was dropped — every former rule should live somewhere reachable via VCS.

Quick Check: Choosing the Split

Your CLAUDE.md has grown to ~3,500 lines covering five languages and a deploy runbook. Most sessions touch only one language at a time, and context is running tight. As the architect, what is the best restructuring?

Recap: Monolith vs Modular

Key takeaways:

  • A monolithic CLAUDE.md loads fully on every request, wasting tokens and burying rules in the low-attention middle.
  • .claude/rules/ files with a paths frontmatter glob load only when matching files are edited — the core token saver.
  • @path imports modularize and reuse standards; the core file keeps universal rules (overview, build, deploy, safety).
  • Share team rules at project level via VCS; keep only personal preferences in user-level ~/.claude/CLAUDE.md.
  • /memory edits persist; /compact is not a replacement for structurally splitting rules.
무료로 시작

AI 튜터와 함께 Python을(를) 배우세요 — 무료

브라우저에서 실제 코드를 작성하고 실행하며, 24/7 AI 튜터로부터 즉각적인 도움을 받고, 웹이나 앱에서 중단한 부분부터 계속 학습하세요.

코스
26
레슨
104

자주 묻는 질문

“단일형 규칙과 모듈형 규칙” 강의는 무료인가요?

네 — “단일형 규칙과 모듈형 규칙” 전체 내용을 이 웹사이트에서 무료로 읽을 수 있습니다. 인터랙티브하게 실습하려면(내장 코드 에디터와 24/7 AI 튜터), CoddyKit PRO로 업그레이드하면 Claude Architect 강의 전체를 잠금 해제할 수 있습니다. Claude Architect 강의에는 총 4개의 강의가 포함되어 있습니다.

“단일형 규칙과 모듈형 규칙”에서 뭘 배우나요?

컨텍스트와 토큰을 절약하도록 거대한 CLAUDE.md를 나눕니다 브라우저에서 직접 실행하는 실습 코드로 Claude Architect을(를) 배우며, 24/7 AI 튜터가 강의를 진행하면서 질문에 답변해줍니다.

Claude Architect을(를) 시작하는 데 경험이 필요한가요?

사전 경험은 필요하지 않습니다. CoddyKit의 Claude Architect은(는) 초급자부터 고급 학습자까지를 위해 구성되어 있으므로, 여기서 시작하거나 처음부터 시작할 수 있으며 자신의 속도대로 진행할 수 있습니다. 이것은 4개 중 4번째 강의입니다.

“단일형 규칙과 모듈형 규칙” 강의는 얼마나 걸리나요?

대부분의 CoddyKit 강의는 약 5~10분이 소요됩니다. 각 강의는 간결하고 인터랙티브하여 꾸준한 진행이 가능하며, 웹과 앱에서 중단한 부분부터 바로 시작할 수 있습니다.

이 Claude Architect 강의에서 코드를 작성하고 실행할 수 있나요?

네. 모든 Claude Architect 강의에는 내장 코드 에디터가 포함되어 있으므로, 브라우저에서 바로 실제 코드를 작성하고 실행한 후 즉시 AI 피드백을 받을 수 있습니다 — 로컬 설정이 필요 없습니다.

이 강의의 모든 강의

  1. 사용자, 프로젝트 및 디렉터리 수준
  2. @path 가져오기 구문
  3. Frontmatter 경로가 있는 .claude/rules/
  4. 단일형 규칙과 모듈형 규칙
← Claude Architect(으)로 돌아가기