Skip to content
AI Agent & Markdown Files

Generate a CLAUDE.md for Your Repo That Claude Code Actually Follows

For when Claude Code keeps making the same mistakes in your repo even though the rule is right there in CLAUDE.md. Give it your real commands, the parts of the structure that aren't obvious from the code, and the mistakes you keep correcting. It writes a short CLAUDE.md of specific rules with the important ones first, lists what it cut and why, and flags the never-break rules that belong in a hook or linter config instead of a polite request.

Illustration for the AI prompt: Generate a CLAUDE.md for Your Repo That Claude Code Actually Follows
Chat promptAI Agent & Markdown FilesClaudeChatGPTGemini
The Prompt
You are a senior engineer who writes CLAUDE.md files for Claude Code. I want a CLAUDE.md for my repo that Claude Code actually follows. My last attempt either came from /init and filled up with things Claude could already read from the code, or it grew into a long wish list that Claude reads and then ignores: the same mistakes, the wrong test command, rules near the bottom skipped. I know CLAUDE.md is context, not enforced configuration, so I want a short file where every line earns its place, plus a clear list of the rules that should be hooks or linter config instead.

HARD RULES:
1. UNDISCOVERABLE AND UNIVERSAL ONLY. Include a line only if Claude could not work it out by reading the code AND it applies to most tasks in this repo. Cut directory tours, framework explanations, general best practices ("write clean code", "use meaningful names") and anything that is already in the README.
2. SHORT. Aim for under 60 lines and never go over 150. If my input would push it longer, move task-specific detail into separate files the CLAUDE.md points to, and tell me which ones.
3. SPECIFIC AND ACTIONABLE. Every rule is a direct instruction with a concrete command, path or name, for example "Run a single test with `pnpm vitest run <file>`", not "make sure tests pass". No vague words like "properly", "clean" or "where appropriate".
4. NEVER INVENT. Use only the commands, paths, tools and rules I give you. If something is missing or unclear, write [CONFIRM: ...] instead of guessing. Never fill a gap with the popular default for my stack.
5. MOST IMPORTANT FIRST. Commands and hard rules go near the top, not buried at line 300. State each hard rule once, plainly, with the reason in a few words. Save "NEVER" for the 3 to 5 rules that would cause real damage if broken; do not put every line in capitals.
6. LINTERS AND HOOKS DO THE ENFORCING. Formatting and style rules that a linter or formatter can enforce stay out of the file. Rules that must never be broken (for example never pushing to main, never editing generated files, never reading .env) get one line in the file AND a suggested hook or config in a separate section, because a rule in a prompt is a request and a hook is enforcement.
7. POINTERS, NOT COPIES. Point to files (for example "API conventions: see docs/api.md") instead of pasting their content. Do not use @imports to pull in long docs, because imported files still load into context every session.
8. NO CONFLICTS. If I mention subdirectory CLAUDE.md files, an AGENTS.md or existing rules, flag any rule that contradicts another. Personal preferences go in CLAUDE.local.md, not the shared file.

BEFORE WRITING, ask me these in one short batch and STOP:
1. What the project is in one sentence, plus the stack and versions (language, framework, package manager).
2. The exact commands for install, dev, build, test (full suite and a single test), lint or format, and typecheck. Pasting package.json scripts or a Makefile is fine.
3. The non-obvious parts of the structure: generated, legacy or shared folders, and places where code is easy to put in the wrong spot.
4. The mistakes Claude keeps making in this repo, in my own words. These are the most valuable input.
5. The rules that must never be broken, and which hooks, linters or formatters I already use.
6. Any existing CLAUDE.md, AGENTS.md, .cursorrules or /init output you should trim rather than start from scratch (I will paste it).

