AI Learn
Cursor · AI Coding Tutorial

Create Cursor Project Rules for a repository

Turn recurring coding conventions into scoped project rules so Agent gets the right instructions for the files it is changing.

Reviewed September 19, 2026Independent tutorialFeatures may vary
Not official support. AI Learn is an independent education site and is not affiliated with Cursor. Check the provider’s current documentation for plan-specific limits, pricing and feature availability.
Before you start

Cursor Project Rules belong in .cursor/rules and can be scoped to relevant paths. Prefer small rules with one purpose over a single giant instruction file.

1. Collect repeated conventions

Start with rules you repeatedly correct: framework patterns, file naming, test expectations, API boundaries or forbidden generated files.

2. Create a focused rule

Give the rule a clear purpose and concise instructions. Include examples only when they remove ambiguity.

3. Scope it to the right files

Apply frontend rules to frontend files, database rules to migrations, and so on. Narrow scoping prevents irrelevant guidance from polluting context.

4. Test with one real edit

Ask Agent to make a small change in a file covered by the rule and explain which rule it followed.

5. Refine from failures

If Agent ignores or misreads the rule, reduce ambiguity, adjust scope or split the rule instead of simply adding more prose.

Try this prompt

Before editing this file, list the Cursor Project Rules that apply to it and summarize the constraints. Then make the smallest change that satisfies the task and show how the diff follows those rules.

Common mistakes

One global rule for everything; rules that conflict with each other; stale commands; using legacy configuration without checking current Cursor rule support; never testing rule scope.

Finish check

A small edit in a matching file receives the intended guidance while unrelated files are not burdened by that rule.

开始之前

Cursor Project Rules 通常放在 .cursor/rules,并可以限定作用路径。优先写“一个规则解决一个问题”的小规则,不要堆成一份巨大指令文件。

1. 收集你反复纠正的约定

从你经常重复提醒的规则开始:框架写法、文件命名、测试要求、API 边界、禁止修改的生成文件等。

2. 每条规则只解决一个明确问题

给规则一个清晰目的和短指令,只有在能真正消除歧义时才加入示例。

3. 把作用范围限定到正确文件

前端规则只匹配前端文件,数据库规则只匹配迁移等。范围越准确,越不会让无关规则污染上下文。

4. 用一个真实小改动测试

让 Agent 修改一个会命中该规则的小文件,并让它说明遵循了哪条规则。

5. 根据失败方式改规则

如果 Agent 忽略或误解规则,先减少歧义、调整范围或拆分规则,不要只是一味增加更多文字。

可以直接套用的提示词

编辑这个文件之前,先列出适用于它的 Cursor Project Rules 并总结约束。然后只做满足任务所需的最小改动,并说明 diff 如何遵守这些规则。

常见错误

一个全局规则管所有东西;多条规则互相冲突;命令已经过时;不确认当前 Cursor 规则机制却继续依赖旧配置;从不测试规则作用范围。

完成检查

完成后,命中规则的文件能得到正确指导,而无关文件不会被这条规则干扰。

開始之前

Cursor Project Rules 通常放在 .cursor/rules,並可以限定作用路徑。優先寫“一個規則解決一個問題”的小規則,不要堆成一份巨大指令檔案。

1. 收集你反復糾正的約定

從你經常重復提醒的規則開始:框架寫法、檔案命名、測試要求、API 邊界、禁止修改的生成檔案等。

2. 每條規則只解決一個明確問題

給規則一個清晰目的和短指令,只有在能真正消除歧義時才加入示例。

3. 把作用範圍限定到正確檔案

前端規則只匹配前端檔案,數據庫規則只匹配遷移等。範圍越準確,越不會讓無關規則污染上下文。

4. 用一個真實小改動測試

讓 Agent 修改一個會命中該規則的小檔案,並讓它說明遵循了哪條規則。

5. 根據失敗方式改規則

如果 Agent 忽略或誤解規則,先減少歧義、調整範圍或拆分規則,不要只是一味增加更多文字。

可以直接套用的提示詞

編輯這個檔案之前,先列出適用於它的 Cursor Project Rules 並總結約束。然後只做滿足任務所需的最小改動,並說明 diff 如何遵守這些規則。

常見錯誤

一個全局規則管所有東西;多條規則互相衝突;指令已經過時;不確認當前 Cursor 規則機制卻繼續依賴舊配置;從不測試規則作用範圍。

完成檢查

完成後,命中規則的檔案能得到正確指導,而無關檔案不會被這條規則干擾。

Official references

Check current product details at the source

Related practical tutorials

Continue with another single-task workflow.

All tutorials →