Articles / AI-ready builds

How to Set Up CLAUDE.md for a Website Project

CLAUDE.md is a plain text file in your project that Claude Code reads at the start of every session. For a website, keep it short: what the site is, how it fits together, the commands, the rules and the changes that must stay in step. Back the rules that matter with permission settings and hooks, because CLAUDE.md guides Claude but does not enforce anything.

By ,

If you use Claude Code on a website, the single most useful file in your project is CLAUDE.md. It is a plain text file that Claude reads at the start of every session. Think of it as the briefing you would give a new developer on their first day: how the site works, where things live, what to check and what not to touch.

This guide shows what to put in one, with a real-world example and the settings that turn rules into locks.

Where it goes

Put CLAUDE.md in the root of your project, next to package.json. Claude Code also reads .claude/CLAUDE.md, and a CLAUDE.local.md for personal notes you don't want to share. Commit the main file to Git so everyone, and every AI session, gets the same rules.

What to put in it

Keep it short and specific. A file that is too long gets skimmed, by people and by AI. These sections cover almost every website:

  1. What the site is. One or two lines: the framework, the CMS, the hosting.
  2. How it fits together. Where pages, components, styles and content live.
  3. Commands. How to run it, build it and check it.
  4. Rules. The things that must never happen.
  5. Keep in step. Changes that need a matching change somewhere else.

A real example

This is a trimmed version of the kind of CLAUDE.md we hand over with every site:

CLAUDE.md
# Acme website

Astro site, static output, hosted on Cloudflare. Content in Sanity (Studio in studio/).

## How it fits together
- Pages: src/pages. Every page uses src/layouts/Base.astro.
- Sections are components in src/components. Reuse them before making new ones.
- All words come from Sanity. Small interface words (buttons, menu) are in
  Site settings > Labels. Never hard-code text in a template.
- Styles: src/styles/global.css only. Use the existing classes and variables.

## Commands
- npm run dev: local site
- npm run build: builds the site, checks every internal link and page title

## Rules
- Never change a page address (slug). If one must change, add a redirect.
- Never edit public/_redirects. Redirects are managed in Site settings.
- Never commit secrets. Keys live in Cloudflare and GitHub secrets.
- Ask before adding a dependency.
- Plain, short copy. No em dashes.

## Keep in step
- New page route: add it to the sitemap check in scripts/check-links.mjs.
- New Sanity field the code compares or splits: add it to NO_MARKERS in src/lib/sanity.ts.

Notice what it does not include: long explanations of Astro, generic coding advice or anything Claude already knows. Every line is specific to this site.

Rules guide, settings enforce

This is the part most people miss. CLAUDE.md shapes what Claude tries to do, but it does not change what Claude Code allows. If something must never happen, put it in the settings file as well. Claude Code enforces those rules itself.

.claude/settings.json
{
  "permissions": {
    "allow": [
      "Bash(npm run dev)",
      "Bash(npm run build)"
    ],
    "deny": [
      "Read(./.env)",
      "Read(./.env.*)",
      "Edit(./public/_redirects)",
      "Bash(npx wrangler deploy *)",
      "Bash(git push --force *)"
    ]
  }
}
  • allow lets Claude run safe commands without asking each time.
  • ask makes it check with you first.
  • deny blocks the action completely.

Hooks for anything a rule can't express

A hook is a small script Claude Code runs before or after an action. A PreToolUse hook runs before every edit, can look at which file is about to change and can block it. Exiting with code 2 stops the edit and passes your message back to Claude, so it knows why.

.claude/settings.json
{
  "hooks": {
    "PreToolUse": [
      {
        "matcher": "Edit|Write",
        "hooks": [{ "type": "command", "command": "node .claude/hooks/protect.mjs" }]
      }
    ]
  }
}
.claude/hooks/protect.mjs
// Blocks edits to files that should only change on purpose.
const PROTECTED = ['public/_redirects', 'src/styles/tokens.css', 'wrangler.jsonc'];

let input = '';
process.stdin.on('data', (chunk) => (input += chunk));
process.stdin.on('end', () => {
  const file = JSON.parse(input).tool_input?.file_path || '';
  const hit = PROTECTED.find((p) => file.endsWith(p));
  if (hit) {
    console.error(`${hit} is protected. Explain the change and ask a person to make it.`);
    process.exit(2);
  }
});

Mistakes we see

  • Writing a manual. Five hundred lines of general advice. Keep it to what is specific to the site.
  • Rules with no lock. "Never deploy" in CLAUDE.md, but nothing in the settings stopping it.
  • Letting it go stale. When the site changes, update the file in the same commit.
  • Secrets in the file. CLAUDE.md is committed to Git. Never put keys, passwords or private links in it.
  • No checks to run. If there is no build check, Claude can't prove its change works. Give it one.

Keep it alive

Treat CLAUDE.md like code. When Claude makes a mistake twice, add a line that prevents it. When a rule no longer applies, delete it. A good file gets better every month, and so does every session that reads it.

Want this set up for your site, with the locks and checks already in place? That is part of every AI-ready website we build. Read the AI-ready website guide for the bigger picture.

  • What is CLAUDE.md?

    A plain text file in your project that Claude Code reads at the start of every session. It explains how the project works and what the rules are.

  • Where does CLAUDE.md go?

    In the root of your project, or in .claude/CLAUDE.md. Commit it to Git so every session gets the same rules. Personal notes can go in CLAUDE.local.md.

  • Does CLAUDE.md stop Claude from doing things?

    No. It guides what Claude tries to do. To block an action, add a deny rule in .claude/settings.json or a PreToolUse hook, which Claude Code enforces itself.

  • How long should CLAUDE.md be?

    As short as possible while staying specific to your site. A page or two is plenty for most websites.

  • Should I put API keys in CLAUDE.md?

    Never. It is committed to Git. Keep secrets in your hosting provider and GitHub secrets, and deny reading .env files in the settings.

Rather have us do it?

Send a few lines about it. Mark replies within 48 hours to set up a free call and a fixed quote.

Book a free call