Then reply using exactly these sections:
CLAUDE.MD: the complete file inside one markdown code block, using these headings: # Project (1 to 2 lines), ## Commands, ## Architecture (only what is not obvious), ## Conventions (only what no linter enforces), ## Rules (the hard rules), ## Pointers (where deeper docs live). Leave out any section with nothing real in it.
LINE COUNT: the number of lines in the file.
MOVE TO HOOKS OR LINTERS: each never-break rule paired with the kind of hook or tool config that would enforce it, as a suggestion for me to verify, not a finished script.
CUT AND WHY: everything from my input you left out, one line each, with the reason (discoverable from code, linter's job, task-specific, README content, duplicate).
CONFIRM: every [CONFIRM] placeholder still in the file.
KEEP IT IN SYNC: 3 short triggers for when this file needs editing (for example a renamed script or a moved folder), and a reminder to start a fresh session or run /clear after editing it.

Plain text outside the code block, no intro, no pep talk.

Here are my details:
Project and stack: [FILL IN]
Commands: [PASTE SCRIPTS OR LIST]
Non-obvious structure: [FILL IN]
Mistakes Claude keeps making: [FILL IN]
Never-break rules and existing hooks or linters: [FILL IN]
Existing instruction file to trim: [PASTE OR "none"]

Start with the questions.
Open directly inChatGPTClaudeGemini

How to use this chat prompt

Paste it directly into a new chat, replace anything in [BRACKETS] with your context, and send. Re-use it whenever the task comes up, or save it as a text-expander snippet.

Example output

Next.js and pnpm monorepo with Vitest. Claude keeps running npm and editing the generated Prisma client. All six questions answered.

Plain ChatGPT answer

## Overview: This is a Next.js project using TypeScript and React.

## Best practices: Write clean, maintainable code and follow consistent naming.

## Testing: Always make sure all tests pass before committing.

With this prompt

CLAUDE.MD: ## Commands: `pnpm install`, `pnpm dev`, single test `pnpm vitest run <file>`. Use pnpm, never npm.

## Rules: NEVER edit packages/db/generated/. Change schema.prisma, then run `pnpm db:generate`.

LINE COUNT: 34

MOVE TO HOOKS OR LINTERS: block writes to packages/db/generated/ with a PreToolUse hook; import order goes to ESLint.

CUT AND WHY: folder tour (discoverable from code), "write clean code" (general advice).

CONFIRM: [CONFIRM: is the typecheck script `pnpm typecheck`?]

FAQ

Frequently asked questions

What should be in a CLAUDE.md file?

Only what Claude can't work out from the code and what applies to most tasks: the exact build, test and lint commands, the parts of the architecture that aren't obvious, and the handful of mistakes you keep correcting. Leave out directory tours, general best practices, style rules a linter already enforces and anything that's in your README. The prompt lists everything it cut and why, so you can see the trade-offs.

How long should a CLAUDE.md be?

Shorter than most people write. Common advice from developers who use Claude Code daily is under 300 lines and ideally much less, and the prompt aims for under 60 because every extra rule competes for attention with the ones that matter. If your details won't fit, it moves task-specific detail into separate docs the file points to.

Why does Claude Code ignore my CLAUDE.md?

Anthropic's documentation treats CLAUDE.md as context Claude reads, not configuration it is forced to obey, so a rule is a request rather than a guarantee. Long files, vague wording, rules buried near the bottom and contradictions between files all make it more likely a rule gets skipped. The prompt keeps the file short and specific, puts the hard rules first, and moves anything that must never happen into a suggested hook. If you edit the file mid-session, starting a fresh session (or running /clear) is the simplest way to make sure Claude is working from the new version.

Should I use /init or write CLAUDE.md myself?

/init is a quick starting point, but it builds the file by scanning your code, so a lot of what it writes tends to be things Claude could discover on its own. A practical approach is to run /init, paste its output into this prompt as the existing file to trim, and let it keep only the commands and rules that are both non-obvious and relevant to most tasks.

Where does CLAUDE.md go, and what about AGENTS.md?

Put the shared file in the root of your repo and commit it. Personal preferences can go in a CLAUDE.local.md that you keep out of git, and rules for one part of a monorepo can live in a CLAUDE.md inside that folder. AGENTS.md is a similar convention read by tools like Codex and Cursor; many teams keep one main file and point the other at it, and the prompt flags any rule that conflicts between them.

Keep going

What's next