Skip to main content
gradually.ai logogradually.ai
Blog
About Us
Subscribe to AI Newsletter
AI Newsletter
  1. Home
  2. AI Blog

How to Create the Perfect CLAUDE.md (incl. Template)

Learn how to create a perfect CLAUDE.md file. Including free template, best practices, and pro tips for Claude Code.

FHFinn Hillebrandt
September 25, 2025
Auf Deutsch lesen
AI Programming
How to Create the Perfect CLAUDE.md (incl. Template)
š•XShare on XFacebookShare on FacebookLinkedInShare on LinkedInPinterestShare on PinterestThreadsShare on ThreadsFlipboardShare on Flipboard
Links marked with * are affiliate links. If a purchase is made through such links, we receive a commission.

Maybe you know this:

Claude does something weird, suddenly creates 10 new files when you just wanted to fix a bug, uses JavaScript even though your entire project is TypeScript, or spends 5 minutes or more understanding your project before each task.

The solution is to create one or more CLAUDE.md files.

In this blog article, I'll show you how to create a perfect CLAUDE.md file including templates, examples, and pro tips. So you never have to say (or, realistically, less often) "Claude, no! What the hell are you doing?" anymore.

1. What is a CLAUDE.md File?

CLAUDE.md is a "here are my rules" file for Claude Code. You tell it once how it should work for you, and it remembers for all future sessions.

Important to understand:

A CLAUDE.md isn't static documentation, but a living documentation of Claude's mistakes. Every time Claude does something wrong, that correction goes directly into my CLAUDE.md (so Claude gets smarter with each task).

After struggling with Claude for weeks, I analyzed my sessions. And with a proper CLAUDE.md, things just work much better.

2. Global, Project, and Folder-Specific CLAUDE.md

There are the following types of CLAUDE.md files:

  • Global CLAUDE.md (~/.claude/CLAUDE.md): Your personal settings that apply to all projects
  • Project-specific (in project root): Specific instructions for a single project
  • Folder-specific CLAUDE.md (in project root): Specific instructions for a single folder

You don't need to reference all three file types in prompts – Claude Code automatically checks with every prompt whether global, project-specific, or folder-specific CLAUDE.md files exist and loads them into the context window accordingly.

Claude loads CLAUDE.md files hierarchically and combines them intelligently. The most specific (deepest nested) file wins in conflicts. This means:

# ~/.claude/CLAUDE.md (Global)
- Always use TypeScript
- Write tests with Jest

# ~/project/CLAUDE.md (Project)
- Write tests with Vitest  # Overrides Jest

# Result for Claude:
- Always use TypeScript (from global)
- Write tests with Vitest (from project)

You should still avoid conflicts between file types or clearly point out conflicts to prevent unexpected behavior.

Tip
Keep the global CLAUDE.md minimal (max 50 lines) and put everything project-specific in the local file.

3. Structure and Layout

CLAUDE.md is a normal Markdown file. Nothing magical about it. Claude interprets it as additional context for each request.

