<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[KRIATIZ Dev Notes]]></title><description><![CDATA[KRIATIZ Dev Notes]]></description><link>https://kriatiz.hashnode.dev</link><image><url>https://cdn.hashnode.com/uploads/logos/6b071c2e6b4c23864d78ddc3/208274f2-f890-43c1-b7f5-ea87bd02c4c0.png</url><title>KRIATIZ Dev Notes</title><link>https://kriatiz.hashnode.dev</link></image><generator>RSS for Node</generator><lastBuildDate>Fri, 04 Dec 2026 21:27:58 GMT</lastBuildDate><atom:link href="https://kriatiz.hashnode.dev/rss.xml" rel="self" type="application/rss+xml"/><language><![CDATA[en]]></language><ttl>60</ttl><item><title><![CDATA[CLAUDE.md in Claude Code: How to Write Project Instructions, Rules and Memory]]></title><description><![CDATA[TL;DR: CLAUDE.md is an instructions file Claude Code reads at the start of every session: build and test commands, architecture, conventions and things to…]]></description><link>https://kriatiz.hashnode.dev/claude-md-in-claude-code-how-to-write-project-instructions-rules-and-memory</link><guid isPermaLink="true">https://kriatiz.hashnode.dev/claude-md-in-claude-code-how-to-write-project-instructions-rules-and-memory</guid><category><![CDATA[claude-code]]></category><category><![CDATA[Artificial Intelligence]]></category><dc:creator><![CDATA[Vladyslav Koshelyev]]></dc:creator><pubDate>Wed, 25 Nov 2026 18:12:23 GMT</pubDate><content:encoded><![CDATA[<p><strong>TL;DR:</strong> <code>CLAUDE.md</code> is an instructions file Claude Code reads at the start of every session: build and test commands, architecture, conventions and things to avoid. A good one is short (under 200 lines), specific and free of contradictions. Larger projects split instructions into <code>.claude/rules/</code> files scoped to paths.</p>
<p>The same templates are in the open-source <a href="https://github.com/Gunner91/claude-code-kit/tree/main/claude-md-templates">claude-code-kit repository on GitHub</a>.</p>
<h2>Why CLAUDE.md matters</h2>
<p>Every Claude Code session starts fresh: the model doesn’t remember that yesterday you agreed to run tests with <code>pnpm</code>. CLAUDE.md fixes that — write the essentials once and Claude gets them in context on every launch.</p>
<blockquote>
<p>Per the docs, CLAUDE.md content is delivered as a user message after the system prompt. It’s strong guidance, not enforcement. Anything that must <strong>never</strong> happen belongs in <a href="https://kriatiz.com/en/blog/claude-code-hooks/">hooks</a> and permission rules in <code>settings.json</code>.</p>
</blockquote>
<h2>Where the files live and how they load</h2>
<p><img src="https://kriatiz.com/img/blog/en/cc-claude-md-layers.png" alt="Claude Code memory file layers: managed policy, user, project, local" /></p>
<table>
<thead>
<tr>
<th>Scope</th>
<th>Location</th>
<th>Use for</th>
</tr>
</thead>
<tbody><tr>
<td>Managed policy</td>
<td>system-wide Claude Code folder (set by IT)</td>
<td>organization-wide rules</td>
</tr>
<tr>
<td>User</td>
<td><code>~/.claude/CLAUDE.md</code></td>
<td>your preferences across all projects</td>
</tr>
<tr>
<td>Project</td>
<td><code>./CLAUDE.md</code> or <code>./.claude/CLAUDE.md</code></td>
<td>team instructions, committed to git</td>
</tr>
<tr>
<td>Local</td>
<td><code>./CLAUDE.local.md</code></td>
<td>your personal project notes; add to <code>.gitignore</code></td>
</tr>
</tbody></table>
<p>All discovered files are <strong>concatenated</strong>; more specific ones come later.</p>
<h2>How Claude discovers CLAUDE.md files</h2>
<ul>
<li><strong>Up the tree, at launch:</strong> CLAUDE.md files in the working directory and every parent directory.</li>
<li><strong>Down the tree, on demand:</strong> files in subdirectories load when Claude reads or edits files there — handy in monorepos.</li>
<li><strong>Check</strong> what’s loaded with <code>/memory</code>.</li>
</ul>
<h2>What to put in CLAUDE.md</h2>
<ol>
<li><strong>Commands:</strong> install, run, test, lint — exactly as you run them.</li>
<li><strong>Architecture:</strong> where things live and where new code goes.</li>
<li><strong>Conventions:</strong> style, naming, preferred libraries.</li>
<li><strong>Don’ts:</strong> files not to touch, actions that need a question first.</li>
<li><strong>Pointers</strong> to detailed docs via imports.</li>
</ol>
<pre><code># Project: shop — Next.js + PostgreSQL

## Commands
- Dev: `npm run dev`
- Tests: `npm test` — run the related test after every change
- Must pass before finishing: `npm run lint &amp;&amp; npm run typecheck`

