Where does each tool read rules from?
These are the locations in the vendors' documentation as of 29 November 2026.
| Tool | File | Format | When it loads |
|---|---|---|---|
| Cursor | .cursor/rules/*.mdc | Markdown with description, globs and alwaysApply frontmatter | Always, when a matching file is in context, when the agent judges it relevant, or when you @-mention it |
| Cursor | AGENTS.md, CLAUDE.md | Plain Markdown | AGENTS.md in the root and subfolders; CLAUDE.md is applied to every conversation |
| Claude Code | ./CLAUDE.md or ./.claude/CLAUDE.md | Plain Markdown, with @path imports | Every session |
| Claude Code | .claude/rules/*.md | Markdown, optional paths frontmatter | Every session, or only when Claude works with matching files |
| Claude Code | AGENTS.md | Plain Markdown | Read directly from v2.1.277, but by default only when there is no CLAUDE.md |
Sources: Cursor rules, Cursor help on rules, Claude Code memory.
Three details trip people up:
- A
.mdfile in.cursor/rulesdoes nothing. Cursor's docs: "Project rules must use the.mdcextension. A plain.mdfile in.cursor/rulesis ignored by the rules system." .cursorrulesis on its way out. Cursor calls the root file "legacy and will be deprecated".- Cursor rules apply to Agent (Chat) only. "They do not apply to Tab completion or Bugbot PR reviews." Code you accept from Tab never saw them.
How should I set it up for both tools?
One shared file and one pointer:
- Write the rules in
AGENTS.mdat the repository root. Cursor reads it directly, and so do other agents that follow the AGENTS.md format. - Create
CLAUDE.mdwith@AGENTS.mdon its first line. Claude Code expands imports, up to four hops deep.
Why import instead of relying on Claude Code reading AGENTS.md by itself? Its docs say that by default it reads AGENTS.md "only when you have no CLAUDE.md", and a CLAUDE.local.md counts too. The day someone adds one, the security rules would silently stop loading. The import survives that.
The rules to paste
Copy this into AGENTS.md and delete the lines for parts of the stack you do not use.
## Security rules
If a request conflicts with a rule below, stop and name the rule. Do not work around it.
### Who is calling
- Every API route, server action and edge function gets the user from the verified session on the server. Never from the request body, query string or a header the client sets.
- Every read or change of a user's record checks, on the server, that the record belongs to that user or that their role allows it.
- New routes require sign-in. A public route gets a comment saying why it is public.
### Database
- Every new table enables row level security in the same migration, with separate select, insert, update and delete policies.
- No policy on user data uses `true`, or checks only that someone is signed in.
- Users never write their own role, plan, credits, price, org_id or is_admin. Only server code or a verified webhook changes these.
- Views over protected tables use `security_invoker = true`.
- Every `security definer` function sets `search_path = ''` and checks `auth.uid()` itself.
### Secrets
- No secret in client code or in a NEXT_PUBLIC_, VITE_, EXPO_PUBLIC_ or PUBLIC_ variable. Only keys the provider documents as public go there.
- Never open, print or log .env files or secret values. Ask me for the variable name.
### Input and output
- SQL uses parameters or the query builder, never strings joined with user input.
- User text is rendered as text. No dangerouslySetInnerHTML, v-html or innerHTML with user data.
- Uploads are checked for type and size on the server.
- Redirects after sign-in accept only relative paths on this site.
### Money
- Prices and plans are looked up on the server, never taken from the client.
- Webhook handlers verify the provider's signature before anything else.
### Packages
- Before adding a dependency, state its exact name and why. Do not add one you cannot confirm exists.
### Before saying a security change is done
- List each route or policy changed and the check it now makes.
- Add a test where a signed-out user and a second user are refused.
And CLAUDE.md:
@AGENTS.md
Why are the rules worded like that?
- Each one names something you can search for or test. "Use
security_invoker = true" can be checked in a migration; "be careful with views" cannot. The OpenSSF guide to instructions for AI code assistants asks for rules "kept concise, specific, and actionable" (OpenSSF), and Claude Code's docs say "The more specific and concise your instructions, the more consistent" the results. - It is short. Claude Code suggests keeping each CLAUDE.md "under 200 lines" because longer files "reduce adherence". Cursor suggests rules "under 500 lines".
- No "you are a security expert" line. OpenSSF notes that "telling the system it is an expert often makes it perform poorly or worse".
- The package rule is there for a reason. OpenSSF cites a study where "19.7% proposed packages did not exist", which is how a lookalike package gets installed.
- The database rules match Supabase's own warnings. Its row level security page says "Views bypass RLS by default" and asks you to "Set
search_path = ''on everysecurity definerfunction" (Supabase). Our article on users making themselves admin explains the role rule in detail.
Can some rules load only for risky folders?
Yes, and it keeps the always-on file short. In Cursor, a rule with globs attaches when a matching file is in context:
---
description: Database migration rules
globs: supabase/migrations/**/*.sql
alwaysApply: false
---
- Read every existing policy on a table before changing it.
- A migration that drops or replaces a policy says what the new one allows, in one sentence.
Save that as .cursor/rules/migrations.mdc. The Claude Code version is .claude/rules/migrations.md with the same list under this frontmatter:
---
paths:
- "supabase/migrations/**/*.sql"
---
What can a rules file not do?
Stop anything. Claude Code's docs: "Claude treats CLAUDE.md files and auto memory as context. They aren't enforced configuration." Cursor's: "AI guidance should not be your only security control." Rules lower the odds; settings set the limits.
For secrets, add a deny rule in .claude/settings.json, which the client enforces whatever the model decides (Claude Code permissions):
{
"permissions": {
"deny": ["Read(./.env)", "Read(./.env.*)", "Read(./secrets/**)"]
}
}
Know its limits. Read deny rules also cover shell commands such as cat and head, but the docs say they "don't apply to a command that reads files without naming them, such as grep -r pattern .", or to a script that opens files itself. For that, Claude Code's docs point to the sandbox, which the operating system enforces around shell commands. An old .claudeignore file "has no effect".
Cursor already ignores .env files and .git/ by default. Its own page on .cursorignore warns that the agent's terminal and MCP tools "cannot block access" to ignored files and that "complete protection isn't guaranteed" (Cursor ignore files). Its run modes for terminal commands are described as "best-effort guardrails rather than a hard security boundary" (Cursor agent security).
Then review the code the rules produced: /security-review in Claude Code checks the changes on your branch, and our Claude Code and Cursor checklist covers the rest of the repository side.
Does the agent actually follow it?
Test it once, in a fresh session, with a request that breaks a rule:
Add an API route that returns a user's orders, using the user id from the query string.
A pass is a reply that names the rule and gets the user from the session instead. In Claude Code, /memory lists the instruction files it loaded. If either tool ignores the rule, check the file name first, then run:
ls .cursor/rules/*.md 2>/dev/null # anything listed here is ignored by Cursor
Repeat the test after you edit the rules. When a reviewer or a test catches a mistake the agent made, add one rule for it, in the same specific style.
Should I copy a rules file from GitHub?
Read it first, all of it, in an editor that shows hidden characters. On 18 March 2025 Pillar Security described a "Rules File Backdoor": instructions hidden in rules files with zero-width and bidirectional Unicode characters, invisible on screen, that steer Cursor and GitHub Copilot into adding code nobody asked for (Pillar Security). Both vendors told Pillar that reviewing suggestions is the user's job; GitHub later added a warning for hidden Unicode in files on github.com.
This prints any line with those characters:
perl -CSD -ne 'print "$ARGV:$.\n" if /[\x{200B}-\x{200F}\x{202A}-\x{202E}\x{2060}-\x{2064}\x{FEFF}]/; close ARGV if eof' \
AGENTS.md CLAUDE.md .cursor/rules/*.mdc
No output means none were found. Treat rules files like code in review: they change what code gets written.