Your first check is free. No card needed.Run a free security check

A security rules file for Cursor and Claude Code, ready to copy

Put about twenty specific, checkable security rules in AGENTS.md at the root of your repository, import it from CLAUDE.md with the line @AGENTS.md, and Cursor and Claude Code will both load it in every agent session. Cursor project rules must be .mdc files in .cursor/rules, and a plain .md file there is ignored. Both vendors say rules guide the agent but do not enforce anything, so add a deny rule for .env files in .claude/settings.json and test the result with one prompt.

You asked the agent for "an endpoint that returns the user's orders". It wrote one, the page works, and the endpoint takes the user id from the query string. Nothing in the request was wrong. Nothing in the project told the agent that the user comes from the session.

That is what a rules file is for: the things you would otherwise have to remember to say in every prompt. Most rules files people copy are either a single line ("write secure code") or five hundred lines generated for every language at once. The one below is short on purpose, and every rule is something you can check afterwards.

Where does each tool read rules from?

These are the locations in the vendors' documentation as of 29 November 2026.

ToolFileFormatWhen it loads
Cursor.cursor/rules/*.mdcMarkdown with description, globs and alwaysApply frontmatterAlways, when a matching file is in context, when the agent judges it relevant, or when you @-mention it
CursorAGENTS.md, CLAUDE.mdPlain MarkdownAGENTS.md in the root and subfolders; CLAUDE.md is applied to every conversation
Claude Code./CLAUDE.md or ./.claude/CLAUDE.mdPlain Markdown, with @path importsEvery session
Claude Code.claude/rules/*.mdMarkdown, optional paths frontmatterEvery session, or only when Claude works with matching files
Claude CodeAGENTS.mdPlain MarkdownRead 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 .md file in .cursor/rules does nothing. Cursor's docs: "Project rules must use the .mdc extension. A plain .md file in .cursor/rules is ignored by the rules system."
  • .cursorrules is 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:

  1. Write the rules in AGENTS.md at the repository root. Cursor reads it directly, and so do other agents that follow the AGENTS.md format.
  2. Create CLAUDE.md with @AGENTS.md on 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 every security definer function" (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.

Where does Saqr fit?

A rules file changes what the agent writes. It cannot tell you what the deployed app does. Saqr tests the live app from the outside in a real browser, and on a Full task, signed in with test logins you provide, it checks the same things these rules ask for: routes that answer without sign-in, one user reaching another's records, and fields such as role or price a user should not control. Every finding shows the request and response, with a fix prompt for your AI coding tool. Your first check is free, no card needed.

Saqr (usesaqr.com) is AI security for web apps. Its AI agents attack your live app from the outside, the way a real attacker would, and show you exactly what to fix. From $19 a month, cancel any time. Tests only apps you have shown are yours.

Questions

Should I use .cursorrules or .cursor/rules?

Use .cursor/rules with .mdc files, or AGENTS.md. Cursor's documentation calls the root .cursorrules file legacy and says it will be deprecated. When you move a rule over, set it to Always Apply so it keeps loading in every chat.

Does Cursor read CLAUDE.md?

Yes. Cursor's help pages say it reads CLAUDE.md the same way it reads AGENTS.md, and applies it to every conversation whatever its frontmatter says. Conditional rules belong in .cursor/rules instead.

Will Claude Code read my AGENTS.md without a CLAUDE.md?

From version 2.1.277, yes, but by default only when there is no CLAUDE.md, .claude/CLAUDE.md or CLAUDE.local.md in the working directory or above it (the Project instructions setting in /config changes this). Importing it with a line @AGENTS.md in CLAUDE.md is the way Claude Code's docs recommend to share one file with other tools, and it keeps working if someone adds a local file.

Do the rules apply to Cursor Tab completions?

No. Cursor's documentation says rules apply only to Agent (Chat), not to Tab completion or Bugbot reviews. Code accepted from Tab needs the same review as any other code.

Can a rules file keep the agent away from my .env file?

Not on its own, because both vendors describe rules as guidance. In Claude Code add Read deny rules for .env files in .claude/settings.json and consider the sandbox. Cursor ignores .env files by default but says complete protection is not guaranteed, so keep production secrets out of local files where you can.