Skip to content

Build1 publisher2 min readPublished

Claude Code's memory docs push hard rules out of CLAUDE.md and into a PreToolUse hook

Anthropic's memory documentation sets a 200-line target per instruction file and reserves real blocking for a hook. Everything written in markdown arrives as context the model weighs against your last message.

The Engineer · Build desk

Illustration accompanying Claude Code's memory docs push hard rules out of CLAUDE.md and into a PreToolUse hook

What happened

  • Claude Code can take a repository's existing AGENTS.md as its project instructions, either on its own or alongside CLAUDE.md, according to Anthropic's memory documentation.
  • The two memory systems, CLAUDE.md files and auto memory, both load at the start of every conversation before the first user prompt.
  • Auto memory has Claude write its own notes from the user's corrections and preferences, and can be configured to take those notes automatically.

Compiled by The EngineerSomething wrong?How this is made

Why it matters

  • constraint Instruction adherence is now a budget question. The rule set and the task draw on the same context window, so every line a team adds has a price paid by every session that opens.
  • decision Teams have to sort rules into two piles: those prose can influence, and those that must hold when the model is wrong. Only the second pile has anywhere to go but markdown.
  • exposure With Claude writing notes from corrections, what the agent believes about a repo can change between sessions without anyone opening a pull request.
  • capability A repo that already ships AGENTS.md for other coding agents can stop maintaining a second vendor-specific instruction file.

Both files arrive as prompt text. The documentation is explicit about what that buys: "Claude treats them as context, not enforced configuration." [3] A rule written in CLAUDE.md is a strong suggestion, evaluated against everything else in the window, including the user's last message.

That framing sets the size guidance. Anthropic targets under 200 lines per CLAUDE.md file and says longer files consume more context and reduce adherence [6]. The documentation states that effect without publishing the measurement behind it [20]. For 200 to be the right ceiling in your repo, your instructions would have to be about as compressible as the ones behind the guidance, and your sessions about as long. A file of 200 concrete path rules is a different object from 200 lines of style prose. On the quality side the docs are more useful than the count: "The more specific and concise your instructions, the more consistently Claude follows them." [5]

Imports do not fix size. A CLAUDE.md can pull in other files with `@path/to/import`, and imported files are expanded and loaded into context at launch alongside the file that references them, recursively, to a maximum depth of four hops [8]. Four hops is more depth than an instruction file needs. Split a 600-line instruction set into six 100-line files and launch context still holds 600 lines [19]. Relative paths resolve against the file containing the import, not the working directory [10].

Rules under `.claude/rules/` load only when Claude works with matching files [7]. Path scoping is the part that actually defers tokens, and a migration rule can sit out of a frontend session entirely.

A PreToolUse hook runs outside the model's judgement. The docs name it as the way to block an action regardless of what Claude decides [4]. In my view, any rule whose violation you would write up as an incident belongs there, and its restatement in CLAUDE.md is then documentation for the humans.

Conflict resolution is manual: the guidance is to review `.claude/rules/` periodically and remove outdated or conflicting instructions [15]. In a monorepo, `claudeMdExcludes` skips CLAUDE.md files from other teams that are not relevant to your work [16]. Auto memory adds a second writer to the same surface, since those notes come from your corrections and preferences rather than a commit you reviewed [14].

To confirm a file loaded at all, run `/context` in a session and check the list under Memory files [13].

What to watch

  • Whether Anthropic publishes the evaluation behind the under-200-line target and the claim that longer files reduce adherence.
  • Whether auto memory notes get a diffable on-disk surface a team can gate in code review.
  • Whether path-scoped rules under .claude/rules/ gain any enforcement semantics, or PreToolUse hooks stay the only blocking layer.
Loading claim ledger
Loading source directory links
Loading share composer
Loading topic controls
Loading related stories