CLAUDE.md best practices (with my template)

Write clearer Claude Code project instructions with practical best practices, a downloadable CLAUDE.md template, and a workflow for testing your rules.

CLAUDE.md project instruction sheet with planning diagrams and a pencil on a light drafting table

A useful CLAUDE.md tells Claude Code what matters in your repository: where the code lives, which commands work, what must stay unchanged, and how to verify a result. Keep it specific to the project and easy to maintain. The template below gives you a starting point for website and application work without assuming that every repository uses the same stack.

These CLAUDE.md best practices focus on making instructions testable. A longer file is not automatically a better one, and a well-written file does not replace code review or access controls.

What is CLAUDE.md?

CLAUDE.md is a Markdown file containing persistent instructions for Claude Code. Project-level instructions can live at the repository root or in the .claude directory. Personal instructions and automatic memory have different scopes, so keep shared project guidance separate from individual preferences. Anthropic explains the locations and loading behaviour in its project memory documentation.

If you have not set up the tool yet, start with my Claude Code installation guide. Return here once you can open a session in your repository.

1. Describe the project before prescribing behaviour

Start with a short explanation of what the repository contains. A useful project map identifies the frontend, CMS, backend, and generated output where those exist. Include exact paths only after checking them.

For example, a repository might contain an Astro website at its root and a separate Sanity Studio in a studio directory. That distinction helps prevent a change from being made in the wrong application. A generic instruction such as �follow our architecture� does not communicate it.

My recommendation is to write this section for a developer joining the project tomorrow. Include the facts they would need to find the correct implementation, rather than a complete inventory of every folder.

2. Give verified commands and working directories

A command is useful only if it exists and runs from the stated location. Inspect package scripts, project documentation, and any workspace configuration before adding installation, preview, testing, or build instructions.

Do not invent a test command to make the file look complete. If the project has no automated tests, explain the available checks and any manual verification required. On a multi-application repository, list the working directory for each command.

Anthropic's Claude Code best-practices guide recommends supplying verification criteria and useful project context. Turn that into concrete acceptance checks for your own codebase: which command should pass, which page should render, or which user flow should work?

3. State the boundaries that matter to the client

For an established website, �update this content� should not become a redesign. Write down the relevant boundaries: preserve existing typography, navigation, responsive behaviour, and unrelated sections unless the task asks to change them.

Make exceptions understandable. If a requested feature genuinely requires a schema change, the file should not forbid all schema work. Ask for the reason and scope to be explained instead of creating contradictory blanket rules.

The same applies to delivery. Preparing a local patch, publishing CMS content, and deploying a site are different actions. State how your team authorises each one so the final report can distinguish completed work from work awaiting release.

4. Keep instructions concise and consistent

Anthropic recommends keeping individual CLAUDE.md files below roughly 200 lines and removing contradictory instructions. More specialised guidance can use scoped rules. Imported files still consume context, so splitting text into imports does not make that information free to load. See the instruction-writing guidance.

My editing rule is simple: keep a sentence if it prevents a likely mistake or identifies a decision that is not obvious from the code. Remove stale workarounds, repeated advice, and instructions that no longer match the repository.

Review the file whenever a build command, directory structure, or release process changes. Treat it as maintained project documentation, not a prompt you write once and forget.

5. Do not use prose as a security boundary

CLAUDE.md guides the model; it is not enforced configuration. Anthropic explicitly distinguishes contextual instructions from mechanisms that block actions in its memory documentation.

Keep secrets out of the file. Use the permissions and environment controls appropriate to your development setup, and give accounts only the access they need. An instruction to avoid production writes is useful guidance, but it should not be the only thing protecting production data.

For a client project, I recommend documenting where configuration belongs without including credential values. Describe an environment variable by name and purpose, and keep the actual value in the approved secret store.

My CLAUDE.md starter template

This is a proposed starter template for adapting to your own repository, not a claim that one file fits every project. Replace every bracketed placeholder, remove irrelevant entries, and verify the commands before saving it as CLAUDE.md.

