# CLAUDE.md examples: four stack templates, rules, imports

> Canonical: https://skillalmanac.com/learn/claude-md-examples | Updated: 2026-11-25 | Index status: index-eligible

Complete CLAUDE.md examples for TypeScript, Python, Go and monorepo projects, plus .claude/rules, @imports and AGENTS.md, checked against the Claude Code docs.

## Facts

- Checked 2026-11-25: Anthropic recommends targeting under 200 lines per CLAUDE.md file; imports help organization but do not reduce context cost because imported content loads with it (https://code.claude.com/docs/en/memory)
- Checked 2026-11-25: Project instructions can live at ./CLAUDE.md or ./.claude/CLAUDE.md; personal project notes belong in ./CLAUDE.local.md, and user-wide instructions in ~/.claude/CLAUDE.md (https://code.claude.com/docs/en/memory)
- Checked 2026-11-25: File-specific instructions can be placed in .claude/rules/ with a paths filter so they load for matching work (https://code.claude.com/docs/en/memory)
- Checked 2026-11-25: By default, AGENTS.md is used only when no project-path CLAUDE.md or CLAUDE.local.md takes precedence; direct AGENTS.md support requires Claude Code 2.1.277 or later (https://code.claude.com/docs/en/memory)
- Checked 2026-11-25: CLAUDE.md supplies context rather than enforced configuration; exceptionless controls belong in hooks, permission rules or managed settings (https://code.claude.com/docs/en/best-practices)
- Checked 2026-11-25: /doctor prompt-audit requires Claude Code 2.1.283 or later and proposes edits for stale, missing or conflicting instructions without applying them automatically (https://code.claude.com/docs/en/memory)
- Checked 2026-11-25: Auto memory loads at most the first 200 lines or 25KB of MEMORY.md; launch-loaded CLAUDE.md files have a separate 4 MiB limit, while nested files and path-scoped rules can load on demand (https://code.claude.com/docs/en/memory)

## Short answer

Last checked 2026-11-25: a useful CLAUDE.md is concise and holds what Claude Code cannot reliably derive from the repository: exact verification commands, misleading legacy patterns and decisions not recorded elsewhere. The Anthropic docs recommend under 200 lines per file. Below are four complete templates (TypeScript web app, Python service, Go service, monorepo root), a path-scoped rules file, import syntax and an AGENTS.md bridge. Each template is an illustration: replace every command with the one your repository really uses.

## What belongs in a CLAUDE.md

As checked on 2026-11-25, the Claude Code best-practices page says the file works best when it holds only what Claude cannot work out from the code:

- How to confirm work: the exact test, typecheck and lint commands, and how to run a single test file.
- Places where the code is misleading: an old pattern that is everywhere but must not be copied, or a directory that looks unused but is not.
- Decisions that are not in the repo: which error helper the team chose, how deploys work, what needs a migration review.
- Anything you have had to correct twice already.

The memory page adds when to add a line: when Claude makes the same mistake a second time, when a code review catches something Claude should have known, or when you type the same correction into chat that you typed last session. It also says a multi-step procedure, or something that matters for one part of the codebase only, should move to a skill or a path-scoped rule.

What to leave out: architecture overviews and directory listings (Claude reads the repo), long procedures (use a skill), and rules with no exceptions (use a hook). The `/doctor` checkup, per the docs, proposes trimming exactly the derivable content, such as directory layouts, dependency lists and architecture overviews, and keeps pitfalls, rationale and conventions that differ from tool defaults.

## Example 1: TypeScript web app

This uses the Commands, Conventions and Gotchas structure shown by the best-practices page, then adds project-specific illustrative entries. The commands assume pnpm and Vitest; copy the structure, not commands your repository does not use.

```markdown
# Commands
- Install: pnpm install
- Dev server: pnpm dev (port 3000)
- Run one test file: pnpm vitest run path/to/file.test.ts
- Typecheck: pnpm tsc --noEmit
- Lint: pnpm eslint . --max-warnings 0

# Conventions
- Use the error helpers in src/lib/errors.ts, never throw raw strings
- Server components by default; add "use client" only when a hook or event handler needs it
- API handlers live in src/app/api/; shared types in src/types/

# Gotchas
- src/legacy/ is still live but do not copy its patterns into new code
- Integration tests need DATABASE_URL set, see .env.example
- Never edit files in src/generated/; run pnpm codegen instead
```

Why each block earns its place: the Commands block lets Claude verify its own work; the Conventions block names a helper file Claude would otherwise miss and a rule about client components that a model may not apply by default; the Gotchas block holds the three things a newcomer would break.

## Example 2: Python service

Illustrative commands for a project using uv, pytest, ruff and mypy.

```markdown
# Commands
- Install: uv sync
- Run one test: uv run pytest tests/test_orders.py::test_refund -x
- Full tests: uv run pytest -q
- Lint and format check: uv run ruff check . && uv run ruff format --check .
- Types: uv run mypy src

# Conventions
- Python 3.12; type hints required on public functions
- Database access only through src/app/repo/; handlers never import the ORM directly
- Money is Decimal, never float

# Gotchas
- Tests marked @pytest.mark.slow hit a real Postgres; start it with docker compose up -d db first
- Alembic migrations in migrations/ need a second reviewer; do not edit an applied migration
```

## Example 3: Go service

Illustrative commands using the standard Go toolchain.

```markdown
# Commands
- Build: go build ./...
- Test one package: go test ./internal/billing -run TestInvoice -count=1
- All tests with the race detector: go test -race ./...
- Vet: go vet ./...

# Conventions
- Errors are wrapped with fmt.Errorf("...: %w", err); never compare error strings
- Public API of each package is only what its doc.go lists
- Config comes from env via internal/config; no os.Getenv elsewhere

# Gotchas
- cmd/legacy-importer is deprecated but still deployed; fix bugs, add no features
```

## Example 4: monorepo root

In a monorepo keep the root file about the whole repository and push package detail into nested files and rules. The docs say CLAUDE.md files in subdirectories load on demand when Claude reads, writes or edits a file there.

```markdown
# Repository map (only what is not obvious)
- apps/web is the customer site; apps/admin is internal and deploys separately
- packages/ui is consumed by both apps; change it only with both apps' tests green

# Commands (run from the repo root)
- Test one workspace: pnpm --filter web test
- Typecheck everything: pnpm -r typecheck

# Conventions
- See @docs/git-instructions.md for branch and commit rules
- Per-package notes live in each package's own CLAUDE.md

# Gotchas
- Do not add a dependency at the root; add it to the workspace that uses it
```

If another team's CLAUDE.md files are picked up by your session in a large monorepo, the docs give the `claudeMdExcludes` setting, for example in `.claude/settings.local.json`:

```json
{
  "claudeMdExcludes": [
    "**/monorepo/CLAUDE.md",
    "/home/user/monorepo/other-team/.claude/rules/**"
  ]
}
```

## Before and after: from vague to checkable

The memory page asks for instructions concrete enough to verify. Its own examples, side by side:

| Vague | Checkable |
| :- | :- |
| Format code properly | Use 2-space indentation |
| Test your changes | Run `npm test` before committing |
| Keep files organized | API handlers live in `src/api/handlers/` |

We have not measured a before-and-after effect of CLAUDE.md edits, and the docs make no numeric claim about it. What they do say is that more specific and concise instructions are followed more consistently, and that files over 200 lines consume more context and may reduce adherence.

## Path-scoped rules with .claude/rules

For a rule that matters in one part of the codebase, put a Markdown file in `.claude/rules/`. This example is from the best-practices page: it loads when Claude works with TypeScript files under `src/api/`.

```markdown
---
paths:
  - "src/api/**/*.ts"
---
- Validate request bodies with the zod schemas in src/api/schemas/, do not hand-roll checks
- Every new endpoint needs an entry in openapi.yaml, CI fails without it
```

The memory documentation checked on 2026-11-25 supports placing file-specific instructions in `.claude/rules/` with a `paths` filter so they load for matching work. The precise supported glob syntax, frontmatter behavior and tool events are version-sensitive; verify those details against the current rules section before relying on them. User-level rules in `~/.claude/rules/` apply to every project, and the docs say a conflict between a user rule and a project rule may be resolved either way, so keep them consistent.

## Imports, local files and AGENTS.md

**Imports.** Write `@path/to/file` inside CLAUDE.md. Relative paths resolve from the file containing the import, and imports can chain to a maximum depth of four hops. The docs example:

```text
See @README for project overview and @package.json for available npm commands for this project.

# Additional Instructions
- git workflow @docs/git-instructions.md
```

Imports do not shrink context, since imported files load with the file that imports them. To mention a path without importing it, wrap it in backticks. The first time a project imports a file from outside the working directory, Claude Code shows an approval dialog.

**Personal notes.** Put them in `CLAUDE.local.md` at the project root and add it to `.gitignore`. For personal instructions shared across git worktrees, import a file from your home directory, for example `- @~/.claude/my-project-instructions.md`.

**Maintainer notes.** Block-level HTML comments in a CLAUDE.md are stripped before the content reaches Claude's context, so you can leave notes for people without spending tokens.

**AGENTS.md.** By default Claude reads `AGENTS.md` only when there is no `CLAUDE.md` or `CLAUDE.local.md` in the working directory or above it. If a repository has both, Claude reads the CLAUDE.md files only. To keep one shared file, create a CLAUDE.md next to it:

```markdown
@AGENTS.md

## Claude Code

Use plan mode for changes under `src/billing/`.
```

On Windows, the docs recommend this import over a symlink. See [CLAUDE.md vs AGENTS.md: Which Agents Read Which File](/learn/agents-md-vs-claude-md) and [Make Claude Code read AGENTS.md: import and verify](/learn/make-claude-code-read-agents-md) for the full comparison.

## Build your file in five steps

1. Run `/init` in the project root. The docs say Claude analyzes the codebase and writes build commands, test instructions and conventions it finds. If a CLAUDE.md exists, `/init` suggests improvements instead of overwriting it.
2. Delete every line Claude could infer from the code.
3. Add the commands that let Claude check its own work.
4. Move personal preferences to `CLAUDE.local.md` or `~/.claude/CLAUDE.md`.
5. Start a new session and run `/context all`. Expected, from the documentation: your CLAUDE.md appears in the list under "Memory files".

To audit an existing file, run `/doctor prompt-audit` (Claude Code 2.1.283 or later). The docs say it reports instructions written for older models, references to missing files or commands and conflicts, while proposing rather than automatically applying edits. This is a model-driven audit, not proof that every defect was detected.

## When a line should not be in CLAUDE.md

The docs say CLAUDE.md content is delivered as a user message after the system prompt, so there is no guarantee of strict compliance. Rules with no exceptions should be a hook, a deny rule or a managed setting. The best-practices page gives this formatter hook, which runs after every edit whether or not Claude remembers the rule:

```json
{
  "hooks": {
    "PostToolUse": [
      {
        "matcher": "Edit|Write",
        "hooks": [
          { "type": "command", "command": "f=$(jq -r '.tool_input.file_path') && npx prettier --write --ignore-unknown \"$f\"" }
        ]
      }
    ]
  }
}
```

Save it in `.claude/settings.json`. Hooks are covered in [Claude Code Hooks: Setup, One Example, and Failure Modes](/learn/claude-code-hooks-explained). Long, procedural content, such as a release checklist, belongs in a skill. A skill's name and description are in context each session, and the full file is read only when the task calls for it.

## What goes wrong and how to fix it

1. **Claude ignores a line.** Cause: the file is long, the line is vague, or two lines conflict. Fix: run `/context all` to confirm the file loaded, make the line concrete, and remove contradictions across the root file, nested files and `.claude/rules/`. Adding IMPORTANT usually does not help, per the best-practices page.
2. **A subdirectory CLAUDE.md does not show in `/context`.** Cause: it loads on demand, not at launch. Fix: create it from your shell, ask Claude to read a file in that folder, and look for the `Loaded` line.
3. **The end of a nested file is ignored.** Cause: on-demand files have a per-file size limit, 40,000 characters on a 200K context window per the docs, and Claude receives only the start of a larger file. Fix: check with `wc -m path/to/CLAUDE.md`, then trim or split into rules.
4. **AGENTS.md is not read.** Cause: a CLAUDE.md or CLAUDE.local.md exists in or above the working directory, or the version is older than 2.1.277. Fix: add `@AGENTS.md` to your CLAUDE.md, or set Project instructions in `/config`.
5. **A `.claude/rules` file never loads.** Cause: broken YAML frontmatter, or a glob that matches nothing. The docs say invalid frontmatter is ignored and the rule loads as if it had no `paths`. Fix: run `claude --debug` to see the parse error.
6. **Instructions vanish after `/compact`.** Cause: they were given only in conversation. The root CLAUDE.md is re-read from disk after compaction. Fix: add them to the file.
7. **Personal notes were committed.** Fix: move them to `CLAUDE.local.md` and gitignore it.

## What our catalogue shows

The following catalogue entries are related to instruction files, migrations, decisions or prompt writing. This table does not establish that no other catalogue skill can help generate a CLAUDE.md, and its install probes tested recognition of a matching request rather than successful completion of an end-to-end task.

| Skill | Platform Score and state | Efficacy verdict | Claude Code recognition probe | Tutorial video |
| :- | :- | :- | :- | :- |
| [agent-instruction-files](/skills/skill-almanac/agent-instruction-files) | 46, provisional | none recorded | Claude Code 2.1.330, 2026-11-23 | yes |
| [rules-to-skills-migration](/skills/skill-almanac/rules-to-skills-migration) | 45, provisional | none recorded | Claude Code 2.1.330, 2026-11-23 | yes |
| [project-decision-log](/skills/skill-almanac/project-decision-log) | 40, provisional | none recorded | Claude Code 2.1.330, 2026-11-23 | yes |
| [prompt-writing](/skills/skill-almanac/prompt-writing) | 57, provisional | LIFT (single-run, 2026-11-21) | Claude Code 2.1.330, 2026-11-23 | yes |

Among these four entries, only prompt-writing has an efficacy verdict. Its provisional LIFT came from three tasks with one run per configuration; Claude Sonnet 5.5 was both executor and blind grader, with no human grader or third-party reproduction. The other three have no recorded efficacy evidence. Recognition probes and tutorial videos are not efficacy tests. See the [Platform Score methodology](/methodology/platform-score) for score definitions.

## FAQ

### Where does CLAUDE.md go?

In the project root as `./CLAUDE.md`, or at `./.claude/CLAUDE.md`. Personal preferences for all projects go in `~/.claude/CLAUDE.md`, and personal project notes in `./CLAUDE.local.md`. Organizations can deploy a managed file at a system path.

### How long should a CLAUDE.md be?

The docs say to target under 200 lines per file. Longer files consume more context and may reduce adherence, and Claude Code shows a startup warning for files over the recommended length.

### Does Claude Code read AGENTS.md?

Yes, when no CLAUDE.md or CLAUDE.local.md exists in the working directory or above it, on Claude Code 2.1.277 or later. Otherwise import it with `@AGENTS.md` from your CLAUDE.md.

### Should I use /init?

It is a good start. The docs say it writes a CLAUDE.md from your codebase and suggests improvements to an existing one, and that from there the work is mostly removing lines that Claude could infer.

### What is the difference between CLAUDE.md and auto memory?

You write CLAUDE.md; Claude writes auto memory notes itself. The docs say auto memory loads up to the first 200 lines or 25KB of its `MEMORY.md` index. A launch-loaded CLAUDE.md is read in full only if it is within the documented file-size limit; nested and path-scoped instruction files may instead load on demand.

### Can CLAUDE.md enforce a rule?

No. It is context, and Claude may decide not to apply a line. Use a hook, a permission deny rule or a managed setting for anything that must always hold.

### How do I check that my CLAUDE.md loaded?

Start a session and run `/context all`, then look under Memory files. `/memory` also lists the files and opens them in your editor.

## Next steps

- [CLAUDE.md vs AGENTS.md: Which Agents Read Which File](/learn/agents-md-vs-claude-md) if your repository serves more than one tool.
- [Claude Code first session: a plan, edit, review loop](/learn/claude-code-first-session-workflow) to see the file in use.
- [Claude Code plugins explained: install, build, validate, trust](/learn/claude-code-plugins-explained) for packaging instructions as skills.
- The [Agent workflow skills](/topics/agent-workflow) and [Claude Code](/tools/claude-code) on this site.

## Related skills

- [agent-instruction-files](https://skillalmanac.com/skills/skill-almanac/agent-instruction-files.md): Platform Score 46/100 (provisional)
- [rules-to-skills-migration](https://skillalmanac.com/skills/skill-almanac/rules-to-skills-migration.md): Platform Score 45/100 (provisional)
- [project-decision-log](https://skillalmanac.com/skills/skill-almanac/project-decision-log.md): Platform Score 40/100 (provisional)
- [prompt-writing](https://skillalmanac.com/skills/skill-almanac/prompt-writing.md): Platform Score 57/100 (provisional)

## Related guides

- [CLAUDE.md vs AGENTS.md: Which Agents Read Which File](https://skillalmanac.com/learn/agents-md-vs-claude-md.md)
- [Claude Code plugins explained: install, build, validate](https://skillalmanac.com/learn/claude-code-plugins-explained.md)
- [Make Claude Code read AGENTS.md: import and verify](https://skillalmanac.com/learn/make-claude-code-read-agents-md.md)
- [Claude Code Hooks: Setup, One Example, and Failure Modes](https://skillalmanac.com/learn/claude-code-hooks-explained.md)
- [Claude Code first session: a plan, edit, review loop](https://skillalmanac.com/learn/claude-code-first-session-workflow.md)

## Sources

- https://code.claude.com/docs/en/memory
- https://code.claude.com/docs/en/best-practices
- https://code.claude.com/docs/en/overview
- https://code.claude.com/docs/en/skills

Platform Scores report our assessment under a published method. They are not a safety guarantee.
