CLAUDE.md: The File That Makes Your AI 10x More Effective
Context files like CLAUDE.md tell AI assistants how your codebase works before they write a single line. Here's why they matter and how to write a good one.
Every AI coding assistant starts the same way: confused.
It doesn't know your conventions. It doesn't know where you put your database schema, how you structure API routes, or that you use Zod for validation. So it guesses. Sometimes it guesses well. Often it doesn't.
A context file fixes this. One file, read before anything else, that tells the AI how your project works. No guessing. No hallucinating patterns that don't exist in your codebase.
A2SaaS ships with CLAUDE.md out of the box. Here's why — and how you can write one for any project.
What Is a Context File?
A context file is a markdown document at the root of your project that AI tools read automatically before they start working. Different tools use different filenames:
- Claude Code reads
CLAUDE.md - Cursor reads
.cursorrules - GitHub Copilot reads
.github/copilot-instructions.md - Windsurf reads
.windsurfrules
The concept is the same across all of them: give the AI a cheat sheet for your codebase.
Think of it as onboarding documentation — except the new hire is an AI that reads the entire thing in milliseconds and actually follows the instructions.
What Goes in a Good Context File
The best context files are concise and practical. They answer the questions an AI would otherwise have to figure out by reading dozens of files.
1. Project Structure
A quick map of where things live. Not every file — just the important directories and what they contain.
src/
├── app/ # Next.js App Router pages
│ ├── (auth)/ # Sign-in/sign-up
│ ├── (marketing)/ # Landing, pricing, blog
│ ├── (app)/ # Dashboard (requires auth)
│ └── api/ # API routes
├── components/ # React components
├── lib/ # Utilities and clients
└── server/db/ # Database schema and helpers
This alone saves the AI from running search queries just to orient itself.
2. Key Patterns with Code Examples
Show the AI how things are done in your project. Not documentation — actual patterns it should follow.
### API Routes
All API routes use this pattern:
\```typescript
import { success, error, handleApiError } from "@/lib/api";
export async function POST(req: Request) {
try {
const body = await req.json();
return success({ data });
} catch (err) {
return handleApiError(err);
}
}
\```
When the AI sees this, it replicates the pattern exactly. No inventing its own error handling. No importing libraries you don't use.
3. Common Tasks
A "how to" section for the things you'll ask the AI to do most often. Keep it to the steps, not the explanation.
### Add a new API endpoint
1. Create file at `src/app/api/v1/[resource]/route.ts`
2. Use `success()` and `error()` from `@/lib/api`
3. Validate input with Zod
This turns a vague request like "add a users endpoint" into a predictable, consistent result.
4. What NOT to Do
This is where context files really shine. Every codebase has landmines — things that look reasonable but break conventions.
## Do Not
- Use `any` types — always define proper types
- Create wrapper components unless asked — use Shadcn primitives directly
- Skip Zod validation on API inputs
- Store secrets in code — use environment variables
AI assistants are eager to please. Without explicit "don't do this" rules, they'll take shortcuts you'll have to clean up later.
The Compound Effect
A context file doesn't just help with one task. It helps with every task, in every session, for every developer on your team.
Without a context file, each AI interaction starts from zero. The assistant has to rediscover your patterns every time. With a context file, it starts from full understanding.
The effect compounds:
- First task: The AI follows your patterns instead of inventing its own
- Second task: It builds on the first task correctly because it knows the conventions
- Tenth task: Your codebase is still consistent, not a patchwork of different AI-generated styles
How A2SaaS Uses CLAUDE.md
A2SaaS ships with a comprehensive CLAUDE.md that covers:
- Project structure — Where every type of file lives
- Auth patterns — How to use
getCurrentUser()andgetUserId() - Database patterns — How to query with Drizzle
- API patterns — How to structure routes with proper error handling
- Common tasks — Step-by-step for adding pages, endpoints, tables, and emails
- Guardrails — What to avoid
When you clone A2SaaS and open it with Claude Code, the AI already knows how your project works. Ask it to "add a posts API endpoint" and it creates the right file, in the right directory, with the right imports, following the right patterns.
No back-and-forth. No corrections. Just working code on the first try.
Writing Your Own
If you're not using A2SaaS, you can still get these benefits. Create a context file for your project in about 15 minutes:
- Start with structure. Paste your top-level directory tree and annotate it.
- Add 2-3 code patterns. Copy a representative API route, a database query, and a component. These become the templates the AI follows.
- List common tasks. What do you ask the AI to do most? Write the steps.
- Add constraints. What should the AI never do? Be specific.
- Keep it under 200 lines. Long context files defeat the purpose. Be concise.
The file should evolve with your project. When you establish a new pattern, add it. When you deprecate something, remove it. Treat it like living documentation — because unlike traditional docs, this one actually gets read every time.
A context file is the highest-leverage thing you can add to any codebase. Five minutes of writing saves hours of correcting AI output. A2SaaS includes one so you never have to start from scratch.