If you use Claude Code to write, review, or refactor code, there is one small file you should not ignore: CLAUDE.md. This file works like a permanent project briefing, helping Claude understand how your codebase works before it starts suggesting or making changes.
The problem is that many teams either make their CLAUDE.md too long, too vague, or do not create one at all. As a result, Claude has to guess important details: which commands are safe to run, what coding standards to follow, how to run tests, and which parts of the project require extra caution.
This article focuses on a simple but powerful version: four lines that every CLAUDE.md should include. They are short, practical, and can make Claude’s output safer, more consistent, and better aligned with your project.
What Is CLAUDE.md?
CLAUDE.md is a special documentation file usually placed at the root of a repository. It contains instructions for Claude Code so the AI can understand the project context before helping you work with the codebase.
Think of CLAUDE.md as an onboarding document for your AI assistant. The difference is that it does not need to be long. In fact, the clearer and more concise it is, the easier it is for Claude to follow.
Main Functions of CLAUDE.md
- Explains how to run the project.
- Lists testing, linting, and build commands.
- Defines safety boundaries when the AI modifies code.
- Guides Claude to follow the existing coding style and patterns.
- Reduces the risk of incorrect assumptions.
Why CLAUDE.md Should Not Be Too Long
It is tempting to turn CLAUDE.md into a complete project manual. However, overly long instructions often make the context less useful. Claude may miss the most important rules because they are buried under too much information.
An effective CLAUDE.md usually has three qualities:
- Concise: it includes only instructions that directly affect how Claude should work.
- Specific: it clearly states commands, rules, and expectations.
- Actionable: it helps Claude make practical decisions while working with code.
For many projects, the following four lines are enough to create a strong foundation.
The 4 Lines Every CLAUDE.md Should Include
Here is a simple version you can adapt:
Follow the existing code style and project structure before adding new patterns. Run relevant tests, lint, and type checks after making changes. Do not run destructive commands or modify secrets without explicit approval. If requirements are unclear, ask before implementing major changes.
These four lines may look simple, but each one plays an important role. Let’s break them down.
1. Follow the Existing Code Style and Project Structure
The first line:
Follow the existing code style and project structure before adding new patterns.
This instruction prevents Claude from introducing new patterns that do not match the existing project. In software development, consistency is often more valuable than personal preference.
For example, if your project uses a specific folder structure, service-layer approach, naming convention, or component pattern, Claude should follow what already exists. Without this instruction, it may create a new structure that looks clean but does not fit the current architecture.
Benefits:
- New code becomes easier for the team to read.
- Duplicate patterns are reduced.
- The project architecture remains consistent.
- Code reviews become faster and smoother.
2. Run Tests, Lint, and Type Checks After Changes
The second line:
Run relevant tests, lint, and type checks after making changes.
Claude can generate code quickly, but fast code is not always correct code. That is why validation is important.
If your project has specific commands, include them directly in CLAUDE.md. For example:
npm run lint npm run test npm run typecheck
Or for a Python project:
ruff check . pytest mypy .
With instructions like these, Claude does not only make changes. It also helps verify whether those changes are safe and working as expected.
[Image Description: Developer running tests, lint, and type checks after making code changes]
[AI Image Prompt: A software developer reviewing automated test results in a terminal, green check marks, code editor in the background, modern AI-assisted development workflow, cinematic lighting]
3. Do Not Run Destructive Commands Without Approval
The third line:
Do not run destructive commands or modify secrets without explicit approval.
This is one of the most important instructions. Claude should not have unlimited freedom to run commands that can delete data, change sensitive configuration, or modify credentials.
Examples of actions that require explicit approval:
- Deleting large numbers of files or folders.
- Running commands such as
rm -rf. - Editing
.envfiles, tokens, API keys, or secrets. - Running risky database migrations.
- Force-resetting branches or rewriting Git history.
You can make this instruction even more specific:
Never run rm -rf, reset git history, edit .env files, or execute database migrations without asking first.
This keeps Claude productive while making sure it does not cross critical safety boundaries.
4. Ask First When Requirements Are Unclear
The fourth line:
If requirements are unclear, ask before implementing major changes.
One of the biggest risks when using AI for coding is assumption. When the instruction is unclear, Claude may jump straight into implementation. Sometimes the guess is correct, but often it leads to a solution that misses the real requirement.
This line encourages Claude to ask questions before making significant changes. The result is a safer and more collaborative workflow.
This instruction is especially useful for:
- Architecture changes.
- Large refactors.
- Changes to business logic.
- External API integrations.
- Database schema changes.
A More Complete CLAUDE.md Example
The four lines above are already a strong foundation. However, if you want something more practical, you can add project-specific details.
Here is a more complete CLAUDE.md example:
# CLAUDE.md Follow the existing code style and project structure before adding new patterns. Run relevant tests, lint, and type checks after making changes. Do not run destructive commands or modify secrets without explicit approval. If requirements are unclear, ask before implementing major changes. ## Common Commands Install dependencies: npm install Run development server: npm run dev Run lint: npm run lint Run tests: npm run test Run type check: npm run typecheck ## Project Notes - Prefer small, focused changes. - Reuse existing utilities before creating new ones. - Keep public APIs backward compatible unless instructed otherwise. - Update documentation when behavior changes.
This version is still concise, but it gives Claude enough direction. The AI knows how to work, how to validate its output, and which boundaries it must respect.
Tips for Writing an Effective CLAUDE.md
Use Specific Instructions
Avoid vague instructions like “write good code.” That kind of guidance is hard to execute because “good” can mean different things to different teams.
Use concrete instructions instead, such as:
- Use TypeScript strict mode.
- Do not add new dependencies without approval.
- Follow the existing component patterns in the
componentsfolder. - Run
npm run testbefore completing the task.
Do Not Copy Long Documentation
CLAUDE.md is not the place to store all project documentation. If your documentation already exists in README files, a wiki, or a docs folder, simply point Claude to those resources.
Example:
Read README.md and docs/architecture.md before changing core modules.
Update It When the Workflow Changes
An outdated CLAUDE.md can become a source of problems. If test commands change, the dependency manager is replaced, or the project structure is updated, make sure this file is updated as well.
Add Rules for Dependencies
Claude may sometimes suggest a new library to solve a small problem. In many projects, this is not ideal because it increases maintenance cost.
You can add this instruction:
Do not add new dependencies without explaining the reason and asking for approval.
Common Mistakes When Creating CLAUDE.md
- Making it too long: Claude may struggle to prioritize the main instructions.
- Being too abstract: vague rules do not help with technical decisions.
- Skipping important commands: Claude has to guess how to run or test the project.
- Ignoring safety boundaries: the risk of harmful changes increases.
- Not updating it: old instructions may conflict with the current project workflow.
Short CLAUDE.md Template
If you want to get started quickly, use this template:
# CLAUDE.md Follow the existing code style and project structure before adding new patterns. Run relevant tests, lint, and type checks after making changes. Do not run destructive commands or modify secrets without explicit approval. If requirements are unclear, ask before implementing major changes. ## Commands - Install: npm install - Dev: npm run dev - Lint: npm run lint - Test: npm run test - Type check: npm run typecheck ## Rules - Make small, focused changes. - Avoid new dependencies unless approved. - Update tests and documentation when needed. - Explain important trade-offs before large changes.
Adjust the command section based on your technology stack. For PHP, Python, Java, Go, or other frameworks, replace the commands with the workflow your team actually uses.
Conclusion
CLAUDE.md does not need to be long to be useful. In many cases, a short and clear file is more effective because it gives Claude the exact guidance and boundaries it needs.
The four essential lines are:
- Follow the existing code style and project structure.
- Run tests, lint, and type checks after making changes.
- Do not run destructive commands or modify secrets without permission.
- Ask first when requirements are unclear.
With these four instructions, Claude Code can work more safely, more consistently, and more closely aligned with your project standards. It is a small file with a big impact.