Skip to the content.

CLAUDE.md Templates: Ready-to-Use CLAUDE.md and AGENTS.md Files for 20+ Stacks

Copy-paste CLAUDE.md templates (and an AGENTS.md template) for popular stacks, plus a practical guide to writing project instructions that AI coding agents actually follow. Templates cover Next.js, React + Vite, Node/Express, FastAPI, Django, Rails, Laravel, Go, Rust, Spring Boot, ASP.NET Core, Flutter, Expo/React Native, SvelteKit, Nuxt, Chrome extensions, Terraform, Turborepo monorepos, Python libraries and data science projects, plus a personal ~/.claude/CLAUDE.md, a stack-independent working agreement, and path-scoped .claude/rules/ snippets. A small, tested linter catches the mistakes that make instruction files silently fail.

Use them with Claude Code, or with Codex, Cursor, GitHub Copilot, Gemini CLI / Antigravity CLI, Aider and other agents through AGENTS.md.

Last reviewed: December 2026. Loading rules for each tool were checked against the official documentation linked in Where to go next.

Contents

60-second quick start

git clone https://github.com/Ralpberry-Labs/claude-md-templates
cp claude-md-templates/templates/python-fastapi/CLAUDE.md ./CLAUDE.md
# fill in every <placeholder>, delete lines that do not apply
python3 claude-md-templates/tools/claude_md_lint.py CLAUDE.md

Then start Claude Code and run /memory (or /context all) to confirm the file is loaded.

Prefer a cross-tool file? Copy templates/agents-md-universal/AGENTS.md instead, and add the two-line CLAUDE.md next to it that imports it.

Alternatively, run /init in Claude Code to generate a draft from your codebase, then compare it with the matching template and keep the best of both. The templates are strongest on rules and gotchas that cannot be discovered by reading the code.

Template catalog

Template Stack Highlights
nextjs-app-router Next.js App Router, React, TypeScript Server vs client components, NEXT_PUBLIC_ secrets rule, build check for routing/caching changes
react-vite-spa React, Vite, TanStack Query Vite does not typecheck, VITE_ env exposure, Testing Library by role
node-express-typescript Express, TypeScript, zod Thin routes, typed errors, Express 4 vs 5 async errors, parameterized SQL
python-fastapi FastAPI, Pydantic v2, SQLAlchemy, Alembic, uv No blocking calls in async def, review autogenerated migrations
django Django, DRF/Ninja, PostgreSQL Services layer, N+1 checks, sqlmigrate, reversible data migrations
rails Rails 8, Hotwire, Solid Queue/Sidekiq Strong params, authorization, concurrent indexes, idempotent jobs
laravel Laravel, Pest/PHPUnit Form Requests, Policies, preventLazyLoading, env() only in config
go-service Go, chi/net/http, pgx + sqlc Error wrapping, context everywhere, goroutine ownership, race detector
rust-cli Rust, clap, anyhow/thiserror No unwrap outside tests, clippy -D warnings, --json output
spring-boot Spring Boot 3, JPA, Flyway, Testcontainers Constructor injection, DTOs not entities, never edit applied migrations
dotnet-aspnet-core ASP.NET Core, EF Core, xUnit Nullable warnings, async all the way, DI lifetimes, AsNoTracking
flutter Flutter, Riverpod/Bloc, freezed Never edit generated files, const widgets, states for async views
expo-react-native Expo, Expo Router, EAS npx expo install, when a new dev build is needed, secure storage
sveltekit SvelteKit, Svelte 5 runes Runes only, server vs universal load, $lib/server, form actions
nuxt Nuxt, Vue 3, Nitro useFetch keys, server-only runtime config, hydration mismatches
chrome-extension Manifest V3, TypeScript Stateless service worker, minimal permissions, no remote code
terraform Terraform/OpenTofu Plan only, never apply; no state surgery; for_each over count
turborepo-monorepo pnpm workspaces + Turborepo --filter and affected runs, workspace:*, per-package CLAUDE.md
python-library Python package on PyPI Public API and deprecations, minimum Python version, extras
python-data-science pandas/polars, scikit-learn, Jupyter Raw data read-only, leakage checks, baselines, no dataframe dumps
agents-md-universal Any Cross-tool AGENTS.md plus a CLAUDE.md that imports it
global-personal Your machine ~/.claude/CLAUDE.md: how you like to work, git habits, verification
working-agreement Any Paste-in behavior block: clarify, stay in scope, verify, report honestly

