$ npx rulesync-cli pull✓ Wrote CLAUDE.md (2 rulesets)# Coding Standards- Always use async/await- Prefer named exports
Rule Writing

CLAUDE.md Examples and Templates for Every Stack

Copy-paste-ready CLAUDE.md templates for Next.js, Python, Go, React, and a universal starter — each annotated with why every rule matters.

9 min read·April 22, 2024

Stop staring at a blank CLAUDE.md — start from a proven template

Copy-paste-ready templates for Next.js, Python, Go, and more

Why Templates Accelerate Adoption

The biggest barrier to writing a CLAUDE.md isn't understanding what it does — it's starting from a blank file. You know your project needs AI coding rules, but staring at an empty markdown file and trying to anticipate every convention the AI should follow is paralyzing. Most developers give up after writing three generic lines.

Templates solve this by giving you a proven starting structure. Instead of inventing rules from scratch, you start with 30-50 lines that cover the patterns most projects need, then customize from there. The difference is dramatic: teams that start from templates report getting to a working CLAUDE.md in 10 minutes vs. the 2+ hours it takes from blank.

The templates below are organized by stack. Pick the one closest to your project, copy it into your repo root as CLAUDE.md, and start removing or modifying rules that don't fit. Adding to a template is always easier than building from nothing.

Universal Starter Template

This 30-line template works for any project in any language. It covers the fundamentals that every AI assistant needs to know: code style preferences, error handling philosophy, testing approach, and security non-negotiables. Start here if your stack isn't covered below, or if you want a minimal base to build on.

The template is organized into four sections with markdown headers. The AI uses these headers to locate relevant rules quickly — a flat list of 30 rules is harder to navigate than four groups of 7-8 rules each.

Key rules in this template: prefer explicit error handling over silent failures, write tests for business logic (not implementation details), never hardcode secrets, and use descriptive variable names that explain intent rather than type. These four principles alone eliminate the most common AI code quality issues.

  • # Code Style — naming conventions, formatting, async patterns, imports
  • # Error Handling — explicit errors, no silent catches, typed error responses
  • # Testing — framework preference, test file location, what to test and what not to
  • # Security — no hardcoded secrets, input validation, parameterized queries
💡 Pro Tip

A good CLAUDE.md template covers four areas: code style (40%), testing (20%), security (20%), and project context (20%). Start with this ratio and adjust based on your AI's output.

Next.js / React Template

The Next.js template extends the universal starter with framework-specific rules that prevent the AI's most common mistakes: generating Pages Router code instead of App Router, creating client components when server components would work, using legacy patterns like getServerSideProps, and ignoring React Server Component constraints.

The most impactful rules in this template are the component boundary rules. Telling the AI 'Use React Server Components by default. Only add "use client" when the component needs useState, useEffect, or event handlers' eliminates the single most common issue with AI-generated Next.js code.

Additional rules cover Tailwind CSS conventions (utility-first, no custom CSS unless necessary), data fetching patterns (fetch in server components, not useEffect), and routing conventions (App Router file-based routing, not manual route definitions).

  • Next.js 16+ App Router — not Pages Router
  • React Server Components by default — "use client" only when needed
  • Tailwind utility classes — no custom CSS unless truly necessary
  • Data fetching in server components — no useEffect for initial data
  • File-based routing conventions — layout.tsx, page.tsx, loading.tsx patterns
  • Metadata API for SEO — generateMetadata, not manual <head> tags

Python / FastAPI Template

Python projects need different AI guardrails than JavaScript projects. The most common AI mistakes in Python codebases are: using untyped function signatures, catching bare exceptions, mixing sync and async patterns incorrectly, and generating code that ignores Pydantic model validation.

This template emphasizes type hints everywhere (the AI tends to skip them), proper async/await patterns for FastAPI endpoints, Pydantic models for request/response validation, and structured logging instead of print statements. These four areas cover roughly 80% of the feedback Python teams give on AI-generated code.

