Prompt Library

Cursor AI Prompts & Rules That Actually Work

21 copy-paste prompts

21 prompts and rules-file examples to get more out of Cursor's Agent, Cmd-K, and @-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 15 prompts are free instantly โ€” no signup needed. Hand-curated and tested by the AI Academy team.

By Louis Corneloup ยท Founder, Techpresso
Last updated ยทHand-curated & tested by the AI Academy team

Cursor Rules & Project Setup

4 prompts

Write a Project Rules File

1/21

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.

Generates a tailored rules file from your actual code so the Agent follows your conventions automatically.

๐Ÿ’ก

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

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.

Sets up path-specific rules so different parts of the codebase get the right guidance.

๐Ÿ’ก

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

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.

Creates a high-signal overview that gives the Agent durable context about how the project fits together.

๐Ÿ’ก

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

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.

Pulls official documentation into context so the Agent uses current APIs, not outdated training-data patterns.

๐Ÿ’ก

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.

Start 7-Day Free Trial

Building Features with Agent

5 prompts

Build a Feature Across Files

5/21

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.

Drives the Agent to plan a multi-file change before writing code, so you can correct the approach early.

๐Ÿ’ก

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

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.

Ties the implementation to an explicit spec and traces each requirement to real code.

๐Ÿ’ก

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

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.

Adds a new endpoint that mirrors an existing one so it fits the codebase's established conventions.

๐Ÿ’ก

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

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.

Produces a new component consistent with your design system and covering real-world states.

๐Ÿ’ก

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

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.

Brings in an external library using its current documented setup rather than outdated patterns.

๐Ÿ’ก

Pro tip: Have Cursor confirm the installed version before generating integration code so it targets the right API surface.

Refactoring & Cleanup

4 prompts

Refactor Without Changing Behavior

10/21

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.

Cleans up code while explicitly preserving behavior and surfacing anything risky.

๐Ÿ’ก

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

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.

Finds and consolidates repeated logic across the project with a review step before changes land.

๐Ÿ’ก

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

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.

Brings an old file up to current standards using authoritative docs rather than guesswork.

๐Ÿ’ก

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

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.

Performs a project-wide rename while first auditing every place the name is used.

๐Ÿ’ก

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.

Try AI Academy Free

Debugging with Context

4 prompts

Debug with Full Context

14/21

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.

Gives the Agent the error, repro steps, and relevant files so it can find the real cause, not a symptom.

๐Ÿ’ก

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

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.

Instruments a tricky code path with focused logging to expose what's actually happening.

๐Ÿ’ก

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

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.

Uses a known-good implementation as a reference to isolate why a similar one is broken.

๐Ÿ’ก

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

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.

Tackles a flaky, hard-to-reproduce issue by reasoning about non-deterministic causes first.

๐Ÿ’ก

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 prompts

Write Tests for a Function

18/21

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.

Generates meaningful tests aligned with your existing test style and verifies they pass.

๐Ÿ’ก

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

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.

Locks in current behavior with tests so a later refactor can be verified as behavior-preserving.

๐Ÿ’ก

Pro tip: Characterization tests are your safety net, write them first and a risky refactor becomes a measurable one.

Document Public APIs

20/21

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.

Adds clear documentation to public interfaces without altering behavior.

๐Ÿ’ก

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

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.

Drafts accurate documentation derived from real files instead of plausible-sounding guesses.

๐Ÿ’ก

Pro tip: Tell it not to invent options, Cursor will otherwise document flags and config that look reasonable but aren't in your code.

Frequently Asked Questions

Cursor rules are instructions the AI reads automatically on every request, defining your stack, conventions, and preferences. Newer Cursor versions store them under a .cursor/rules folder, and you can scope rules to specific file paths. Good rules keep the Agent consistent with your codebase without you repeating yourself each prompt.
Type @ in the chat or Composer to reference specific files, folders, the whole codebase, or external documentation with @Docs. @-mentions ground the AI in real context, which dramatically improves accuracy compared to letting it guess from filenames or memory.
Use Cmd-K for quick inline edits to a selection or a single file. Use the Agent (Composer) for multi-file features, refactors, and tasks that require reading and changing several files. For Agent work, always ask for a plan before it writes code.
Scope your prompt tightly: name the exact file or function, state what to keep unchanged, and tell it not to refactor unrelated code. Asking for a file-by-file plan first and reviewing the diff lets you catch and reject any out-of-scope edits before they land.
Provide context and constraints. @-mention the relevant files, paste full error messages and stack traces, reference an existing implementation as a template, and use @Docs for fast-moving libraries. The more grounded the prompt, the less the model has to guess.

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.