til/applied-sciences/engineering/claude-code-memory-hierarchy
claude-code-memory-hierarchy.mdupdated 2026-07-162501 words
ダブルクリックで英日反転
Applied Sciences · Engineering

Claude Code's CLAUDE.md Hierarchy — Which Instructions Reach How Far

EN

CLAUDE.md is the instruction sheet Claude Code loads automatically into every conversation. Multiple files across a hierarchy all load together — none is skipped.

The Four Layers

  • Managed policy (company-issued PC) — highest priority, cannot be excluded
  • User global (~/.claude/CLAUDE.md) — shared across all your projects
  • Project parent-ancestor — applies to every repo under that folder
  • Repo-specific (repo root) — narrowest scope, read last

Conflict Resolution: Lower Wins

  • All applicable files are concatenated and handed to the AI together
  • Reading order determines priority — the lower (more specific) file is read later and wins
  • Flatly contradictory rules across layers cause the AI to waver; delete duplicates

CLAUDE.md vs settings.json

  • CLAUDE.md = natural-language instructions for the AI ("behave like this")
  • settings.json = tool-level config (permissions, hooks) executed by Claude Code itself
  • Automation like "reformat on save" belongs in hooks, not CLAUDE.md

Placement Guide

  • Cross-project preference → global ~/.claude/CLAUDE.md
  • Team/company rules → CLAUDE.md in a shared parent folder
  • Repo-only agreements → CLAUDE.md at the repo root
  • Rule of thumb: the wider the audience, the higher up you write it
Every layer loads; when layers conflict, the more specific (lower) file wins — "only global takes effect" is a myth.
Applied Sciences · Engineering

Claude Code の​ CLAUDE.md 階層 — 指示は​どの​範囲まで​届くか

JP

CLAUDE.md は​ Claude Code​(ターミナルで​動く​ AI 開発ツール)が​毎回​自動で​読み込む指示書。​階層内の​複数ファイルは​すべて​同時に​読み込まれ、​スキップされる​ものは​ない。

4 つの​層

  • 管理ポリシー​(会社支給 PC)​— 最優先・除外不可
  • ユーザーグローバル​(~/.claude/CLAUDE.md)​— 全プロジェクト共通
  • プロジェクト祖先ディレクトリ — ​その​配下の​全リポに​適用
  • リポ固有​(リポルート)​— 最も​狭いスコープ・​最後に​読まれる

競合時の​ルール:下位が​勝つ

  • 該当するファイルは​すべて​連結​(​concatenate)されて AI に​渡される
  • 読み込み順が​優先度を​決める​ — より​下位​(具体)の​ファイルが​後から​読まれ優先される
  • 層を​またいで​真っ向矛盾する​指示が​あると​ AI が​揺れる​ → 重複削除を​推奨

CLAUDE.md と​ settings.json の​違い

  • CLAUDE.md = AI への​自然言語指示​(​「こう​振る​舞え」)
  • settings.json = ツール本体の​設定​(権限・フック)。​AI ではなく​ Claude Code が​実行
  • 「保存時に​自動整形」などの​自動化は​フック​(hook)に​書く​ — CLAUDE.md ではない

どの​層に​書くか

  • 全プロジェクト共通の​好みは​ ~/.claude/CLAUDE.md
  • チーム・会社ルールは​共有親フォルダの​ CLAUDE.md
  • リポ限定の​取り​決めは​リポルートの​ CLAUDE.md
  • 判断基準:​「誰に​・どこまで​届けたいか」で​置く​高さを​決める
全層が​読み込まれ、​競合時は​下位​(より​具体的)な​ファイルが​勝つ。​「グローバルだけが​効く」は​誤解。
148 notestil