{"slug": "how-to-make-cursor-follow-your-code-style", "title": "How to make Cursor follow your code style", "summary": "Cursor users can enforce code style by creating a `.cursorrules` file in the project root with explicit 'Do' and 'Don't' lists, concrete syntax examples, and a 'Style Reference' section, as vague adjectives like 'clean' are ineffective. The article advises using negative constraints, 'Always/Never' statements, few-shot examples, and file-path triggers to prevent the AI from ignoring rules, and suggests re-centering the AI by citing the specific broken rule when it forgets.", "body_md": "# How to make Cursor follow your code style\n\nTo force [Cursor](/en/tags/cursor/) to follow your specific code style, create a `.cursorrules` file in your project root containing explicit \"Do\" and \"Don't\" lists, concrete syntax examples, and a designated \"Style Reference\" section. The AI ignores vague adjectives like \"clean\" or \"modern\" and instead responds to hard constraints like \"Use named exports instead of default exports\" or \"No semicolons.\"\n\n## Where do I actually put the rules?\n\nPut them in a `.cursorrules` file at the root of your repository.\n\nWhile Cursor has global settings, project-specific files are better because your React frontend needs different rules than your Go backend. If you use a global rule for everything, the AI starts hallucinating TypeScript types inside your Python scripts. I've found that keeping rules local to the repo prevents the AI from getting confused when switching between different languages in a monorepo.\n\n## How should I phrase the rules so they actually work?\n\nUse negative constraints and \"Always/Never\" statements.\n\nVague prompts like \"Write professional code\" are useless. The AI's definition of \"professional\" changes based on the model version ([Claude](/en/tags/claude/) 3.5 Sonnet vs GPT-4o). You need to be pedantic.\n\nInstead of \"Use a consistent naming convention,\" write:\n\n- Always use camelCase for variables.\n- Never use underscores in function names.\n- Always prefix boolean variables with `is` ,`has` , or`should` .\n\nI spent three hours fighting with Cursor's tendency to use\n\n`any` in TypeScript until I added a hard rule: \"Strictly forbid the use of `any`. If a type is unknown, use `unknown` and narrow it with a type guard.\" After that, the errors dropped immediately.\n## Can I give the AI a visual example of my style?\n\nYes, by using \"Few-Shot\" examples directly in the rules file.\n\nLLMs are pattern matchers. A list of rules is good, but a code block is better. In your `.cursorrules`, create a section called `CODE_STYLE_REFERENCE` and paste a 10-line snippet of your \"perfect\" code.\n\nExample format:\n\n``` js\nSTYLE_REFERENCE:\n// Good:\nconst getUser = async (id: string): Promise<User> => {\n  return await db.user.findUnique({ where: { id } });\n}\n\n// Bad:\nasync function getUser(id) {\n  return db.user.findUnique({ where: { id } });\n}\n```\n\nWhen the AI sees the \"Good\" vs \"Bad\" contrast, it stops guessing. I tried this with a project using a very specific functional programming style (no classes, only pipes), and it stopped trying to suggest `class` structures after I provided two contrasting examples.\n\n## How do I handle different rules for different files?\n\nUse file-path triggers within your rules.\n\nCursor doesn't have a built-in \"if file is .css, use these rules\" logic in the `.cursorrules` file yet, so you have to explicitly tell it.\n\nWrite your rules like this:\n\n- For files in `/components` , always use Tailwind utility classes; never use CSS modules.\n- For files in `/lib/api` , always wrap responses in a`Result` type.\n- For `.test.ts` files, use`describe/it` blocks and avoid`test()` calls.\n\nThis prevents the AI from suggesting Tailwind classes in your backend controllers just because it saw them in your frontend files. If you're looking for more ways to optimize these prompts,\n\n[AI Coding](/en/category/aicoding/)workflows often benefit from these kinds of contextual boundaries.\n\n## What happens when the AI ignores my rules?\n\nYou have to \"re-center\" the AI or tighten the constraint.\n\nIf Cursor starts ignoring a rule, it's usually because the system prompt is being overridden by the conversation history. I've noticed that after a long chat session, the AI \"forgets\" the `.cursorrules`.\n\nWhen this happens, don't just say \"Follow the rules.\" Tell it exactly which rule it broke: \"You used a default export, but the `.cursorrules` specify named exports. Fix it and remember this for the rest of the session.\"\n\nIf it keeps happening, your rule is likely too vague. \"Keep components small\" is a suggestion; \"Components must be under 60 lines of code\" is a rule.\n\n## Is there a way to share these rules across a team?\n\nCheck these files into Git.\n\nSince `.cursorrules` is just a text file, committing it to your repo ensures every developer on the team has the AI following the same style. This is the only way to stop the \"AI style drift\" where three different developers get three different versions of the same feature because their local AI settings differ.\n\nFor teams managing a large set of shared [Resources](/en/category/resources/) or prompts, using a centralized knowledge base or a tool like PromptCube is one recommended option to document and version-control these prompts before they land in the `.cursorrules` file.\n\n## Comparison of Rule Types\n\n| Rule Type | Effectiveness | Example | When to use |\n\n| :--- | :--- | :--- | :--- |\n\n| Adjective | Low | \"Write clean code\" | Never |\n\n| Directive | Medium | \"Use arrow functions\" | General preferences |\n\n| Negative Constraint | High | \"Never use `var`\" | Eliminating bad habits |\n\n| Few-Shot Example | Highest | \"Good: [code] / Bad: [code]\" | Complex architectural patterns |\n\n## Frequently Asked Questions\n\n**Does `.cursorrules` work with both Claude and GPT models?**\n\nYes, but Claude 3.5 Sonnet tends to follow complex, multi-step instructions in `.cursorrules` more accurately than GPT-4o, which sometimes ignores negative constraints in longer files.\n\n**Will adding too many rules slow down the AI?**\n\nIt won't slow down the response time, but it will consume more of the \"context window.\" If you put 500 lines of rules in there, the AI has less room to remember the actual code you're working on. Keep it under 50-100 lines.\n\n**Can I use `.cursorrules` for project documentation?**\n\nYou can, but it's better to keep it focused on *how* to write code. For *what* the code does, use a `README.md` or a `docs/` folder. Cursor indexes those anyway, so you don't need to duplicate them in the rules file.\n\n**What is the best way to test if a rule is working?**\n\nStart a fresh chat session and ask the AI to generate a boilerplate component. If it violates your rule immediately, your phrasing is too vague. Refine the rule, restart the chat, and test again.\n\n[Next Telegram Search Bots are Getting Better →](/en/news/9089/)", "url": "https://wpnews.pro/news/how-to-make-cursor-follow-your-code-style", "canonical_source": "https://promptcube3.com/en/threads/9098/", "published_at": "2026-09-09 13:19:18+00:00", "updated_at": "2026-09-09 13:45:26.264970+00:00", "lang": "en", "topics": ["developer-tools", "ai-tools"], "entities": ["Cursor", "Claude 3.5 Sonnet", "GPT-4o"], "alternates": {"html": "https://wpnews.pro/news/how-to-make-cursor-follow-your-code-style", "markdown": "https://wpnews.pro/news/how-to-make-cursor-follow-your-code-style.md", "text": "https://wpnews.pro/news/how-to-make-cursor-follow-your-code-style.txt", "jsonld": "https://wpnews.pro/news/how-to-make-cursor-follow-your-code-style.jsonld"}}