Generate AGENTS.md or CLAUDE.md From Your Repo
A prompt that makes your coding agent read the repo, ask only what it can't find out, run every command it plans to write down, and save a short, accurate AGENTS.md or CLAUDE.md.
Added
You are writing the rules file for this repository: AGENTS.md (and a CLAUDE.md that only contains @AGENTS.md, if I use Claude Code). The file must be short and every fact in it must be true for this repo today. ## Step 1: Read, don't guess Inspect the repo before writing anything: README, package/manifest files (package.json, pyproject.toml, Cargo.toml, go.mod, etc.), lockfiles, CI config, Makefile or task runner, existing rules files (.cursorrules, .cursor/rules, copilot-instructions.md, old CLAUDE.md), test folders, and a few representative source files. Write down what you found: language and framework versions, package manager (from the lockfile, not a guess), how tests, lint, typecheck, build, and dev server are run, folder layout, and any patterns repeated across files. ## Step 2: Ask me only what the repo can't tell you At most 5 questions, e.g. which folders are off-limits, what must never be changed without asking, deploy rules, which conventions are deliberate. If the repo answers it, don't ask. ## Step 3: Verify every command Run each command you plan to include (install, test, lint, typecheck, build). For each, record: the exact command, whether it passed, and how long it took. Only commands that ran correctly go in the file. List any that failed separately with the error, and don't paste them in as if they work. Never run deploy, publish, migration, or anything that touches production; ask me instead. ## Step 4: Write the file (under 40 lines) # [Project name] One sentence: what this is. ## Stack Only decisions an agent could get wrong (framework, package manager, data layer, test tool). ## Commands The verified commands, exactly as run. ## Layout 3 to 6 lines: where things live. ## Rules 3 to 6 rules that change behavior here, each concrete and checkable (e.g. "Run pnpm test:unit before saying done"). No generic advice like "write clean code". ## Ask first Things the agent must not do without asking. ## Step 5: Report - The file. - A table of commands: command, result, time. - What you left out and why (rules from old files that were outdated, duplicated, or untestable), so I can add anything back. - Old rules files that can now be deleted or turned into one-line pointers to AGENTS.md. Rules: no secrets or .env values in the file; if two sources disagree (README vs CI), trust what actually ran and tell me about the conflict.
How to use it
- Click Copy template.
- Paste into ChatGPT, Claude, Grok, Cursor, or your agent framework.
- Replace the [BRACKETED] parts with your details.
Pairs well with: AI Agent Harness Starter Pack: Rules, Hooks, Status & Verify
FAQ
Can an AI agent write its own CLAUDE.md or AGENTS.md?
Yes, and it's often the fastest way to get a good one, as long as it reads the repo first and runs each command it writes down. Unverified rules files are where wrong commands and outdated rules come from.
Why verify the commands?
Because the commands section is what the agent relies on most. A wrong test or build command means every later session wastes time or reports success without really checking.
How is this different from Claude Code's /init?
/init drafts a CLAUDE.md from the repo. This prompt adds a short question round, runs every command before saving it, keeps the file under 40 lines, writes AGENTS.md so other agents share it, and lists what it left out.
How long should AGENTS.md be?
Short. Codex, for example, only reads a limited amount of AGENTS.md text (32 KiB by default across all the files it combines), and long files bury the rules that matter. Aim for under 40 lines in the root file.
Get 3 new templates every week
Free. Unsubscribe anytime.Related templates
AGENTS.md Starter Template for Claude Code, Codex & Cursor
Lean CLAUDE.md: Trim a Bloated Rules File to 40 Lines
One Rules File for Claude Code, Codex, Cursor & Gemini
Rules File Drift Check: Is Your AGENTS.md Lying to the Agent?
This Codebase Is Yours: Ownership Rules for Coding Agents
Browse all Coding & Cursor Rules templates