Best Practices: .cursorrules

Do we have any best practices for properly using .cursorrules files? I’ve tried quite a few things, and I’ve checked the box, but it often ignores quite a bit of my rules.

Is there a way of knowing it’s actually looking at the file? Or, are there limits on the number of words/tokens or whatnot?

3 Likes

To know if cursor is reading the file, just instruct it to say something so you can confirm it read, like:

{
  "say": "In every message you send, you must say 'OH BOY!'",
  "commit_message": "keep them super short and concise, just a couple sentences max."
}
2 Likes

Could you share an example of one of your .cursorrules files? Yours seem structured as an object, and mine is poorly written plain text. I’d love to learn what you’ve done.

Oh, I saw that structure in a post here in the forum, it looked a nice way of structuring the instructions, I will find the post and get back.
Im new to .cursorrules

This post has an object in one of the members message, its a bit overkill IMHO, the value i got from this was the idea to structure the instructions.

This is very cool. Although, is there documentation on the Cursor website on how to best use these. Am I supposed to have a very large .cursorrules file, or can I place my files elsewhere across projects. Can I use multiple files?

The documentation for .cursorrules is one page.
I’m new to .cursorrules, that said, I would keep it minimal because the AI model itself has instructions optimized for coding.
The docs mention project-specific instructions placed in the root folder, so I would keep it in mind when thinking about what to write.

My issue is it’s certainly not reading my .cursorrules.md or .cursorrules file. because if I link it to the doc, then it responds correctly. if not, does whatever.

You must place .cursorrules in the root folder of the file explorer in the side bar

2 Likes

I think my issue is .cursorrules may only work for ctrl+k and chat, not composer. I didn’t realize, my fault.

1 Like


In the chat response check for evidence that your instruction was read.
A plain text in .cursorrules “say ■■ boy in every response” wil output this in the chat.

I meant *oh boy

here’s a couple of mine, they work in chat and compose

sometimes the responses leak into the code generation

Always start responses with 'SSSssssertainly SSsssir' and a newline

Always end responses with 'SSSssssir' and a newline

This is a python project to access Sharepoint and manipulate files and folders.

It is created as a library to be used in other projects.

We are using Python 3.12.6 on Windows
 
we are accessing sharepoint via the office365 library

e.g.

from office365.runtime.auth.client_credential import ClientCredential
from office365.sharepoint.client_context import ClientContext

or this one

Always start answers with "Yes Captain Leuitenant" on a line by itself, in bold

this is a Typescript project, do not suggest changes to .js files, always suggest changes to .ts files.

Do suggest changes to .html files.


DuckDB
------

we are using version 1.29.0of DuckDB-wasm

like this in our treemap.ts file

import * as duckdb from 'https://cdn.jsdelivr.net/npm/@duckdb/[email protected]/+esm';

it depends on gunzip too, so we need to import that
import { gunzip } from 'https://cdn.jsdelivr.net/npm/[email protected]/+esm';

Database structure
------------------

The database is created using the sql script in the treemap/ddb.sql file


D3
--

we're using D3 from a CDN in the html
    <script src="https://cdn.jsdelivr.net/npm/d3@7"></script>


2 Likes

use

1 Like

Check out some of my recent posts about .cursorrules. I’ve done pretty indepth about this. THIS works for me, YMMV!!! Adapt as needed :+1:

I’ll quickly explain my workflow:

Start with a template from https://dotcursorrules.com/ and modify as needed.

I’ve had some pretty good success by first using ChatGPT (web UI), and after plenty of “back and forth”, and Q&A sessions, having Chatty generate a large outline for my project. I then break that down into different files readme-milestones.md, readme-next-days-agenda.md, and several others. Create what you feel you need for your project.

Then in Cursor Composer, tell it to scan your codebase and particularly the readme files, so it has a deep context of the project.

Tell it to ask you any further questions needed for it to fully comprehend the scope of the project, and after enough Q&A sessions, and modifying the readmes, or creating new ones - tell it to modify the .cursorrules for you!

Following this, I went from a basic 80-something lines in my currorrules to over 180.

Every couple of days, I tell it to re-scan those readme files and the cursorrules, to make sure it adheres to my project scope, milestones, and rules.

Good luck to you!

1 Like

Hi Cursor Community, and especially Maxfahl,

I’ve been using the Rules for AI feature configured through the ‘Rules for AI’ tab in the settings menu, as it provides a convenient way to centralize the AI behavior guidelines for my workflows. However, I’ve noticed that these rules are completely ignored when I interact with the AI in composer mode.

To make the AI follow the expected behavior, I have to manually restate the rules in each individual prompt, which defeats the purpose of setting them up globally.

  • Has anyone else experienced this issue?
  • Are there any known limitations or specific configurations required to make the rules apply in composer mode?

I would greatly appreciate any insights or workarounds, and I’m happy to provide more details if needed. Thank you for your help!

Best regards,

1 Like

There have been no specific announcements regarding token limits or other restrictions. Usage is straightforward - you just need to place the .cursorrules file in your project’s root directory.
I’ve published .cursorrules optimized for Composer agent on GitHub, which you’re welcome to reference (although it’s in Japanese, you can easily translate it to English using a browser or LLM).

Japanese?

Yes.

One tip about optimal formats for LLMs:
Source: Medium article

  • Use XML for High-Demand Applications: For projects prioritizing precision, use XML tags to enhance model accuracy.
  • Leverage Markdown for Readability: Markdown is essential when clarity is needed for documentation or simpler tasks.
  • Avoid JSON: Due to poor performance across tests, it’s wise to steer clear of JSON unless absolutely necessary.
2 Likes

One thing to add - you should check this option.