CLAUDE.md Examples & Template

Working CLAUDE.md examples for Python, Node.js, monorepo, and team projects. Copy the template, fill in the brackets, drop into your repo root.

💥 50p impulse-buy: Power Prompts PDF (first 10 buyers) 30 battle-tested Claude Code prompts · 8-page PDF · paste into CLAUDE.md and never re-type a prompt again · 50p impulse-buy, no commitment

CLAUDE.md is the file Claude Code loads automatically on every session. Put house rules there once and Claude follows them in every conversation. This page has four working templates — pick the one closest to your project, fill the brackets.

Template 1 — Python project

# [PROJECT NAME]

## Stack
- Python 3.12, uv for dependencies (lockfile: uv.lock)
- FastAPI for HTTP, SQLAlchemy 2.0 (async) for DB, Postgres 16
- pytest + pytest-asyncio for tests, ruff for lint, mypy strict mode
- pre-commit hooks: ruff format + ruff check + mypy

## House rules
- Always run `uv run pytest -x` after changes. If failures, fix or revert.
- Type hints required on every function. No `Any` unless commented why.
- No print() — use the structured logger from `src/log.py`.
- No mocks of DB layer in tests. Use the test DB fixture in `tests/conftest.py`.
- Database migrations: write with alembic, review the autogenerate output before committing.

## Project layout
- `src/api/` — FastAPI routers
- `src/services/` — business logic (no FastAPI imports here)
- `src/models/` — SQLAlchemy ORM
- `src/log.py` — logging config
- `tests/` — mirrors src/ layout, one test file per module

## Prompts (invoke by name)
### Code review
Review the current diff as a skeptical senior engineer. Output a markdown
table: | file:line | severity 1-5 | category | one-line fix |. Max 12.
If clean, say so in one sentence and stop.

### Test generation
Write tests for [FN]. 2 happy-path, 2 boundary, 2 invalid input,
1 invariant, 1 regression. Do not mock the function under test.

## Commands you have permission to run
- `uv run pytest -x`
- `uv run ruff check .`
- `uv run mypy src`
- `alembic upgrade head` (test DB only)

Template 2 — Node.js / TypeScript project

# [PROJECT NAME]

## Stack
- Node 22 LTS, pnpm for deps (frozen lockfile)
- TypeScript 5.6, strict mode, no implicit any
- Express + zod for validation, Prisma for ORM, Postgres
- Vitest for tests, eslint + prettier
- Husky pre-commit: lint-staged + tsc --noEmit

## House rules
- Run `pnpm test` after changes. If failures, fix or revert.
- All API inputs go through zod schemas. No raw req.body access.
- No `any` types. Use `unknown` and narrow.
- Prisma queries: use `select` to limit columns; never `SELECT *` via Prisma's implicit return.
- Errors: throw custom error classes from `src/errors/`. The global handler maps them to HTTP codes.

## Project layout
- `src/routes/` — Express routes (validation + handler)
- `src/services/` — business logic (no express imports)
- `src/db/` — Prisma client wrapper
- `src/errors/` — custom error classes
- `tests/` — vitest tests mirroring src/

## Prompts (invoke by name)
### PR summary
Read the current diff. Output 5 lines: WHY, WHAT, HOW, RISK, TESTS.
No marketing language. No "this PR aims to".

### Refactor (safe rename)
Rename [OLD] to [NEW] across imports, definitions, tests, comments.
Touch no other code. Run `pnpm test`. Confirm green.

## Commands
- `pnpm test`
- `pnpm lint`
- `pnpm tsc --noEmit`

Template 3 — Monorepo (multi-package)

# [REPO NAME]

## Layout (pnpm workspaces)
- `packages/api` — backend (TypeScript, Express)
- `packages/web` — frontend (Next.js 15, app router)
- `packages/shared` — types and schemas used by both
- `packages/cli` — Node CLI for ops tasks

## Cross-package rules
- Types that cross package boundaries live in `packages/shared`. Do NOT duplicate.
- A change in `packages/shared` must update both `api` and `web` callers in the SAME PR.
- Never import from `packages/web` into `packages/api` or vice versa.

