跳到正文
DEV Community· KANG TAI·· 2 小時前AI 評分60

如何判斷 Cursor 規則應設為 alwaysApply,還是按 glob 套用

Which Cursor rules deserve alwaysApply (and which should wait for a glob)

AI 導讀

KANG TAI 提出 Cursor 規則常駐判斷法,只有遺忘後會造成金錢或時間損失、適用於幾乎所有編輯且內容精簡的規則,才應設為 alwaysApply。其餘規則可按檔案 glob 套用,或設為 alwaysApply: false 並提供明確描述;文中以 React 和 Java 專案示範常駐規則與技術棧專屬規則的分工。

正文

KANG TAI

Someone asked me: how do you decide which rules earn the always-on slot, and which can wait until a matching file shows up?

That's the real product question. Not "how many rules can I zip."

The wrong answer

Putting everything in alwaysApply: true.

You pay context rent every turn. After compaction, long or generic rules get quietly deprioritized anyway. The model still invents a second form library.

The filter I use

A rule earns alwaysApply only if all three are true:

  1. It must survive compression — if the agent forgets it mid-session, you lose money or time (security, anti-scope-creep, "re-read AGENTS.md after compaction").
  2. It applies to almost every edit — not just React forms or Spring controllers.
  3. It stays tiny — a few imperative lines, not a style guide novel.

Everything else gets globs (or alwaysApply: false + a sharp description the agent can request).

Concrete split (React + Java repos)

Always-on (tiny core)

  • Anti-amnesia / session handoff: plan briefly, persist decisions on disk, re-read after compaction
  • Anti-scope-creep: if I asked for a bug fix, do not refactor the folder structure "while you're here"
  • Security baseline: no secrets in commits, no inventing auth bypasses

Globbed (stack layer)

  • React forms / TanStack Query / zod boundaries → **/*.{tsx,ts} under UI paths
  • Spring controllers / Bean Validation / no JPA entities in responses → **/controller/**/*.java, **/web/**/*.java
  • zod ↔ Bean Validation mapping → only when touching API contract files

Same methodology works if your stack is Next-only or Go — the filter is the product, not the file count.

Why free "900-skill dumps" still fail here

Breadth dumps optimize for GitHub stars. They don't decide what must stay in context after compression. Repo-native memory is a priority queue, not a junk drawer.

Try the tiny core first

I open-sourced a free Starter: three always-on rules + one PR-review Skill.

Install the Starter. After your next compaction, force a recovery from AGENTS.md. If that alone saves a session, the globbed pack is the upgrade — not another mega-ZIP.


No fabricated sales. Honest cold-start: methodology posts convert better than hard sell on a small account.

來源:DEV Community · dev.to