VibecodingThe build loopLevel 2: Context

How Do You Give AI Rules It Follows Every Time?

Put your standing instructions in the file or settings your tool reads at the start of each session. That means CLAUDE.md in Claude Code, .cursor/rules or AGENTS.md in Cursor, Instructions in Lovable and v0. Keep it short, and cover what the AI can't work out from your code. For rules that truly can't be broken, use a technical block as well.

Prompt to copy
Write a rules file for this project, for [CLAUDE.md / AGENTS.md / Lovable Project instructions]. Read the project first. Keep it under 60 lines. Include only what you couldn't work out from the code.

Use these sections:

WHAT THIS APP IS: two sentences, who uses it, and what's out of scope.
STACK: framework, database, hosting, and a rule to ask before adding any package.
COMMANDS: how to run the app and the tests. Run the tests before saying work is done.
SECURITY RULES:
- Never put a secret in browser code. Don't use the NEXT_PUBLIC_ or VITE_ prefix for one.
- Every new table gets row level security and a policy in the same migration.
- Never disable row level security or use using (true) on private data to fix an error.
- Take the user's ID from the verified token, never from the request.
- Never read or print .env files.
- Database changes go in migration files, and you ask me first.
HOW TO WORK WITH ME: I'm not a developer. Explain choices in plain language. Make one change at a time. If you can't verify something, say so.

Show me the draft before saving it.
  1. A message in chatGone when the next session starts
  2. A rules fileRead each session, but context, not enforcement
  3. A deny ruleBlocks Claude Code's file tools from a file
  4. A PreToolUse hookCan block an action whatever Claude decides
Rule of thumb for the order, not a vendor ranking, using Claude Code's features as the example. Each rung down the list holds more firmly.
  • Under 200lines per CLAUDE.mdAnthropic's target for Claude Code
  • Under 500lines per ruleCursor's suggestion
  • 10,000characters per fieldLovable's Instructions limit
Sources: Claude Code, Cursor and Lovable docs, checked November 6, 2026. The units differ, so don't compare them directly.

Try it now

  1. 1In Claude Code, run /init, then paste the prompt above to tighten the result. In other tools, paste the prompt and save the result in the location listed above.
  2. 2Start a new session and ask: "What are this project's security rules, and what's out of scope?"
  3. 3Then ask for something that breaks a rule, such as "Put my API key in a VITE_ variable". It worked if the tool pushes back. If not, make the rule more specific or use a block like the one below.

Use it when

As soon as you've corrected the AI on the same thing twice. Anthropic's guide lists this as a sign that something belongs in the file. Add one early for your stack, your test command and your security rules.

Skip it when

Don't write rules for things the AI already does correctly, or copy a long template from the internet. Each line takes up context in every session, and a long file makes the important lines easier to miss. Put a one-off instruction in the prompt instead.

Why it works

Each session starts fresh, as Anthropic's docs put it, so anything you explained yesterday is gone unless it's written down. Details differ by tool:

  • Claude Code: reads CLAUDE.md, and can read AGENTS.md instead. /init drafts one. Target under 200 lines.
  • Cursor: project rules in .cursor/rules must use the .mdc extension, since plain .md files there are ignored. It also reads AGENTS.md. Keep rules under 500 lines.
  • Lovable: Project settings → Instructions, 10,000 characters per field. It also reads a top-level AGENTS.md or CLAUDE.md with every message.
  • v0: the + button in the prompt bar, then New Instruction. Checked instructions stay applied until you uncheck them.
  • Devin Desktop: .devin/rules/*.md and AGENTS.md, with .windsurf/rules still read as a legacy location.

Rule files guide the AI, but they don't force it. Anthropic says CLAUDE.md is context rather than enforced configuration, and that longer files reduce how well they're followed.

Example

You keep having to tell Cursor to use Supabase Auth rather than adding a new sign-in library. So you add one line to AGENTS.md: "Sign-in uses Supabase Auth. Don't add another auth library."

A second line stops a costly habit: "When a query returns nothing after row level security is on, a policy is missing. Add the policy. Never disable row level security." That rule exists because of a specific mistake, which is what makes it useful. A line like "write clean code" doesn't tell the AI anything it can act on.

Going further

For anything that must never happen, use enforcement rather than instructions. In Claude Code, a deny rule such as Read(./.env) blocks its file tools from reading that file, and a PreToolUse hook can block an action whatever Claude decides. Your secret files should also be out of Git, since a rule can't protect a value already in history.

If you use several tools, keep one shared file. Cursor, Lovable, Claude Code and Devin Desktop can all read AGENTS.md, so you don't need to maintain four copies. Rules can also apply to part of a project: Claude Code has path-scoped rules in .claude/rules/, and Cursor can apply a rule only to matching files, such as src/components/**/*.tsx.

Review the file now and then. Delete rules that no longer apply, and any your tests or settings now enforce.

Common mistakes

  • Saving Cursor rules as .md in .cursor/rules. Cursor's docs say they need .mdc, so plain Markdown files there are ignored.
  • Writing vague rules such as "be secure". Name the exact behavior you want, and what to do instead.
  • Treating a rule as a guarantee. Claude Code's docs say it's context, so test important rules and enforce them with deny rules or hooks.
  • Pasting secrets or real customer data into a rules file. These files usually get committed to Git, and they're sent with your prompts.

Sources

Checked 6 November 2026. Products change often, so confirm details with the vendor.

Related

Beyond the course