
Lesson Description
The "Setup Cursor Rules" Lesson is part of the full, Cursor & Claude Code: Professional AI Setup course featured in this preview video. Here's what you'd learn in this lesson:
Steve walks through creating Cursor rules. The rules are written in markdown and can be scoped to a specific file or directory. The "Awesome Cursor Rules" repo or sites like cursor.directory all developers to search rules shared by the development community.
Transcript from the "Setup Cursor Rules" Lesson
[00:00:00]
>> Steve Kinney: So there's a bunch of ways to make them. One, you could just literally make that folder and do it right. The other one, you do add user rule or user rule, view user rules, new cursor rules, do that. Okay, so let's call this one reaction. And as you can see, this basically looks like a markdown file where you can start to express some of that intent.
[00:00:38]
We were talking about this earlier. This is one of the things that multiple people have mentioned. My co founder, Rylan, does this where he's got this one where he uses, he has three of these. It's funny, when I grab his code, he said, always print these three emojis to the chat to acknowledge that you have read this file.
[00:01:06]
If he doesn't see those, he knows his file has not gotten picked up. Which is when I talk about there's more art to this than science, genius and ridiculous. And it works. And now every time I see this code, I see those emojis all the time. It's like not taking up that many tokens.
[00:01:24]
So, you know, have fun. But, like, I'm like, it's wild. So if anyone else has, like, weird tricks like that, definitely bring them up. Because, like, I was like, that would have never occurred to me to do so. Yeah. So we've got. You can. Some of these. You can tweak in these settings.
[00:01:44]
So these are the options we saw earlier. I don't trust that one. I don't trust that one because I'm not a good enough person for that. So apply to specific files. I think it's the interesting one for our case. Okay. And you can see some suggestions. So if this one is React, it makes sense that we definitely want TSX files.
[00:02:03]
And the nice thing just to, like, as a sanity check is if you type in a bogus pattern, you at least get a warning. I know this because I made a typo one day and I think I spelled svelte wrong, which I do daily. And you can at least catch that.
[00:02:27]
And you can do stuff like where you can get, like, again, the regular brain, smart brain, galaxy brain version of this is like, all TSX files. Great. All REACT files. Like, hey, we write them in typescript, hey, we do this, so on and so forth. Don't export them as default.
[00:02:43]
I don't have weird things. But, like, if I could convince six people on my team to follow them, I think I can convince an AI and, like, you can build this up, but then you can also do, like, you know, this obviously won't work but let's say like Source/ Components TS so now hey, this rule only to my reusable components.
[00:03:11]
And then let's say I had two different files. I could have one for all react components and I could have one for the react components in this file or the other thing that I will do is I have and I codify these in some rules for creating files and I have a bunch of other weird stuff that is my own making where it's like if I'm defining tools for an agent to use, I'll actually use a tool TS file and then those are automatically pulled into those rules.
[00:03:42]
You can start to build out what you want for react component they should be in this folder, they should export the function or export default whatever it is that you should be consistent in your code base because again, the consistency matters because I am tightly wound. The consistency matters because that is context clues for the LLM right?
[00:04:02]
And giving it more patterns is only adding chaos and entropy into the system. And I used to deal with people, I let go of a lot of that. I don't need to hassle my hard working team that I like arrow functions and Alex likes function expressions. You know what, the code base has both because Alex is working very hard and that's not helpful in a pull request.
[00:04:29]
But for an AI, I can be the worst version of myself and it's been working out great for me. So I will kind of, I'll show you. So I've got some that I wrote recently where I reuse my own jokes. So for TypeScript, even if it's creating a TypeScript file or whatever, but also to make sure it doesn't change it, okay, here are the files we're gonna use.
[00:04:59]
And again, where do you think the inspiration for this rule came from? Never use @ts-ignore or ts-expect-error without explanatory comments. You know where that came from. It did it. And some of this, as you can see my increased frustration over time. And yes, I'm aware of what I'm doing to the token counts.
[00:05:25]
I'm aware that I'm a hypocrite at times. But as you can see, I don't like enums. So some of that is my own personal things. We can kinda begin again. Some of that though is useful, right, document the complex type with JSON comments. Now every time it goes into a Typescript file it reads that.
[00:05:45]
Sometimes it doesn't, you know, so on and so forth. Again, as you see, I care strongly about eslint but I wrote this one before I got the flow of making, now I've got pre-commit hooks and so it's like a lot of times I will have to say in a prompt you are not successful until you can make a commit, right?
[00:06:11]
And knowing that my pre-commit hooks will not pass if my rules are not followed. When we look at cloud hooks later you can have hooks where you can see it will check with you Pre tool use and post tool use. Where post tool use. You can run all those checks and yell at it or pre tool use if it starts to say hey, it's going to run this bash command git commit no verify which skips all the pre commit hooks.
[00:06:40]
You can literally block it, right? And that's like again that is the set of controls to keep this stuff like in place. You know, like just little like is this the most important thing in the world? No. Am I a bad person? Probably. I like my imports in a certain order.
[00:06:58]
Like do you understand how hard I am to work with as a person? I do type validation with Zod now. I think I have like the one that I have in my project now is like always use Zod v4 again rules, so on and so forth. You can kind of see about like, you know, like don't just trust that fetch because fetch returns any.
[00:07:21]
It'll just believe whatever you said. Actually this is like a known pattern that somehow works, wrong and right anti-patterns. If you've ever done the image generation, negative prompts are a thing like statistics, you say what you want, but also making it very clear what you don't want actually for these models is an effective counterbalance.
[00:07:48]
So you can begin to try to find some of these patterns. But again these are just ones of TypeScript. What I want an employee to do is eventually read these documents about the architecture of this application before you touch any files in this directory. I have JSON. There's a bunch of code that I.
[00:08:09]
A lot of those Zod schemas that I use in my code base I actually have generated from the types out of other things. So it's like never edit these files. Always run this bun command to generate those files whenever you update this other file to express all the rules in writing clearly and then you end up with better results, right?
[00:08:32]
And so like I said, there's a bunch of ways you can begin to tweak this. I would implore you in your copious free time, you can go into kinda rules and again, do not, I want that one. I'm building a Chrome extension right now, as I mentioned. So I'm like, I'm at least gonna read this.
[00:08:49]
But you can kinda see some interesting ones. Even this one jumped out at me because it's got some things similar before, as we saw earlier. Like, and it's like, for me, when I said some of those file extensions and folders in a Chrome extension, you've got a service worker which does not have access to the dom, right?
[00:09:08]
You've got content scripts that run in the DOM that do not have access to a lot of the Chrome extension APIs. You've got these weird things that have access to both, right? I start with the rules. Then I have eslint rules that apply adaptively to those file paths.
[00:09:24]
And again, you tell it not to do it 60% of the time. It works every time. And then you have the feedback loop to make sure it doesn't do that, because ideally, you still want to tell it not to do it, because that feedback loop is tokens now.
[00:09:40]
It's better than me having to tell it to start over. Yeah, have both. But ideally, if you can get it right the first time, that is great. Because a lot of times it won't read the ESLint error message unless it gets an error exit code of not zero.
[00:09:53]
Awesome.
>> Male: One thing I found interesting is if you ask it why, sometimes it'll tell you how I got to that thought. And then you can kind of reverse engineer the psychology.
>> Steve Kinney: Yeah, yeah. Every time it does something you don't want, if you build your own muscle memory of why did you do that, right?
[00:10:07]
Again, it's not unlike parenting. Like I said, how those rules apply is an interesting dance. As many as you need, as few as you can get away with, right? And, like, make sure you're not repeating yourself across them unless you feel the need to. And like, they will be read ideally every time.
[00:10:27]
So they start to take away some of that boilerplate. And there are other tools that we'll look at in a little bit for taking away some of that boilerplate as well.
Learn Straight from the Experts Who Shape the Modern Web
- In-depth Courses
- Industry Leading Experts
- Learning Paths
- Live Interactive Workshops