## Don't
- Don't edit .env* or package-lock.json
- Don't add dependencies without asking
</code></pre>
<h2>Writing instructions Claude follows</h2>
<ul>
<li><strong>Under 200 lines per file</strong> — longer files consume context and reduce adherence.</li>
<li><strong>Specific and verifiable:</strong> “use 2-space indentation”, not “format code properly”.</li>
<li><strong>Structured:</strong> Markdown headings and short bullets.</li>
<li><strong>Consistent:</strong> if two rules conflict, Claude may pick either one.</li>
<li><strong>Notes for humans</strong> go in block HTML comments <code>&lt;!-- ... --&gt;</code>, which are stripped before reaching the model.</li>
</ul>
<h2>Imports with @</h2>
<p>CLAUDE.md can pull in other files: <code>@docs/api-conventions.md</code>. Paths resolve relative to the importing file, and imports can nest up to four hops. Imports inside code blocks and code spans are ignored.</p>
<blockquote>
<p>Imports don’t save context — the imported file loads in full. To load instructions only when relevant, use path-scoped rules.</p>
</blockquote>
<h2>Path-scoped rules in .claude/rules</h2>
<p>A rule without frontmatter loads at launch. A rule with <code>paths</code> loads only when Claude works on matching files:</p>
<pre><code>---
paths:
  - "app/api/**/*.ts"
---
# API route rules
- Validate request bodies with zod, return 400 on failure
</code></pre>
<p><code>paths</code> is the only field Claude Code reads from a rule; it accepts a list or a comma-separated string and supports patterns like <code>src/**/*.{ts,tsx}</code>. Personal rules for all projects go in <code>~/.claude/rules/</code>.</p>
<h2>CLAUDE.local.md, /init and /memory</h2>
<ul>
<li><strong><code>CLAUDE.local.md</code></strong> — personal project notes, loaded after CLAUDE.md in the same folder; keep it out of git.</li>
<li><strong><code>/init</code></strong> generates a starter CLAUDE.md, or suggests improvements if one exists. Always edit the result.</li>
<li><strong><code>/memory</code></strong> lists all memory files, opens them for editing and manages auto memory.</li>
</ul>
<h2>Auto memory</h2>
<p>Claude Code also keeps its own notes about the project and your preferences in <code>~/.claude/projects/&lt;project&gt;/memory/</code>, with <code>MEMORY.md</code> as the index. The first 200 lines or 25 KB of the index load at session start; topic files load on demand. Turn it off in <code>/memory</code> or with <code>"autoMemoryEnabled": false</code> in project settings.</p>
<blockquote>
<p><strong>The difference:</strong> CLAUDE.md is written by you and shared through git; auto memory is Claude’s private notes on your machine.</p>
</blockquote>
<h2>Monorepos: excluding other teams’ files</h2>
<p>Use the <code>claudeMdExcludes</code> setting — an array of path globs, for example in <code>.claude/settings.local.json</code> — to skip CLAUDE.md files you don’t need. Managed policy files can’t be excluded.</p>
<h2>Checklist</h2>
<ol>
<li>Run, test and lint commands are present and work.</li>
<li>There’s a map of the project.</li>
<li>Rules are specific and consistent.</li>
<li>Under 200 lines; details live in path-scoped rules.</li>
<li>Hard limits are enforced with hooks or permissions.</li>
<li>Personal notes live in <code>CLAUDE.local.md</code>.</li>
</ol>
<p>Related: <a href="https://kriatiz.com/en/blog/claude-code-install-setup/">install and safe setup</a>, <a href="https://kriatiz.com/en/blog/claude-code-skills/">skills</a>, <a href="https://kriatiz.com/en/blog/claude-code-subagents/">subagents</a>.</p>
<h2>FAQ</h2>
<p><strong>Where should CLAUDE.md live?</strong></p>
<p>Team instructions in the project root (./CLAUDE.md or ./.claude/CLAUDE.md), personal preferences in ~/.claude/CLAUDE.md, personal project notes in ./CLAUDE.local.md.</p>
<p><strong>How long should CLAUDE.md be?</strong></p>
<p>The docs recommend under 200 lines per file. Move details into .claude/rules/ with paths so they load only when needed.</p>
<p><strong>Does CLAUDE.md guarantee Claude won’t do something?</strong></p>
<p>No — it’s guidance. Enforce hard limits with hooks and permission rules in settings.json.</p>
<p><strong>What’s the difference between CLAUDE.md and auto memory?</strong></p>
<p>You write CLAUDE.md and commit it; Claude writes auto memory and keeps it locally under ~/.claude/projects/.../memory/.</p>
<hr />
<p><em>Originally published on my blog at <a href="https://kriatiz.com/en/blog/claude-code-claude-md/">kriatiz.com</a>. This article was written with the help of AI and reviewed by me.</em></p>
]]></content:encoded></item></channel></rss>