الانتقال إلى المحتوى
Claude وأدوات الـ AI للبرمجةCLAUDE.md· 7 دقائق للقراءة

Why a Shorter CLAUDE.md Works Better: Only Write What Claude Can't See

Every line loads into every session. Keep the commands, gotchas and decisions; let Claude read the rest from the code.

ReadIn

مقال كل يوم يفرق معاك

21 نوفمبر 2026
  • كاتب موثّق
  • Claude Code 2.x
محتويات المقال

A team's CLAUDE.md started as twenty lines. Every time Claude missed something, someone added a paragraph: an architecture overview, the folder tree, every lint rule, a forty-step release procedure. Now it's 600 lines, and the one convention that keeps breaking, "throw AppError from src/lib/errors.ts, never raw strings", sits in the middle next to a folder tree that's two refactors out of date. Someone rewrites it as "IMPORTANT: NEVER THROW RAW STRINGS". Claude starts wrapping errors in test helpers too, where the team wanted plain assertions.

The common misconception

"The more Claude knows about the project, the better it follows it, so CLAUDE.md should document the architecture and every rule." Smart teams believe this for good reasons:

  • Onboarding docs work that way for people: a new hire with a thorough guide makes fewer mistakes.
  • Claude Code's own /init generates a CLAUDE.md from the codebase, which looks like an invitation to describe it, though the docs add that from there "the work is mostly removing lines".
  • Older models sometimes did need things spelled out, and loud emphasis once helped.
  • When Claude misses a rule, adding text is the fastest fix at hand.

The half-truth: CLAUDE.md really is the place for what Claude must know in every session. But "every session" is exactly the problem. What's useful on one task is noise on the next, and Claude can already find most of it.

What actually happens

Every line is in every session

The files in your working directory and above it load at launch, and Claude Code re-sends the full context, including them, with every request. Anthropic's best-practices guide says each line "takes a little of Claude's attention on every task, whether it's relevant or not". The memory guide gives the size target: under 200 lines per file, because "Longer files consume more context and reduce adherence." And if two instructions contradict each other, Claude may pick one arbitrarily, a risk that grows when nobody prunes the file.

CLAUDE.md is also context, not configuration. It arrives as a user message after the system prompt, and Claude "tries to follow it, but there's no guarantee of strict compliance".

Claude already reads the repo

Claude starts each task by reading code, and the docs say current models find your file layout, conventions, test framework and how existing components are built, "usually faster than you could explain them". That's why "Describe your architecture and file layout in CLAUDE.md" is on the docs' list of advice you can stop following. The /doctor checkup proposes trims along the same lines: directory layouts, dependency lists and architecture overviews go; pitfalls, rationale and conventions that differ from tool defaults stay.

The two-question test

Before writing a line, the docs suggest asking: could Claude find this by reading the code, and would it actually go and look? If both answers are yes, leave it out. What passes the test is short:

  • How to confirm work: the exact test, typecheck and lint commands, and how to run one test file
  • Places where the code misleads: an old pattern that new code must not copy, a directory that looks unused but isn't
  • Decisions that aren't in the repo, such as which error helper the team settled on
  • Anything you've had to correct twice

Emphasis isn't the fix

The docs list IMPORTANT and ALL CAPS among habits from older models. Current models follow a plainly worded line, and piling on emphasis "mostly makes Claude over-apply the rule". If Claude keeps ignoring a line, either the file is long enough that the line gets lost, or it's a rule with no exceptions, which belongs in a hook.

The same file, before and after

Markdown CLAUDE.md
# ArchitectureNext.js app. Pages in src/app/, components in src/components/,API routes in src/app/api/, helpers in src/lib/.Stack: React, TypeScript, Tailwind, Prisma, Vitest.# Folder structuresrc/app/ src/components/ src/lib/ prisma/ tests/ ...# Rules- IMPORTANT: ALWAYS write clean, readable code- Use TypeScript for all new files- NEVER THROW RAW STRINGS!!! Use the error helpers.# Release process1. Pull main. 2. Bump the version. 3. ... (38 more steps)

Everything in the first version's top half is visible in the repo. "Write clean code" can't be checked, and the release steps matter only when you release. The second version holds commands Claude needs to check its own work, one convention it couldn't guess and two traps it would hit.

Where the rest goes

A rule that matters for one part of the codebase goes in .claude/rules/ with a paths: filter. It loads only when Claude reads, writes or edits a matching file:

Markdown .claude/rules/api.md
---paths:  - "src/app/api/**/*.ts"---- Validate request bodies with the zod schemas in src/lib/schemas/- Every new endpoint needs an entry in openapi.yaml
What you want Claude to knowWhere it goesWhen it's in context
Commands, gotchas, team decisionsCLAUDE.mdEvery session
Rules for one area of the code.claude/rules/ with paths:When Claude touches a matching file
A multi-step procedure, like a releaseA skillDescription every session, body when used
A rule with zero exceptionsA hook or a deny ruleEnforced by Claude Code, not read by Claude
Architecture, layout, dependenciesNowhere: Claude reads the codeWhen Claude explores
Your personal preferencesCLAUDE.local.md, gitignoredEvery session, only yours

keeps a stable CLAUDE.md cheap to re-send, since it sits near the start of every request with the rest of the project context. Cheap isn't free, though: it's still in context on every turn. And a mid-session edit to the project-root CLAUDE.md doesn't apply until the next /clear, /compact or restart.

How to apply it in your project

  1. Run `/doctor`Let the checkup propose cuts for content Claude can derive from the codebase. Review each one; you decide what goes.
  2. Apply the two-question test to every lineCould Claude find it in the code, and would it look? If yes to both, delete it. Keep commands, traps and decisions.
  3. Move area rules and procedures outPut rules for one directory in .claude/rules/ with paths:, and long procedures in a skill.
  4. Turn the "never" lines into hooksIf a line has emphasis because Claude must never break it, enforce it with a hook or a deny rule and drop the caps.
  5. Audit it like codeReview CLAUDE.md changes in pull requests, and run /doctor prompt-audit now and then to catch stale or contradicting lines. Start a fresh session to load the new version.

Key takeaways

  • CLAUDE.md loads into every session, so every line costs attention on every task, relevant or not.
  • Aim for under 200 lines; longer files consume more context and reduce adherence.
  • Don't describe the architecture or folder layout; Claude reads the repo.
  • Keep commands, misleading spots, decisions that aren't in the repo and repeated corrections.
  • Move area rules to .claude/rules/, procedures to skills and must-never rules to hooks.

📚 المصادر

  1. How Claude remembers your project — Claude Code Docs
  2. Best practices for Claude Code — Claude Code Docs
  3. How Claude Code uses prompt caching — Claude Code Docs

التعليقات (0)