## Per-package CLAUDE.md
Each package has its own `CLAUDE.md` with package-specific rules.
If you're working inside a package, the package CLAUDE.md is authoritative.
This root CLAUDE.md only covers cross-package concerns.

## Test command
- `pnpm -r test` — runs every package's tests
- After cross-package change, ALWAYS run this, not just one package's tests

## Prompts
### Cross-package change planner
For a change touching [PACKAGE_A] and [PACKAGE_B]:
1. List the shared types/contracts affected
2. Plan: shared first, then api, then web (or matching dependency order)
3. After each step, run `pnpm -r tsc --noEmit`. Stop on first error.

Template 4 — Team project (with operational rules)

# [PROJECT]

## Who's on this project
- Code review must include @backend-leads for changes to `src/api/`
- DB schema changes require @dba review (use the migration template in `docs/migrations.md`)
- Customer-facing copy changes require @design review (label PRs `needs-copy-review`)

## Branching
- Main is protected. Branch from main, PR back to main.
- Branch names: `feat/-`, `fix/-`, `chore/`
- One commit per logical change. Use the commit template (CLAUDE: respect it).

## Deploy
- `main` → staging on merge (auto)
- Production tag `vX.Y.Z` → prod (manual approval in CI)
- Hotfixes: branch from prod tag, not from main

## Safety rules for Claude
- Never push to main directly. Always open a PR.
- Never run `git push --force` unless I explicitly ask, even on feature branches.
- Never run anything against the production DB. If a script touches DB, confirm it points to staging.
- Always create new commits — do not amend unless I ask.
- When generating migrations, only WRITE the migration file. Do NOT run it. I'll review and run.

## Prompts
### Pre-PR checklist
Before I open a PR, check:
- All tests pass locally
- No console.log / print() left in
- No commented-out code
- The PR description follows the template at `docs/pr-template.md`
- Migration (if any) is reversible

Output as a checklist. Fix what you can, flag what you can't.

What to include vs leave out

IncludeLeave out
Stack and versions (lockfile name)Generic "we use Python" — Claude knows
Test/lint commands you want Claude to runLong lists of every npm script
House rules with "always" or "never" framingAspirational style guides Claude can't enforce mechanically
Named prompts you reuseOne-off prompts for a single session
Safety rules (no force-push, no prod DB)Generic warnings Claude already follows
Project layout if non-standardThe Python/Node default layout — Claude can infer

The CLAUDE.md anti-patterns

Pair CLAUDE.md with a prompts pack

The Claude Code Power Prompts PDF gives you 30 named prompts you can paste under ## Prompts in your CLAUDE.md. Paste once, Claude reads them every session, you stop re-typing. £3 launch tonight (first 10 buyers), £5 standard, 8 pages, instant download.

Grab the 30-prompt PDF →

Frequently asked questions

Where does Claude Code look for CLAUDE.md?
Claude Code reads CLAUDE.md at the project root (where you launched `claude`), at `~/.claude/CLAUDE.md` (global), and at any parent directory above the current. Sub-directory CLAUDE.md files override parents for the files inside them. Use this layering: house-style rules at `~/.claude/`, project rules at repo root, area-specific rules in sub-packages.
How long should CLAUDE.md be?
Aim for 100–300 lines. Below 100 you're underspecifying; above 300 Claude has trouble keeping all rules in mind and may quietly drop the less-important ones. If you have more than 300 lines of rules, split by sub-directory or extract to docs/ and reference them by path.
Should CLAUDE.md include actual prompts I want Claude to reuse?
Yes — that's one of its highest-value uses. Define named prompts under headings like '## Prompts' or '## Code Review'. Then in any session: 'use the Code Review prompt on the current diff'. Claude pulls the named prompt from CLAUDE.md without re-pasting.

Free tools

Cost Calculator → API Cookbook → Diff Summarizer → Skills Browser →

More examples

Claude API Python QuickstartClaude API Node.js / TypeScript QuickstartClaude API Streaming in PythonClaude API Streaming in Node.js / TypeScriptClaude API Tool Use in PythonClaude API Tool Use in Node.js / TypeScript