Cursor AI Prompts & Rules That Actually Work
21 prompts and rules-file examples to get more out of Cursor's Agent, inline edit, and file mentions. Set up project rules, build features across files, refactor safely, debug with context, and write tests.
In short: This page contains 21 copy-paste ready prompts, organized into 5 categories with a description and pro tip for each. The first 5 prompts are free instantly, no signup needed. Hand-curated and tested by the AI Academy team.
Cursor Rules & Project Setup
4 promptsWrite a Project Rules File
1/21โจ What it does
Cursor reads the repo and drafts a project rules file covering stack, folders, naming, preferred libraries, errors, and tests. Save it as the rules file, then tighten any bullet that is not actually how you work.
Read the codebase and draft a project rules file for Cursor. Include: the tech stack and framework versions, the folder structure and where new files go, our naming and import conventions, the libraries to prefer (and any to avoid), and how we handle errors and tests. Output it as concise, imperative bullet rules I can paste into a .cursor/rules file.
Pro tip: Keep rules short and imperative ('Use named exports', not paragraphs). Cursor follows terse, scannable rules far more consistently than prose.
Add Scoped Rules for a Directory
2/21โจ What it does
Cursor writes a short scoped rule that applies only under a path you name, such as src/api, with the conventions you list for that area in under 15 bullets. Review when each rule should fire, then save it so the rest of your repo stays unaffected.
Create a scoped rule that applies only to files under [path, e.g. src/api/**]. The rule should enforce: [specific conventions for that area, e.g. all handlers return a typed Result, validate input with zod, never log secrets]. Keep it under 15 bullet points and explain when each rule should trigger.
Pro tip: Use glob-scoped rules for areas with unique conventions (API, UI, tests) instead of one giant global file the model half-ignores.
Document the Codebase for Context
3/21โจ What it does
Cursor writes a one-page architecture overview from [folder]: main modules, data flow, entry points, and outside services. Save it as your context rule, then fix any name that does not match the real code.
Generate an architecture overview I can keep as a rule for context: the main modules and what each does, how data flows through the app, the key entry points, and the external services we call. Use @[folder] to ground it in the real code and keep it to one page.
Pro tip: Mention the @-folder explicitly so Cursor reads real files rather than guessing the architecture from filenames.
Pin Library Docs as Context
4/21โจ What it does
Cursor uses the docs for [library/framework] version [X] to summarize current patterns for the task you name and what changed, then proposes a standard for your rules. Confirm the version, then add the standard so the Agent stops using old APIs.
I'm using [library/framework] version [X]. Using @Docs for it, summarize the current recommended patterns for [task, e.g. data fetching] and note anything that changed from older versions. Then propose how we should standardize our usage and add it to our rules.
Pro tip: Reference @Docs for fast-moving libraries, it stops Cursor from suggesting deprecated APIs it learned from older code.
Prompts get you started. Tutorials level you up.
A growing library of 300+ hands-on AI tutorials. New tutorials added every week.
Building Features with Agent
5 promptsBuild a Feature Across Files
5/21โจ What it does
Cursor plans [feature] against [relevant files/folders], lists files it will touch, then implements only after you confirm, without sneaky new dependencies. Approve or correct the plan first, then let it write the code.
Implement [feature] end to end. First read @[relevant files/folders] to match existing patterns, then make a short plan listing the files you'll create or change and why. After I confirm, implement it, keeping each file consistent with our conventions. Don't add new dependencies without flagging them.
Pro tip: Always ask for the file-by-file plan first, reviewing the plan is much cheaper than reviewing a 10-file diff after the fact.
Implement Against a Spec
6/21โจ What it does
Cursor implements [feature] from [paste requirements] using components in [folder], and points each requirement to the code that satisfies it. Answer any ambiguity before it codes, then walk the pointers in your review.
Here is the spec for [feature]: [paste requirements]. Implement it using the existing components in @[folder]. For each requirement, point to the exact code that satisfies it. If any requirement is ambiguous, ask me before coding rather than guessing.
Pro tip: Telling the Agent to ask when ambiguous prevents it from inventing behavior to fill gaps in your spec.
Wire Up an API Endpoint
7/21โจ What it does
Cursor adds a [METHOD] [route] endpoint that [does what], matching validation, errors, and response shape in [existing handler file]. Call the new route once, then keep the file list it prints for your notes.
Add a [METHOD] [route] endpoint that [does what]. Follow the pattern in @[existing handler file]: same validation, error handling, and response shape. Add the route, the handler, input validation, and any types. List the files you changed and show how to call the endpoint.
Pro tip: Point the Agent at a concrete existing handler as the template, it copies a real example far more reliably than a described pattern.
Build a UI Component
8/21โจ What it does
Cursor builds a [component name] that [behavior and props], matching [similar existing component], with loading, empty, and error states plus accessible labels. Click those states, then tighten any prop type that is wrong in your types.
Create a [component name] component that [behavior and props]. Match the styling and structure of @[similar existing component], reuse our shared UI primitives, and handle loading, empty, and error states. Keep it accessible (labels, keyboard nav) and add the prop types.
Pro tip: Listing loading/empty/error in the prompt gets them all built in one pass instead of follow-up fixes later.
Integrate a Third-Party Library
9/21โจ What it does
Cursor adds [library] for [task] using the current version and docs, then wires it into [target file] with the recommended setup. Add the env vars it lists, then run your app to confirm the hook-up.
Add [library] to handle [task]. First check @package.json for the current version (or tell me what to install), then reference @Docs for the correct setup. Wire it into @[target file] following the library's recommended pattern, and explain any config or env vars I need to add.
Pro tip: Have Cursor confirm the installed version before generating integration code so it targets the right API surface.
Refactoring & Cleanup
4 promptsRefactor Without Changing Behavior
10/21โจ What it does
Cursor refactors [file or function] for readability and less duplication without changing behavior or the public interface. Run your existing tests, then revert any change it flagged as risky.
Refactor @[file or function] to improve readability and remove duplication. Do NOT change its external behavior or public interface. Explain each change briefly, keep the existing tests passing, and if a change is risky, flag it instead of applying it.
Pro tip: Stating 'do not change behavior' and 'keep tests passing' keeps refactors safe, the Agent otherwise tends to 'improve' logic you didn't ask it to touch.
Extract and Consolidate Duplication
11/21โจ What it does
Cursor finds duplicated patterns in [folder], proposes shared helpers, then extracts them after you approve and updates every call site. Read each call-site diff, then merge only if the helpers still read clearly.
Search the codebase for code duplicated across @[folder]. List the duplicated patterns you find, then propose where to extract shared helpers. After I approve, do the extraction and update all call sites. Show the diff for each call site you changed.
Pro tip: Ask for the list of duplications first, you may only want to consolidate some of them, not blindly DRY everything.
Modernize Legacy Code
12/21โจ What it does
Cursor updates [file] to current [language/framework] practice, replacing deprecated APIs with patterns from the docs. Accept the replacements one by one, then run your file's tests after each step.
Update @[file] to current best practices for [language/framework]: replace deprecated APIs, use modern syntax, and improve typing. Reference @Docs for the correct current patterns. Make changes incrementally and explain why each replacement is the recommended approach now.
Pro tip: Pair this with @Docs so 'modern' means the framework's actual current recommendation, not just the model's default.
Rename and Reorganize Safely
13/21โจ What it does
Cursor lists every use of [old name] in [folder], then renames it to [new name] across imports, references, and strings. Check the list first, then build your project to confirm nothing else broke.
Rename [old name] to [new name] across the codebase and update every import, reference, and string that depends on it. Use @[folder] to find all usages first and list them before changing anything. Verify nothing else breaks after the rename.
Pro tip: Have the Agent enumerate all usages before renaming so you can catch dynamic references that a naive find-and-replace would miss.
Like these prompts? There are full tutorials behind them.
Learn the workflows, not just the prompts. 300+ easy-to-follow tutorials inside AI Academy โ and growing every week.
Debugging with Context
4 promptsDebug with Full Context
14/21โจ What it does
Cursor traces [paste error and stack trace] from [steps to reproduce] through [relevant files], explains the root cause, then applies the smallest fix. Reproduce the bug once more on your machine, then leave unrelated code alone.
I'm getting this error: [paste error and stack trace]. It happens when [steps to reproduce]. Read @[relevant files] to trace the cause, explain the root cause before fixing, then apply the smallest fix that resolves it. Don't refactor unrelated code while you're in there.
Pro tip: Always paste the full stack trace and @-mention the files in it, the line numbers let Cursor jump straight to the culprit.
Add Targeted Logging
15/21โจ What it does
Cursor adds temporary labeled debug logs around [function/area] to trace [key variables] when [behavior] happens, and tells you what to watch. Run the path, then delete those logs when you are done.
I can't reproduce why [behavior] happens. Add temporary, clearly-labeled debug logging around @[function/area] to trace the values of [key variables] and the flow of execution. Tell me what to look for in the output, and remind me to remove the logs after.
Pro tip: Ask for clearly-labeled temporary logs so they're easy to grep and remove once you've found the issue.
Compare Against Working Code
16/21โจ What it does
Cursor compares [file for A] and [file for B] to explain why [feature A] works and [feature B] does not, then proposes the fix. Confirm the difference it names, then apply only that fix in your branch.
The [feature A] works but [feature B] doesn't, even though they're similar. Compare @[file for A] and @[file for B], list the meaningful differences, and tell me which difference most likely explains why B fails. Then propose the fix.
Pro tip: Diffing against working code is often the fastest path to a bug, the Agent spots the one line that diverges.
Trace an Intermittent Issue
17/21โจ What it does
Cursor reads [relevant files] and ranks likely causes of intermittent [behavior]: timing, order, state, races, or outside responses. Confirm the top cause before changing code, then add a test if you can force it.
Sometimes [behavior] fails but usually it works. Read @[relevant files] and reason about what could differ between runs, timing, ordering, state, async race conditions, or external responses. List the most likely causes ranked by probability, and suggest how to confirm each before we change anything.
Pro tip: For intermittent bugs, ask for ranked hypotheses and confirmation steps, jumping straight to a fix usually just hides the real race.
Tests & Documentation
4 promptsWrite Tests for a Function
18/21โจ What it does
Cursor writes tests for [file/function] in [test framework], matching [test folder], covering happy path, edges, and errors, then runs them. Read what it left out, then add any case you still care about.
Write tests for @[file/function] using [test framework]. Cover the happy path, edge cases, and error conditions, and match the structure of our existing tests in @[test folder]. Run them and fix any failures. List which behaviors are covered and which you intentionally left out.
Pro tip: Ask what was intentionally left uncovered, it reveals assumptions the Agent made and gaps you may want to fill.
Add Tests Before Refactoring
19/21โจ What it does
Cursor writes characterization tests for [module] that lock today's behavior, quirks included, without fixing anything. Run them on your current code, then start the refactor only after they pass.
Before we refactor @[module], write characterization tests that capture its current behavior exactly as it is today, including any quirks. Don't fix anything yet. These tests should pass on the current code so we can refactor safely afterward.
Pro tip: Characterization tests are your safety net, write them first and a risky refactor becomes a measurable one.
Document Public APIs
20/21โจ What it does
Cursor adds doc comments to exported functions and types in [file] covering purpose, params, returns, and gotchas, with no logic changes. Skim the comments, then keep only the ones that match how you actually use the API.
Add doc comments to the exported functions and types in @[file]. For each, describe what it does, its parameters, return value, and any side effects or gotchas. Match our existing doc style and don't change any logic, only add documentation.
Pro tip: Restrict it to documentation only, otherwise the Agent often 'tidies' code while writing comments and sneaks in behavior changes.
Generate a README Section
21/21โจ What it does
Cursor writes a README section you name, such as setup and usage, from [relevant files], with install, env vars, commands, and a real example. Delete any invented flag, then paste the section into your README.
Write a [section, e.g. setup and usage] section for the README based on @[relevant files]. Cover install steps, required env vars, the main commands, and a short usage example, all grounded in the actual code and scripts. Keep it concise and don't invent options that don't exist.
Pro tip: Tell it not to invent options, Cursor will otherwise document flags and config that look reasonable but aren't in your code.
Free tool
Prompt Optimizer
Turn a rough idea into a structured, professional AI prompt.
Frequently Asked Questions
Is Cursor worth paying for?
Read our honest, no-hype breakdown with the real pricing.
Prompts are the starting line. Tutorials are the finish.
A growing library of 300+ hands-on tutorials on ChatGPT, Claude, Midjourney, and 50+ AI tools. New tutorials added every week.
7-day free trial. Cancel anytime.
Related guides