The trick is finding the right balance between "too little info" and "token waste". In that regard, I keep the formatting as simple as possible. I mostly use only:

  • Headings with # for structure
  • Bullet points with - for lists
  • Code blocks with ``` for examples
  • Bold with **text** for important things

What you should avoid are tables (too many tokens), images (get ignored), links (mostly useless).

4. Creating the CLAUDE.md Step by Step

Let's get practical. I'll show you how to create a solid CLAUDE.md in 10 minutes that actually makes a difference.

4.1 Setting Up Global CLAUDE.md in ~/.claude/

First, the global file. This should contain your personal preferences – things you always want, regardless of which project you're working on:

# Terminal
mkdir -p ~/.claude
touch ~/.claude/CLAUDE.md

Here's an example for a global CLAUDE.md:

# Global Developer Preferences

## General Rules
- Prefer TypeScript over JavaScript
- Write code in English, comments in German
- Use modern ES6+ syntax
- No console.log() in production code

## Code Quality
- Write clean, readable code
- Use meaningful variable names
- Keep functions small (max 20 lines)
- Follow DRY principle

## Error Handling
- Always try-catch with async/await
- Never swallow errors
- Meaningful error messages

## Git
- Commit messages in English
- Use Conventional Commits format
- Never push directly to main

4.2 Defining Project-Specific Instructions

Now the project-specific CLAUDE.md. This should contain everything Claude needs to know about your specific project.

To do this, simply give Claude Code the following command:

Create a CLAUDE.md for this project. Analyze the project comprehensively so you don't forget anything. Use the following template:"

And copy in the following template (simply copy & paste):

# [Project Name]

[One-sentence description of the project]

## Tech Layers
- **Framework**: [e.g., Next.js, React, Vue]
- **Language**: [e.g., TypeScript, Python]
- **Database**: [e.g., PostgreSQL, MongoDB]
- **Styling**: [e.g., Tailwind, CSS Modules]
- **Testing**: [e.g., Jest, Vitest, Pytest]

## Project Structure
```
src/
ā”œā”€ā”€ [important folder]/   # [Description]
ā”œā”€ā”€ [another folder]/     # [Description]
└── [config files]        # [Description]
```

## Development
```bash
[install command]        # Install dependencies
[dev command]           # Development server
[build command]         # Production build
[test command]          # Run tests
```

## Code Standards
- [Standard 1, e.g., "TypeScript strict mode"]
- [Standard 2, e.g., "Follow ESLint rules"]
- [Standard 3, e.g., "No any types"]
- [Standard 4, e.g., "Tests for new features"]

## Project-Specific Rules
- [Rule 1, e.g., "API calls only via services/"]
- [Rule 2, e.g., "Styling only with Tailwind"]
- [Rule 3, e.g., "Components must be typed"]

## Important Notes
- [Note 1, e.g., "Production secrets in .env.production"]
- [Note 2, e.g., "No direct DB queries"]
- [Note 3, e.g., "Mind rate limiting"]

## Common Mistakes to Avoid
- DON'T: [Common mistake]
- DON'T: [Another mistake]
- ALWAYS: [Best practice]
- ALWAYS: [Another best practice]

And here's what it can look like in the end:

# AI Blog Project

Next.js 15 Blog with TypeScript, focused on AI and SEO topics.

## Tech Layers
- **Framework**: Next.js 15.3.3 with App Router
- **Language**: TypeScript 5.x (strict mode)
- **Styling**: Tailwind CSS v4 with PostCSS
- **UI**: Radix UI + shadcn/ui components
- **Database**: PostgreSQL with Prisma ORM

## Project Structure
```
src/
ā”œā”€ā”€ app/              # Next.js App Router
│   └── blog/         # Blog posts (IMPORTANT: No /blog/ URL!)
ā”œā”€ā”€ components/       # React Components
│   └── ui/          # shadcn/ui Components
ā”œā”€ā”€ lib/             # Utilities and Services
└── types/           # TypeScript Types
```

## Important Commands
```bash
npm run dev          # Development server
npm run build        # Production build
npm run lint         # Run ESLint
npm run typecheck    # TypeScript check
```

## Blog System Rules
- Blog posts in src/app/blog/[slug]/page.tsx
- URLs WITHOUT /blog/ prefix (Rewrite in next.config.ts)
- Always use BlogPostConfig for metadata
- CodeBlock component for all code examples
- Define FAQ items outside the component

## Code Standards
- Components in PascalCase
- Utilities in camelCase
- Tailwind instead of CSS modules
- No new components without checking ui/
- German content, English code

## Common Mistakes to Avoid
- DON'T: Create new README.md
- DON'T: Leave console.log in code
- DON'T: New UI components from scratch
- ALWAYS: Edit existing files
- ALWAYS: TypeScript strict mode

## Git Workflow
- Feature branches from main
- PR before merge
- Squash commits on merge

5. Avoiding Common Beginner Mistakes

Here are mistakes you should avoid:

  1. Being too vague: "Write good code" doesn't help. Be specific: "Use async/await instead of Promises"
  2. Putting in too much: 1000+ lines CLAUDE.md? Claude ignores half of it. Keep CLAUDE.md compact.
  3. File in wrong location Check with ls -la ~/.claude/ and in project root
  4. Not updating: Project changes, CLAUDE.md stays the same = chaos
  5. Contradictory instructions "Use tabs" globally and "Use spaces" locally = chaos (Claude can often detect conflicts, but not always)
  6. Wrong Markdown syntax No tabs, only spaces. Markdown must be valid.
  7. Wanting to explain everything: Claude knows the basics. You don't need to explain what React is.
  8. Copy-paste without adapting: My template is a starting point, not the solution.
Tip
Ask Claude directly: "What's in your CLAUDE.md?" – the answer shows what was actually loaded.

6. Adapting to Your Workflow

The template is just the beginning. What works for me doesn't have to work for you. Here's my workflow for adapting:

  1. Start with the basic template
  2. Work normally with Claude for a week or a few days
  3. Note every "Claude does X wrong" moment
  4. Add these as rules to CLAUDE.md
  5. Test if it's better
  6. Repeat

After 2-3 weeks, you'll have a CLAUDE.md that perfectly fits your style.

7. Pro Tips: Advanced CLAUDE.md Configuration

Time for the advanced tricks that make the difference between "pretty good" and "holy shit this is good".

7.1 Formulating Context-Specific Instructions

Instead of general instructions, make them situation-specific:

## Context Rules

### For Bug Fixes
- First understand, then fix
- Analyze root cause
- Write regression test
- Update changelog

### For New Features
- First define Types/Interfaces
- API-First Design
- Write tests in parallel
- Documentation comments

### For Refactoring
- Don't change functionality
- Tests must stay green
- Proceed step by step
- Measure performance

7.2 Defining Code Standards and Best Practices

Be ultra-specific with code standards. Claude does exactly what you say – no more, no less:

## Code Standards (Detailed)

### Naming Conventions
- Components: PascalCase (UserProfile, NavBar)
- Hooks: camelCase with 'use' prefix (useAuth, useFetch)
- Utils: camelCase (formatDate, parseJson)
- Constants: SCREAMING_SNAKE_CASE (API_URL, MAX_RETRY)
- Types/Interfaces: PascalCase with Suffix (UserType, ApiResponse)

### Async Code
```typescript
// ALWAYS like this:
try {
  const data = await fetchData()
  return processData(data)
} catch (error) {
  logger.error('Fetch failed:', error)
  throw new AppError('Data fetch failed', error)
}