Path-scoped rule snippets for .claude/rules/ (load only when matching files are touched): testing, database migrations, frontend components. Plus a CLAUDE.local.md example for personal, uncommitted notes.

Every template is under 200 lines, uses <angle brackets> for things you must fill in, and passes the linter.

What goes in a good CLAUDE.md

The best instruction files contain what an agent cannot learn by reading the code, written as exact, checkable instructions.

Include Why
One-line project summary and stack Orients every session in seconds
Exact commands: install, dev, test (all and single), lint, typecheck, build, migrate Agents waste the most time guessing these
Directory responsibilities (“server code lives in lib/server/”) Prevents code in the wrong layer
Rules a linter does not enforce, with the reason or location “Money is integer cents” saves a class of bugs
Gotchas: services that must be running, generated files, slow or flaky things What a new teammate trips on in week one
Boundaries: what not to touch, what to ask about first Stops unwanted edits to lockfiles, migrations, CI
Definition of done Agents follow end-of-task checklists well
Leave out Why
Anything your formatter or linter already enforces Costs context, adds nothing
Generic advice (“write clean code”, “follow best practices”) Changes no behavior
Long architecture essays Link to docs/ or import selectively; move area-specific detail to path-scoped rules
Facts that change weekly (current sprint, who is on call) Goes stale and misleads
Secrets, internal URLs with tokens Instruction files are committed and shared
Instructions for one task Put them in the prompt, or a skill if they recur

Write instructions the way you would write a runbook: imperative, specific, verifiable. “Run pnpm tsc --noEmit after changing types” beats “make sure types are correct”.

Anatomy of a template

Every template follows the same order, so you can scan any of them quickly:

# <Project name>
<One sentence: what it does and who uses it.>

## Stack              -> versions and the tools that matter, with choices as <a | b>
## Commands           -> copy-pasteable, including how to run ONE test
## Layout             -> what lives where, and what must not import what
## Rules              -> the non-obvious constraints, each with a reason or location
## Gotchas            -> traps specific to this repo (in some templates)
## Definition of done -> the checks to run before saying "done"

The stack templates encode framework-specific traps that agents commonly hit. A few examples:

Before and after

Before (typical first attempt):

# My App
This is a Next.js app. Please write clean, well-tested code and follow best practices.
Use TypeScript. Make sure everything works before finishing.

Nothing here changes behavior: the agent already knows it is a Next.js TypeScript app from package.json, and “clean” and “works” are not checkable.

After (from the nextjs-app-router template, filled in):

# Invoicer
Invoicing dashboard for small agencies; customers are logged-in agency admins.

## Commands
- Dev: `pnpm dev` | Typecheck: `pnpm tsc --noEmit` | Tests: `pnpm vitest run path/to/file.test.ts`
- Build before finishing routing or caching changes: `pnpm build`

## Rules
- Server Components by default; `"use client"` only for state, effects or browser APIs.
- All DB access through `lib/server/queries/*`; never import `lib/server` from client components.
- Amounts are integer cents (`amountCents`); never floats.
- Validate every Server Action input with zod.

## Gotchas
- `pnpm test` needs Docker (testcontainers Postgres).

## Definition of done
1. Typecheck and touched tests pass (show the commands)
2. No new `any`, no `console.log`

How Claude Code loads instruction files

