Demo, all content is generated
Question

My .cursor/rules file is ignored, agent keeps running npm instead of pnpm

Solved · 163 views · asked by kaito · edited

Project uses pnpm. I made a rule through the "New Cursor Rule" command, it created .cursor/rules/package-manager.mdc:

---
description:
globs:
alwaysApply: false
---
Always use pnpm. Never run npm install or npx.

The agent still runs npm install every time it adds a package, and now I have both package-lock.json and pnpm-lock.yaml. Vercel then complained about two lockfiles.

What I’ve tried

Wrote the rule in capitals, added it twice, restarted Cursor. Also tried telling it in the chat, which works for that chat only.

Comment

3 answers

Marked as helpful by the asker
sergio_ruiz · edited

With alwaysApply: false, no globs and an empty description, that rule is a Manual rule. It only gets loaded when you @-mention it. Cursor never has a reason to pick it up by itself.

For a rule that must hold everywhere:

---
description: Package manager for this repo
alwaysApply: true
---
Use pnpm for everything (pnpm add, pnpm dlx). Never run npm or npx.

You can check it's loaded: start a new agent chat and look at the rules listed in the context for that message. If it's not in there, the model never saw it.

Keep "always" rules to one or two short files, though. Everything always-on competes for the same context.

Comment
It shows up in the context now and the agent used pnpm add on the first try. Didn't know about Manual being the default. kaito · edited
The rule-type dropdown in the editor UI sets the same frontmatter, if you prefer clicking. leo_prompts · edited
kenji_w · edited

Also remove the other signal the agent is reading. Models look at lockfiles before they look at rules:

rm package-lock.json

and add to package.json:

"packageManager": "pnpm@9.12.0",
"scripts": { "preinstall": "npx only-allow pnpm" }

Now if anything runs npm install it fails loudly, and the agent reads the error and switches.

Comment
Did both. Belt and braces. kaito · edited
leo_prompts · edited

If you also use other agents on the same repo, put the one-liner in AGENTS.md at the root as well. Cursor reads that file too, so you have one place for the rules every tool should follow.

Comment