Download the Markdown template, or copy the version below.

# Project instructions

## Project context
- Project: [name and purpose]
- Stack: [framework, language, CMS, runtime]
- Repository map: [important paths and their responsibilities]

## Scope
- Implement the requested change using existing conventions.
- Preserve unrelated layouts, routes, content, and interactions.
- Explain any necessary dependency or architecture change before making it.

## Commands
- Install dependencies: [verified command]
- Start local preview: [verified command]
- Type/lint checks: [verified command]
- Tests: [verified command, or explain that none exist]
- Production build: [verified command]
- Run commands from: [directory]

## Content and configuration
- Content source: [CMS, local files, or database]
- Generated files: [paths and regeneration commands]
- Keep credentials in the approved secret store or ignored environment files.
- Never print secrets or include them in commits or examples.

## Verification
- Read the relevant implementation before editing.
- Run checks appropriate to the change and report their results accurately.
- For visual changes, inspect desktop and mobile rendering.
- For forms, verify success, validation, and failure paths.
- Distinguish local results from deployed behavior.

## Delivery
- Summarise what changed, why, and how it was verified.
- Mention unresolved failures or assumptions.
- Commit, push, publish, or deploy only when the task authorises it.

How to test your instructions

Start with a read-only orientation task

Open a fresh session and ask Claude to explain the project structure, identify the build command, and describe how it would verify a small content edit. Compare the response with the actual files. If it points to a nonexistent directory or an incorrect script, fix the instructions before asking for implementation.

Try one bounded change

Use a branch and choose a small task, such as changing a page heading or fixing a navigation state. Record the expected result first. Check whether the resulting diff stays within the task, and inspect the rendered page as well as the reported command output.

Improve the rule that failed

If a mistake recurs, identify the missing decision rather than adding a vague warning. Replace �be careful with generated files� with their actual paths and regeneration process. Replace �check everything� with the relevant validation commands and browser checks.

This is a practical evaluation workflow, not a guarantee of perfect compliance. Keep reviewing the code even when earlier tasks went well.

Common mistakes to avoid

Copying another project's commands unchanged

A template can organise information, but it cannot know your scripts or deployment process. A plausible command that does not exist wastes time and makes completion reports unreliable.

Filling the file with temporary task details

Keep a one-off bug description in the task or issue. Reserve shared instructions for durable conventions. Otherwise, the next unrelated task may inherit outdated assumptions about what should be changed.

Claiming production success after a local build

A local build does not establish that deployment finished, that the correct environment variables are present, or that an external integration works. Ask for evidence that matches the claim. For a content change, verify the affected rendered page in the environment that matters.

Conclusion: make the next correct action clear

The most useful CLAUDE.md best practices are concrete: describe the repository, provide verified commands, define boundaries, and explain how completion is checked. Adapt the template to your project and revise it when reality changes.

If you need help setting up a workflow for your team, explore my Claude Code development and consulting service. You can also contact me with the repository structure and the problems you want the workflow to prevent.

What I would do in a real project

I prefer a small, well-tested implementation that solves the client’s actual workflow. The technology matters, but clear ownership, publishing checks, and a maintainable handover matter more than a fashionable stack.

Common questions

How should I start evaluating this approach?

Start with one representative page or workflow, use realistic content, and test the full path from editing or development through the public visitor experience.

Is this approach right for every project?

No. Compare it with the simplest setup that meets the requirements, including the team’s editing needs, integrations, hosting, and ongoing maintenance.

What should I test before launch?

Test mobile layouts, error states, performance, accessibility, metadata, forms or checkout flows, publishing, and recovery from a failed build or integration.

When should I bring in a developer?

Bring in help when the content model, integrations, migration, testing, or deployment process has risks that the current team cannot confidently own.

Put the idea into practice

Need help applying this to a real project? Share your goals, current setup, and the workflow you need to improve.

Discuss your project ↗

Let’s connect

Currently open to collaborations

info@awais-javed.com

Open email ↗

Choose your mail app or copy the address.