// NEVER like this:
fetchData().then(data => processData(data))
```

### Imports
- Absolute imports for src/ ('@/components/Button')
- Grouped imports (React, Third-party, Local)
- Prefer named exports

7.3 Optimizing Project Structure and File Paths

Claude tends to create files in the wrong place. Be explicit:

## File Locations (IMPORTANT!)

### Where new files go:
- React Components → src/components/[name]/[Name].tsx
- API Routes → src/app/api/[route]/route.ts
- Utilities → src/lib/utils/[name].ts
- Types → src/types/[name].types.ts
- Hooks → src/hooks/use[Name].ts
- Tests → [same-folder]/[name].test.ts

### These folders NOT to touch:
- node_modules/ (obvious, but Claude does it anyway)
- .next/ (Build output)
- dist/ (Build output)
- coverage/ (Test output)

### When in doubt:
ALWAYS ask me before creating new files!

7.4 Performance Optimization for Large CLAUDE.md Files

Large CLAUDE.md files can slow Claude down. Here it can help to outsource the instructions from CLAUDE.md to separate docs:

# Project Core (Max 100 Lines)

## Must-Know (Top Priority)
- [Only the most important things]
- [Max 10 points]

## Quick Reference
```
npm run dev
npm run build
npm run test
```

## Details see:
- Architecture: docs/ARCHITECTURE.md
- API: docs/API.md
- Testing: docs/TESTING.md
Tip
Unfortunately, docs aren't always loaded automatically, so you sometimes have to reference them manually.

Outsource details to separate docs and reference them. Claude can ask for more details when needed.

7.5 Version Control and Team Synchronization

What you can do when working in a team:

  • CLAUDE.md in the repo: Yes, commit it. Everyone on the team benefits.
  • CLAUDE.personal.md in .gitignore: For personal preferences
  • Changelog at the end: Document changes
# Team Project

[... Project Config ...]

---
## Changelog
- 2025-01-25: TypeScript strict mode enabled (FH)
- 2025-01-20: Tailwind v4 Update (MK)
- 2025-01-15: Initial version (FH)

8. CLAUDE.md Support in Other Tools

CLAUDE.md isn't just for Claude Code. More and more AI coding tools support the format – either natively or as a fallback. Here you can see which tools support CLAUDE.md and other configuration standards:

Columns:
|
Tool
CLAUDE.md
AGENTS.md
GEMINI.md
Cursor Rules
Native Config
CLI Tools(5 entries)
Claude Code
Anthropic
NativeNoNoNoCLAUDE.md
Codex CLI
OpenAI
FallbackNativeNoNoAGENTS.md
Gemini CLI
Google
NoConfigurableNativeNoGEMINI.md
Aider
Open Source
NoConfigurableNoNo.aider.conf.yml
Factory Droid
Factory.ai
NativeNativeNoNo.factory/droids/*.md
IDE & Editors(6 entries)
Cursor
Cursor Inc.
NativeNativeNoNative.cursor/rules/*.mdc
Windsurf
Codeium
NoNoNoSimilar.windsurf/rules/*.md
Amp
Sourcegraph
FallbackNativeNoNoAGENTS.md
Zed Editor
Zed Industries
Nativevia ACPNativeNosettings.json
JetBrains AI
JetBrains
NoNoNoNo.aiassistant/rules/*.md
Replit Agent
Replit
NoPartialNoNoreplit.md
IDE Extensions(9 entries)
GitHub Copilot
Microsoft
NativeNativeNativeNocopilot-instructions.md
Continue.dev
Open Source
NoProposedNoNo.continue/rules/*.md
Cody
Sourcegraph
NoNoNoNo.vscode/cody.json
Amazon Q
AWS
NoNoNoNo.amazonq/rules/*.md
Tabnine
Tabnine
NoPartialNoNo.tabnine/guidelines/*.md
Supermaven
Cursor (acquired)
NoNoNoNoEditor config
Augment Code
Augment
NativeNativeNoNo.augment/rules/*.md
Cline
Open Source
NoNativeNoNo.clinerules/*.md
Roo Code
Open Source
NoNativeNoNo.roo/rules/*.md
Autonomous Agents(3 entries)
Devin
Cognition
NoPartialNoNoDashboard
Jules
Google
NoNativeNoNoAGENTS.md
Poolside AI
Poolside
NoNoNoNoEnterprise config
Terminal Tools(1 entries)
Warp Terminal
Warp
NoNoNoNolaunch_configurations
Native supportPartial/WorkaroundNo support

Tip: If you work in a multi-tool environment, it can make sense to rename your CLAUDE.md to AGENTS.md and create a symlink for Claude Code:

# CLAUDE.md → AGENTS.md (Universal) + Symlink
mv CLAUDE.md AGENTS.md
ln -s AGENTS.md CLAUDE.md

Frequently Asked Questions

š•XShare on XFacebookShare on FacebookLinkedInShare on LinkedInPinterestShare on PinterestThreadsShare on ThreadsFlipboardShare on Flipboard
FH

Finn Hillebrandt

AI Expert & Blogger

Finn Hillebrandt is the founder of Gradually AI, an SEO and AI expert. He helps online entrepreneurs simplify and automate their processes and marketing with AI. Finn shares his knowledge here on the blog in 50+ articles as well as through his ChatGPT Course and the AI Business Club.

Learn more about Finn and the team, follow Finn on LinkedIn, join his Facebook group for ChatGPT, OpenAI & AI Tools or do like 17,500+ others and subscribe to his AI Newsletter with tips, news and offers about AI tools and online business. Also visit his other blog, Blogmojo, which is about WordPress, blogging and SEO.

Similar Articles

Claude Code Commands: The Ultimate Reference
AI Programming

Claude Code Commands: The Ultimate Reference

January 28, 2026
FHFinn Hillebrandt
Gemini CLI Commands: The Ultimate Menu
AI Programming

Gemini CLI Commands: The Ultimate Menu

January 28, 2026
FHFinn Hillebrandt
Claude Code: The Complete Beginner's Guide
AI Programming

Claude Code: The Complete Beginner's Guide

October 15, 2025
FHFinn Hillebrandt
How to Create the Perfect AGENTS.md (incl. Template)
AI Programming

How to Create the Perfect AGENTS.md (incl. Template)

September 26, 2025
FHFinn Hillebrandt
Claude Code vs. Gemini CLI vs. OpenAI Codex: The Ultimate Comparison
AI Programming

Claude Code vs. Gemini CLI vs. OpenAI Codex: The Ultimate Comparison

September 1, 2025
FHFinn Hillebrandt

Stay Updated with the AI Newsletter

Get the latest AI tools, tutorials, and exclusive tips delivered to your inbox weekly

Unsubscribe anytime. About 4 to 8 emails per month. Consent includes notes on revocation, service provider, and statistics according to our Privacy Policy.

gradually.ai logogradually.ai

Germany's leading platform for AI tools and knowledge for online entrepreneurs.

AI Tools

  • AI Chat
  • ChatGPT in German
  • Text Generator
  • Prompt Enhancer
  • FLUX AI Image Generator
  • AI Art Generator
  • Midjourney Prompt Generator
  • Veo 3 Prompt Generator
  • AI Humanizer
  • AI Text Detector
  • Gemini Watermark Remover
  • All Tools →

Creative Tools

  • Blog Name Generator
  • AI Book Title Generator
  • Song Lyrics Generator
  • Artist Name Generator
  • Team Name Generator
  • AI Mindmap Generator
  • Headline Generator
  • Company Name Generator
  • AI Slogan Generator

Business Tools

  • API Cost Calculator
  • Token Counter
  • AI Ad Generator
  • AI Copy Generator
  • Essay Generator
  • Story Generator
  • AI Rewrite Generator
  • Blog Post Generator
  • Meta Description Generator
  • AI Email Generator

Resources

  • MCP Server Directory
  • Agent Skills
  • n8n Hosting Comparison
  • OpenClaw Hosting Comparison

Ā© 2025 Gradually AI. All rights reserved.

  • Blog
  • About Us
  • Legal Notice
  • Privacy Policy