File Scope Shared? Loaded
Managed CLAUDE.md (set by your organization) Everyone on the machine Admin-controlled Always
~/.claude/CLAUDE.md You, all projects No Every session
~/.claude/rules/*.md You, all projects No Every session (or by paths)
CLAUDE.md or .claude/CLAUDE.md in the working directory and every parent Project Yes, via git At launch
CLAUDE.local.md next to them You, this project No (gitignore it) At launch, after CLAUDE.md at the same level
CLAUDE.md in subdirectories That subtree Yes On demand, when Claude reads or edits files there
.claude/rules/*.md without paths Project Yes At launch
.claude/rules/*.md with paths Matching files Yes When Claude reads or edits a matching file
AGENTS.md Project Yes Instead of CLAUDE.md when no CLAUDE.md/CLAUDE.local.md exists in the working directory or above (recent versions)

Key facts:

Scale up: imports, rules and nested files

Imports. Pull other files in with @path. Paths are relative to the importing file; imports can nest up to four hops; ~/ works for files in your home directory (Claude Code asks once before loading imports from outside the project).

@docs/architecture.md
@~/.claude/my-team-conventions.md

Imports organize content but do not save context: the imported file loads with the importer. Text in backticks or code blocks is not imported, so `@README` stays literal.

Gotcha this repo’s linter catches: npm scoped package names in prose, like “uses @nuxt/test-utils”, look like imports. Put package names in backticks.

Path-scoped rules. Put topic files in .claude/rules/. With a paths field they only load when Claude touches matching files, which is the main way to keep a big project’s instructions small:

---
paths:
  - "migrations/**"
  - "db/migrate/**"
---
# Migration rules
- Create PostgreSQL indexes CONCURRENTLY...

Nested CLAUDE.md files. In a monorepo, keep a short root file (how to run things, cross-cutting rules) and a CLAUDE.md in each app or package with its local commands and conventions. They load when Claude works in that folder.

Exclusions. In large monorepos, the claudeMdExcludes setting skips CLAUDE.md files from other teams by glob.

One file for every agent: AGENTS.md

AGENTS.md is a plain Markdown convention for agent instructions read by many tools (the agents.md site lists Codex, Cursor, Copilot’s coding agent, Gemini CLI, Jules, Aider, Zed, Warp, Windsurf, Devin, Junie, Amp, goose, opencode, RooCode and others). There are no required fields.

Patterns for teams that use several tools:

Situation Setup
Mostly non-Claude tools, Claude Code too Write AGENTS.md. Recent Claude Code versions read it when there is no CLAUDE.md.
Claude-specific additions needed AGENTS.md for shared content + CLAUDE.md containing @AGENTS.md and the extras
Everyone on macOS/Linux, no Claude extras ln -s AGENTS.md CLAUDE.md (avoid symlinks if anyone uses Windows)
Gemini CLI / Antigravity CLI Both read AGENTS.md in the workspace (Gemini CLI via context.fileName); global rules stay in ~/.gemini/GEMINI.md
Aider Add read: AGENTS.md to .aider.conf.yml
GitHub Copilot Reads AGENTS.md (nearest file wins) and .github/copilot-instructions.md

The agents-md-universal template contains both files.

Instruction files across tools

Tool Main file(s) Scoped rules Nesting Notes
Claude Code CLAUDE.md, .claude/CLAUDE.md, CLAUDE.local.md; reads AGENTS.md when no CLAUDE.md exists .claude/rules/*.md with paths globs Parent dirs at launch, subdirs on demand @path imports, 4 hops
OpenAI Codex AGENTS.md, AGENTS.override.md; global ~/.codex/AGENTS.md Nested AGENTS.md per directory Root to working dir, closer files later Combined size capped by project_doc_max_bytes (default 32 KiB); extra names via project_doc_fallback_filenames
GitHub Copilot .github/copilot-instructions.md, AGENTS.md, or a root CLAUDE.md/GEMINI.md .github/instructions/*.instructions.md with applyTo globs Nearest AGENTS.md wins Personal > repository > organization instructions
Cursor AGENTS.md .cursor/rules/*.mdc with description, globs, alwaysApply Nested AGENTS.md supported Rule types: always, auto-attached by glob, agent-requested, manual
Gemini CLI GEMINI.md (configurable with context.fileName, can include AGENTS.md) - Global, workspace and just-in-time subdirectory files @file imports; /memory show, /memory reload
Antigravity CLI GEMINI.md and AGENTS.md in the workspace; ~/.gemini/GEMINI.md - - Successor to Gemini CLI for many users; workspace skills in .agents/skills/
Aider Any file passed with --read or read: in .aider.conf.yml (for example CONVENTIONS.md or AGENTS.md) - - Read-only context files

Details change often; the Where to go next section links each tool’s current docs.

The working agreement

templates/working-agreement/CLAUDE.md is a stack-independent block that addresses the four most common agent failure modes:

  1. Guessing instead of asking when the request is ambiguous. Fix: restate the task, ask with a proposed default.
  2. Over-building: extra abstractions, options and layers nobody asked for. Fix: simplest change that solves the stated problem.
  3. Collateral edits: reformatting, renaming or “improving” unrelated code. Fix: surgical diffs; note other problems instead of fixing them.
  4. Unverified success claims. Fix: run the checks, report exact commands and results, and say what was not verified.

Paste it at the end of any template, or into ~/.claude/CLAUDE.md so it applies everywhere.

Copy-paste rule library

Reusable blocks for common concerns. Paste the ones that apply, then make them specific to your project (replace the examples in angle brackets).

Git and pull requests

## Git
- Never commit or push unless asked. Never force-push shared branches.
- Branch names: `<type>/<ticket>-<short-slug>` (e.g. `fix/PAY-142-refund-rounding`).
- Commit messages: Conventional Commits; the body explains why.
- One concern per PR; include how you verified the change.

Testing

## Testing
- Run the narrowest relevant tests first: `<single-test command>`, then `<full suite>`.
- Bug fixes start with a failing test that reproduces the bug.
- No sleeps in tests; use fake timers. No real network calls; use the fixtures in `<path>`.
- Do not delete or weaken a test to make a change pass; explain instead.

Dependencies

## Dependencies
- Ask before adding a dependency. Prefer the standard library and existing packages.
- Add packages with `<package manager command>` so the lockfile updates; never edit the lockfile by hand.
- New dependencies need a reason in the PR description (size, maintenance, license compatibility).

Security

## Security
- Never print, log or commit secrets; read them from environment variables listed in `.env.example`.
- Validate all external input at the boundary (`<validation library>`); parameterize every query.
- Every new endpoint checks authorization, not just authentication.
- Do not disable security linters or checks; flag the finding instead.

Database

## Database
- Schema changes only through new migrations in `<path>`; never edit merged migrations.
- Migrations must work while the previous app version is still running (expand/contract).
- Large-table changes: concurrent index creation, batched backfills, `lock_timeout`.

Frontend and accessibility

## Frontend
- Semantic HTML first; every interactive element is keyboard accessible with an accessible name.
- Text contrast at least 4.5:1; no layout breakage at 320 px width or 200% zoom.
- Images have width/height and alt text; the LCP image is never lazy-loaded.

Performance

## Performance
- Measure before and after any optimization and report both numbers.
- Watch for N+1 queries in list endpoints; use `<eager loading API>`.
- Do not add caching without stating the invalidation rule.

Documentation

## Docs
- User-visible changes update `README.md` or `docs/` in the same PR.
- Public functions have doc comments with an example.
- Add a CHANGELOG entry under Unreleased.

Working style

## Working style
- Restate the task; ask (with a proposed default) when something is ambiguous.
- Do what was asked and nothing more; list other problems you notice instead of fixing them.
- Before finishing, run the checks and report the exact commands and results; say what you could not verify.

Lint your instruction files

python3 tools/claude_md_lint.py                       # CLAUDE.md, AGENTS.md, CLAUDE.local.md, .claude/rules/** in cwd
python3 tools/claude_md_lint.py path/to/CLAUDE.md docs/AGENTS.md
python3 tools/claude_md_lint.py --templates templates/*/*.md   # allow <placeholders>
Rule Severity Catches
length warning over 200 lines, error over 400 Files too long to be followed reliably
placeholder warning Unfilled <Project name>, <a \| b> choices, TODO, TBD
missing-import error @path that does not exist, including accidental ones like @scope/package
import-depth warning Imports nested deeper than four hops
vague warning “write clean code”, “follow best practices”, “be careful”, “make sure it works”
no-commands warning No code-formatted commands at all
secret error Keys, tokens, private keys, password = "..."
frontmatter error Unclosed frontmatter or empty paths: in rules files

