⌨️

Cursor AI System Prompt

A comprehensive system prompt that turns Cursor into a senior engineer on your specific codebase.

⌨️ Cursor Advanced Cursor

The prompt

You are an expert software engineer with deep knowledge of this codebase.

CODING STANDARDS:
- Follow existing patterns — match naming, file structure, and architecture exactly
- TypeScript: always define explicit types, avoid 'any'
- Functions: max 30 lines, single responsibility, descriptive names
- Errors: always handle with try/catch, log meaningful messages
- Comments: JSDoc on all exported functions, inline for complex logic only

WHEN WRITING CODE:
1. Read existing files first to understand patterns
2. Check for existing utilities before creating new ones
3. Match the import style used in the file
4. Use the existing UI component library, never raw HTML
5. Follow the existing folder/naming conventions exactly

SECURITY RULES:
- Never expose env variables in client code
- Always sanitize user inputs
- Use parameterized queries, never string concatenation for SQL
- Validate all API inputs with existing schemas

TESTING:
- Write unit tests for all business logic functions
- Follow existing test file naming and structure
- Mock external dependencies

TECH STACK: [YOUR STACK]
IMPORTANT FILES: [KEY FILES TO KNOW]
CODING STYLE: [ESLINT/PRETTIER CONFIG SUMMARY]

Replace everything in [SQUARE BRACKETS] before you run it. The bracketed fields are not optional — they are what the output is built from.

Why this prompt is built this way

This is not a prompt you send; it is a file you commit. Dropped into .cursorrules at your project root, it is prepended to every request the assistant makes — which makes it the single highest-leverage piece of text in an AI-assisted codebase, because it applies to work you have not thought of yet.

The instruction doing the most work is the first one under WHEN WRITING CODE: read existing files first. Left to itself, an assistant writes idiomatic code for the language rather than idiomatic code for your project, and the result is a codebase with six different ways of doing the same thing. Pattern-matching against what already exists is what keeps generated code from looking generated.

The security block is short and absolute on purpose. Rules phrased as flat prohibitions — never expose env variables, never concatenate SQL — survive summarisation and partial attention far better than nuanced guidance does.

The three bracketed fields at the bottom are what turn a generic ruleset into yours, and they are the ones people leave blank.

What to use it for

  • Solo developer productivity
  • Team AI consistency
  • Onboarding AI to legacy code
  • Code standardization

Adapting it to your situation

  • Fill in TECH STACK and IMPORTANT FILES properly. Without them, rule 5 — follow existing conventions — has nothing to anchor against.
  • Paste a short exemplary file into the rules. One good example of a component or a service teaches pattern-matching better than a paragraph describing it.
  • Change the 30-line function limit to whatever your team actually enforces. An invented number nobody follows erodes the credibility of every rule around it.
  • Add your framework quirks — server components, module boundaries, state conventions — since those are what assistants get wrong most often.

Where this goes wrong

The rules file is not a security control. An assistant following the security block is a helpful default, not a guarantee, and generated code still needs review — particularly anything touching authentication, queries or user input.

The other trap is letting it go stale. A rules file describing a stack you migrated off six months ago actively makes output worse, because it steers toward patterns that no longer exist in the codebase.

Which model to run it on

Written for Cursor, since .cursorrules is a Cursor convention. The same content works as a system prompt or project instruction in any assistant that supports one.

Practical tips

Place this in your .cursorrules file at the root of your project. Update the TECH STACK and IMPORTANT FILES sections with your actual stack. Add examples of good code from your codebase for even better pattern matching.