For data science and ML projects, add rules about pandas vs. polars preferences, NumPy array patterns, and notebook vs. script conventions. The base Python template intentionally excludes these to stay focused on web API development.

  • Type hints on every function signature and return type
  • Pydantic models for all request/response schemas — no raw dicts
  • Async/await for all I/O operations — no sync calls in async endpoints
  • Structured logging with loguru or structlog — no print() statements
  • Exception handling with specific types — never catch bare Exception
  • Virtual environment conventions — requirements.txt or pyproject.toml
ℹ️ Python Specific

Type hints are the single highest-impact rule for Python projects. AI assistants skip them by default — one rule ('Type hints on every function signature') eliminates 30%+ of review feedback.

Go Template

Go's explicit error handling and strong conventions make it a natural fit for AI rules — but the AI still gets several things wrong without guidance. The most common issues: wrapping errors without context, using panic for recoverable errors, inconsistent struct field naming, and generating overly complex interfaces.

The Go template focuses on idiomatic patterns: always wrap errors with fmt.Errorf and %w for unwrapping, return errors instead of panicking, keep interfaces small (1-3 methods), and use table-driven tests. These rules align the AI with the Go community's established conventions.

The template also includes rules about dependency injection patterns, context propagation (always pass ctx as the first parameter), and goroutine lifecycle management. These are areas where AI-generated Go code is most likely to introduce subtle bugs.

  • Error wrapping with fmt.Errorf("%w", err) — never bare error returns
  • No panic for recoverable errors — return errors up the call stack
  • Small interfaces (1-3 methods) — accept interfaces, return structs
  • Table-driven tests with t.Run — subtests for each scenario
  • Context as first parameter — propagate ctx through all function chains
  • Goroutine lifecycle — always ensure goroutines can be cancelled via context

How to Customize Any Template

Templates are starting points, not sacred texts. The most effective CLAUDE.md files are customized to reflect your project's specific conventions, architecture, and domain. Here's a systematic approach to customization that takes 10-15 minutes.

First, read through the template and remove any rule that doesn't apply to your project. If you don't use Tailwind, remove the Tailwind rules. If you don't write tests yet (no judgment), remove the testing section for now and add it back when you do. Fewer accurate rules beat many irrelevant ones.

Second, add project-specific context. What's your directory structure? What database and ORM do you use? Are there domain-specific terms the AI should know? A line like 'We use Drizzle ORM with Neon Postgres — never generate Prisma code' prevents an entire class of errors.

Third, add the rules you wish existed last week. Think about the last 5 times you corrected AI-generated code. Each correction is a missing rule. 'Don't use default exports' or 'Always destructure props in component parameters' — these small, specific rules compound into dramatically better output.

  1. 1Copy the closest template into your repo root as CLAUDE.md
  2. 2Remove rules that don't apply to your project (2 minutes)
  3. 3Add your stack specifics: framework, ORM, database, key libraries (3 minutes)
  4. 4Add your top 5 'things I always correct the AI on' as rules (5 minutes)
  5. 5Add project context: directory structure, naming patterns, domain terms (5 minutes)
  6. 6Commit, code with it for a day, and iterate based on AI output
Quick Start

The fastest path: copy a template, delete what doesn't apply, add your top 5 AI corrections as rules. Total time: 10 minutes. Total impact: dramatically better AI output from day one.

Sharing Templates Across Your Org

Once you've built a great template for your stack, the next challenge is getting it to every repo that needs it — without falling back to copy-paste. This is where the template becomes a composable ruleset.

The pattern is straightforward: upload your template as a ruleset in RuleSync, give it a descriptive name (e.g., 'nextjs-standards' or 'python-fastapi-base'), and assign it to projects that use that stack. You can layer a company-wide base ruleset underneath and team-specific overrides on top.

When you improve the template — fix a rule, add a new convention, remove something outdated — every repo that uses the ruleset gets the update on the next sync. No copy-pasting, no drift, no 'which version is the latest?' confusion.

CLAUDE.md Examples and Templates for Every Stack — RuleSync Blog