Code spans and fenced blocks are excluded from import, vague-phrase and placeholder checks, matching how Claude Code treats imports. Exit code 1 on errors, so you can run it in pre-commit or CI. Python 3.9+, no dependencies; tests in tests/.

Keeping it alive

Instructions vs hooks vs skills

Mechanism Strength Use for Example
CLAUDE.md / AGENTS.md Guidance the model usually follows Facts, conventions, commands, definition of done “Amounts are integer cents”
.claude/rules/ with paths Guidance, loaded only when relevant Area-specific conventions Migration rules for migrations/**
Skills (SKILL.md) On-demand procedures Multi-step workflows used sometimes “How we release”, “how we review”
Permission rules Enforced by Claude Code Allow/ask/deny tools and paths Deny Read(./.env)
Hooks Enforced by code you write Must-always / must-never actions Run the formatter after every edit; block git push --force

If a rule must never be broken, do not rely on an instruction file alone.

Mistakes that make agents ignore you

Mistake Fix
600-line CLAUDE.md copied from a wiki Cut to the essentials; move details to path-scoped rules, skills or linked docs
“IMPORTANT” and “MUST” on everything Emphasis only works when it is rare; reserve it for one or two critical rules
Commands that no longer exist Re-verify commands after tooling changes; the linter cannot run them for you
Rules without reasons “Do not use fetch in components (all requests go through api/client.ts for auth refresh)” is followed far more reliably
Contradictions between root and nested files Keep cross-cutting rules only at the root
Instructions about a single task Put them in the prompt instead
A CLAUDE.local.md added to a repo that relies on AGENTS.md It counts as a CLAUDE.md, so Claude stops reading AGENTS.md; import @AGENTS.md in it or change the project instructions setting

FAQ

Should I commit CLAUDE.md? Yes, the project CLAUDE.md (or AGENTS.md) is meant to be shared. Keep personal notes in CLAUDE.local.md (gitignored) or ~/.claude/CLAUDE.md.

How long should a CLAUDE.md be? Anthropic’s documentation recommends targeting under 200 lines per file. Most good project files are 40-120 lines. Use path-scoped rules for area-specific detail.

What is the difference between CLAUDE.md and AGENTS.md? Both are Markdown instruction files. CLAUDE.md is Claude Code’s native file (with imports, rules and local variants); AGENTS.md is a cross-tool convention. Recent Claude Code versions read AGENTS.md when no CLAUDE.md exists, and a CLAUDE.md can import it with @AGENTS.md.

Does /init make templates unnecessary? /init is good at discovering commands and structure from the code. Templates add what code does not reveal: framework traps, boundaries and a definition of done. Use both.

Where do I put instructions for one package in a monorepo? In that package’s own CLAUDE.md (or AGENTS.md), or in a root .claude/rules/ file with paths pointing at the package.

Can I use these templates with Cursor or Copilot? Yes. Save the content as AGENTS.md (both tools read it), or adapt it into .cursor/rules/*.mdc or .github/copilot-instructions.md.

Why are some choices written as <pnpm | npm>? So you pick the one your project uses and delete the rest. The linter warns about any left unfilled.

Do instruction files work in CI runs of Claude Code? Yes. The GitHub Action and claude -p read the repository’s CLAUDE.md like an interactive session does, unless you run with --bare, which skips it.

Where to go next

Contributing

New stack templates and fixes are welcome. A template must: stay under 200 lines, use <placeholders> for project-specific values, include exact commands (including how to run one test), list framework-specific traps rather than generic advice, end with a definition of done, and pass python3 tools/claude_md_lint.py --templates. Please verify commands against the framework’s current documentation.

If this helped you, a star helps others find it.

More free resources

Part of the Ralpberry Labs open-source collection. See also Top 100 Open Source.