You told the AI on Monday that the app uses Supabase, that prices are stored in cents, and that it must never touch the payments file. On Wednesday it suggests a new database, writes prices as decimals and edits the payments file anyway.
Nothing is broken. Each new chat starts with no memory of the last one unless you give the tool a place to read your rules from. That place is a context file: AGENTS.md, CLAUDE.md, a Cursor rule, or Lovable’s Instructions. This guide explains which tool reads which file, how to keep a single source of truth, what belongs in it, and what must stay out. It ends with a starter file you can copy. Tool-specific help: /fix/cursor, /fix/claude and /fix/lovable.
Why the AI forgets your project
The model behind these tools does not keep anything between conversations. Cursor’s docs say so directly and describe rules as the way to put the same context back at the start of every request (Cursor: Rules). Claude Code works the same way: every session opens with an empty context window, and CLAUDE.md files plus Claude’s own auto memory are what carry knowledge forward (Claude Code: memory).
Lovable adds a memory of its own on top of your written instructions. When you send a message, it reads your instructions, your code, instruction files in the repository, and the project facts and personal preferences it has saved (Lovable: Instructions).
Memory features are useful, but you don’t control exactly what they keep. A context file is the part you write, review and version yourself.
Which file each tool reads
These were checked against each tool’s docs on 26 Nov 2026. The tools change fast, so recheck the linked page if something doesn’t behave as described.
| Tool | Where your rules go | Notes |
|---|---|---|
| Cursor | .cursor/rules/*.mdc, or a root-level AGENTS.md (nested ones in subfolders work too) | A plain .md file inside .cursor/rules is ignored. There are also User Rules (all your projects) and Team Rules on Team and Enterprise plans (Cursor: Rules) |
| Claude Code | CLAUDE.md or .claude/CLAUDE.md in the project; ~/.claude/CLAUDE.md for all your projects; CLAUDE.local.md for private notes | Falls back to AGENTS.md when neither CLAUDE.md nor CLAUDE.local.md exists (v2.1.277 or later) (Claude Code: memory) |
| Lovable | Workspace, project and personal Instructions fields, plus instruction files in the repository | Instructions were called Knowledge before. A top-level AGENTS.md or CLAUDE.md is read with every message (Lovable: Instructions) |
| Other agents | AGENTS.md | The AGENTS.md site lists GitHub Copilot’s coding agent, Windsurf, Gemini CLI, Zed and others as compatible (AGENTS.md) |
Cursor: when a project rule applies
Each .mdc rule has a small frontmatter block with description, globs and alwaysApply. Those three fields decide when the rule is used. In the Cursor UI, the type dropdown labels them Always Apply, Apply to Specific Files, Apply Intelligently and Apply Manually (Cursor: Rules):
alwaysApply: true(Always Apply): included in every chat.globsset (Apply to Specific Files): attached when a matching file, such assrc/components/**/*.tsx, is in context.- Only
descriptionset (Apply Intelligently): the Agent reads the description and decides whether the rule is relevant. - None of them (Apply Manually): applied only if you @-mention it in chat.
You can type /create-rule in the Agent chat and describe the rule, and Cursor writes the file with the frontmatter filled in. A file you mention inside a rule, such as @migration-template.sql, is not pasted into the prompt. The Agent opens it when it needs it, so anything that must always be seen belongs in the rule body itself (Cursor: Rules). Rules don’t affect Cursor Tab completions.
Claude Code: CLAUDE.md first, AGENTS.md as a fallback
By default Claude Code looks for CLAUDE.md first. If it finds one (including CLAUDE.local.md) in the working folder or any folder above it, it skips AGENTS.md. That has a side effect: if your shared rules sit in AGENTS.md and you add a private CLAUDE.local.md, Claude no longer loads the shared rules. You can change this under /config with the Project instructions setting, for example to claude-md-and-agents-md to load both. To check what loaded, run /context all and look under Memory files (Claude Code: memory).
Lovable: fields plus repository files
Lovable has three plain-text fields, each up to 10,000 characters:
- Workspace instructions (owners and admins only): shared rules for every project in the workspace.
- Project instructions (anyone who can edit the project): the app’s purpose, key tables, architecture decisions.
- Personal instructions: your own preferences, visible only to you.
When they conflict, Lovable says it generally favours personal instructions first, then project, then workspace. On each message it also reads a root-level AGENTS.md and CLAUDE.md, and a nested file like src/components/AGENTS.md whenever it works on code in that folder (Lovable: Instructions).
One detail to know: on paid plans, Lovable may rewrite or delete a rule in AGENTS.md that no longer matches the code, unless you asked for that rule. Read the diff when that file changes.
One shared file or several?
If you use more than one tool, keep one source of truth so the rules can’t drift apart:
- Put the rules in
AGENTS.mdat the project root. Cursor, Lovable and Claude Code can all read it, as can the other agents listed on the AGENTS.md site. - For Claude Code, either have no
CLAUDE.mdat all, or makeCLAUDE.mda one-line file that imports the shared one:
@AGENTS.md
Claude’s docs suggest this import for sessions where AGENTS.md can’t be read directly. An imported file still counts toward the context Claude loads, so it doesn’t make a long file cheaper (Claude Code: memory).
- In Lovable, keep the Project instructions field short and point it at the same rules, or leave it for things that only matter inside Lovable, such as design guidelines. Lovable reads the repository file either way.
- Use Cursor
.mdcrules only for rules that should apply to some files and not others, such as component conventions undersrc/components/.
For a large project, nested files help. A second AGENTS.md inside a subfolder adds rules for that part of the code. The AGENTS.md site says the closest file to the edited code wins, and Cursor combines nested files with their parents, with the more specific one taking priority (AGENTS.md; Cursor: Rules).
What to put in
Write it as if you were onboarding a new developer who has never seen the project. Lovable’s own advice is the same: explain the architecture decisions so the AI doesn’t try to undo them (Lovable: Instructions).
- Purpose, in two lines. What the app does and who uses it.
- Stack. Framework, database, auth provider, hosting, payment provider.
- Commands. How to install, run, test and build. If you list a test command, agents that support AGENTS.md will try to run it and fix failures before they finish (AGENTS.md).
- Folder map. Where pages, components, API code, database migrations and environment files live.
- Conventions you actually enforce. Money in integer cents, named exports, the one state library you use.
- Domain words. What “order”, “member” or “credit” means in your app.
Make each line checkable. Claude’s docs give the contrast between “Use 2-space indentation” and “Format code properly” (Claude Code: memory). If you can’t tell whether the AI followed a rule, rewrite it until you can.
Rules that prevent expensive mistakes
These are the rules worth adding first, because each one maps to a failure we’ve written a full guide on:
- Don’t disable Row Level Security. “Never turn off RLS or drop a policy to make an error go away. Show me the policy and explain what it blocks.” See Supabase RLS policies explained.
- Keep secrets out of client code. “Never put the Supabase service_role key, Stripe secret key or any private API key in frontend code or in a file that gets committed.” If one already leaked, follow what to do when an API key leaks.
- Don’t touch environment files. “Do not create, edit or print
.envfiles. Ask me to change environment variables myself.” - Don’t rewrite working files. “Change only the files the task needs. Ask before deleting or rewriting a file over 50 lines.” Pair this with git so you can roll back: see how to undo AI agent changes.
- No destructive database commands without asking. “Never run DROP, TRUNCATE, a reset or a migration against production. Show me the SQL first.” Why this matters: when an AI agent deletes your database.
- Say when it’s unsure. “If you can’t confirm how something works, read the file or ask. Don’t guess.”
A rule is a request, not a lock
Every one of these tools treats your file as guidance. Claude’s docs state plainly that CLAUDE.md is context and not enforced configuration, and that a hook can stop an action whatever the model chooses (Claude Code: memory; Claude Code: best practices). Cursor’s docs warn that AI guidance shouldn’t be the only security control, even for enforced Team Rules (Cursor: Rules).
So back each rule with a real control. RLS on every table protects data even if the AI writes a bad query. Secrets stored in your host’s or Supabase’s secret settings can’t be pasted into a component. Commits before every big change let you undo. The context file makes mistakes less likely; the controls limit the damage when one still happens. The security checklist for vibe-coded apps lists the controls to check.
What to keep out
- Secrets. No keys, passwords, connection strings or tokens. Project files like
AGENTS.mdandCLAUDE.mdare meant to be committed and shared through version control (Claude Code: memory), so anything in them is readable by everyone with access to the repository, and by everyone if the repository is public. Write “the Stripe secret key lives in the host’s environment variables” instead. - Long histories. A changelog of every bug you fixed fills the context and buries the rules. Claude’s docs suggest staying below 200 lines in each
CLAUDE.mdbecause longer files cost more context and are followed less reliably. Cursor suggests keeping a rule under 500 lines and splitting large ones (Claude Code: memory; Cursor: Rules). - Vague wishes. “Write clean, scalable code” gives the AI nothing to check. Lovable’s docs use “Write clean code” as their example of a less useful instruction (Lovable: Instructions).
- Whole style guides and copied code. Cursor recommends a linter for formatting rules and pointing at an example file rather than pasting it (Cursor: Rules).
- Rules that contradict each other. If two lines disagree, Claude may follow either one (Claude Code: memory). Check nested files and tool-specific rules against the main file.
A starter template to copy
Save this as a root-level AGENTS.md and replace everything in angle brackets. Delete any line that isn’t true for your app. A wrong rule is worse than no rule.
# AGENTS.md
## What this app is
<One or two sentences: what it does and who uses it.>
## Stack
- Frontend: <React + Vite / Next.js / ...>
- Backend and database: <Supabase (Postgres, Auth, Storage) / ...>
- Payments: <Stripe / none>
- Hosting: <Vercel / Netlify / Lovable publish / ...>
## Commands
- Install: <npm install>
- Run locally: <npm run dev>
- Test: <npm test>
- Build: <npm run build>
Run the test and build commands before saying a task is done.
## Where things live
- Pages: <src/pages/>
- Components: <src/components/>
- Supabase client and queries: <src/lib/supabase.ts>
- Database migrations: <supabase/migrations/>
- Environment variables: set in <host dashboard>; never in code
## Conventions
- <Store money as integer cents.>
- <Use the existing UI components in src/components/ui before adding a library.>
- <Dates are stored in UTC.>
## Guard rails (do not break these)
- Never disable Row Level Security or drop a policy. If a query fails
because of RLS, show me the policy and explain the fix.
- Never put the service_role key or any secret key in frontend code,
in this file, or in any committed file.
- Do not create, edit or print .env files. Ask me to change them.
- Change only the files the task needs. Ask before deleting a file or
rewriting more than about 50 lines of working code.
- Never run DROP, TRUNCATE, a database reset or a migration against
production. Show me the SQL first.
- Do not add a new dependency without saying why.
- If you are not sure how something works, read the code or ask.
Do not guess.
## Words used in this app
- <"Member": a paying user with an active subscription.>
If you use Claude Code, add a CLAUDE.md that contains only @AGENTS.md. In Cursor, the file works as it is. In Lovable, it is read with every message once it’s in the project.
You can also let the tool draft the first version and then edit it. Claude Code’s /init command scans the codebase and writes a starting CLAUDE.md with the build commands and conventions it finds (Claude Code: memory). Check every line it writes against what the project really does, then add the guard rails yourself. A scan of the code can’t tell what you never want changed.
Keep it alive
A context file that describes last month’s app steers the AI the wrong way. A few habits keep it accurate:
- Add a rule the second time you correct the same thing. Claude’s and Cursor’s docs give the same trigger: a repeated mistake is the signal to write a rule (Claude Code: memory; Cursor: Rules).
- Update it when the stack changes. Moved from Lovable Cloud to your own Supabase, or swapped the payment provider? Change the Stack and Where things live sections the same day.
- Review what the AI writes into it. Lovable can edit
AGENTS.mdon paid plans, and any agent can edit a file you ask it to. Treat changes to the context file like code changes and read the diff. - Audit it. In Claude Code v2.1.283 or later,
/doctor prompt-auditlooks for outdated instructions, missing files and contradictions, and proposes edits without applying them (Claude Code: memory).
Rules shape what the AI builds next. They don’t check what’s already there. If the project grew for weeks before it had any rules, it may already have open tables, keys in the frontend or duplicated logic, and the vibe coding cleanup guide covers how to find them. If you’d rather have a senior engineer review the codebase you already have, start at /fix/cursor, /fix/claude or /fix/lovable.
FAQ
Do I need both AGENTS.md and CLAUDE.md?
No. One AGENTS.md covers Cursor, Lovable and the agents listed on the AGENTS.md site, and Claude Code v2.1.277 or later reads it when there’s no CLAUDE.md or CLAUDE.local.md. Add a CLAUDE.md only if you want Claude-specific rules, and have it import @AGENTS.md so the shared rules still load (Claude Code: memory).
Where do Cursor rules live now?
Project rules are .mdc files in .cursor/rules, and you can organise them in subfolders. A plain .md file there is ignored because it has no frontmatter. If you’d rather write plain Markdown, use an AGENTS.md at the root or in a subfolder (Cursor: Rules).
Can I paste secrets in the context file?
No. These files are committed with your code and read into every AI request. Put secrets in your host’s environment variables or your backend’s secret settings, and name only where they live. If a key has already gone into a committed file, rotate it: what to do when an API key leaks.
How long should the file be?
As short as it can be while still true. Claude’s docs aim for fewer than 200 lines in each CLAUDE.md, Cursor suggests under 500 lines per rule, and each Lovable Instructions field holds up to 10,000 characters (Claude Code: memory; Cursor: Rules; Lovable: Instructions). If it grows past that, move rules for one area into a nested AGENTS.md or a scoped Cursor rule.
Does Lovable read these files?
Yes. Lovable loads a root-level AGENTS.md or CLAUDE.md on each message, and a subfolder’s file when it works in that folder. It also reads its own Instructions fields and its saved memory of the project (Lovable: Instructions).
Comments