Chapter 34
34 / 50

AI Rules Configuration

⏱️ 30 min

.cursorrules, CLAUDE.md, and Skills are three complementary, not interchangeable config formats. Sort out what each is good at — and what it isn't — before mixing them. Otherwise you end up writing the same rule three times and nobody on the team will keep them in sync.

If you've never written one, start with Cursor Rules Intro and Claude Code Skills. This page covers how to divide responsibility across the three formats and keep them aligned across a team.

What each format is actually for

FormatLoadingGranularityBest for
.cursorrulesLoaded fully on Cursor startupSingle project fileSmall projects (<500 lines of rules), Cursor-only teams
.cursor/rules/*.mdcAuto-injected by glob, or agent-triggeredMultiple files with frontmatter globLarge projects, load different rules per file pattern
CLAUDE.mdLoaded by Claude Code on startup, with nested loading from subdirsProject + user + per-directoryLong-lived architectural rules, domain knowledge
Skills (~/.claude/skills/)Triggered on demand, not in default contextNamed bundle, SKILL.md + assetsHigh-frequency but task-specific complex workflows (>200-line SOPs)

The key difference:

  • .cursorrules and CLAUDE.md are always-on context — write too much and you blow your token budget every session
  • Skills are lazy-loaded — only read when the AI decides it needs them, so you can park lots of SOPs without polluting context
  • .cursor/rules/*.mdc sits in between, matching by glob

What goes where

The most common mistake is dumping everything into CLAUDE.md until it's 2,000 lines and burns 5K tokens per session. Better split:

Rule typeGoes inExample
Architectural laws (always enforced)Top of CLAUDE.md"no service file over 600 lines", "prefer ObjectId over slug"
Code style.cursorrules or .cursor/rules/style.mdcnaming, import order, tab vs space
Domain knowledgeMiddle of CLAUDE.md"users have free/paid/enterprise tiers, perms via RBAC"
Complex workflow SOPs (>200 lines)Skilldeployment flow, data migration, cert generation
Stack-specific.cursor/rules/{stack}.mdc with globReact rules that only apply to *.tsx
Personal preferences~/.claude/CLAUDE.md (user-level)"use bun not npm", "commit messages in Chinese"

Team sync strategy

Rules only matter if they're committed to git. Three layers, three approaches:

# 1) Project-level — all in
git add .cursorrules .cursor/rules/ CLAUDE.md
git commit -m "chore: update AI rules for new auth pattern"

# 2) Project Skills — committed under .claude/skills/
git add .claude/skills/deploy-prod/
git commit -m "skill: add prod deploy SOP"

# 3) User-level — never committed
# ~/.claude/CLAUDE.md and ~/.claude/skills/ are personal; don't commit

Typical .gitignore additions:

# AI cache + personal settings stay local
.claude/settings.local.json
.cursor/settings.local.json

# But project-level rules MUST be committed:
# !.cursorrules
# !.cursor/rules/
# !CLAUDE.md
# !.claude/skills/

Mandatory review: changes to CLAUDE.md or .cursorrules must go through PR — no direct pushes. These files affect every engineer's AI behavior, equivalent to changing lint config; the team needs to agree.

Real example: how JR Academy layers it

~/.claude/CLAUDE.md                         # Personal (~50 lines)
└─ "use bun not npm"
└─ "auto-push after commit"
└─ Projects registry

jr-academy-ai/CLAUDE.md                     # Project laws (~600 lines)
└─ ABSOLUTE RULES (rm policy, git safety)
└─ Service architecture (600-line cap, single responsibility)
└─ ID-First Principle (post-incident learnings)
└─ Anti-Template Content Rule
└─ MongoDB / Auth / Testing constraints

.cursor/rules/frontend.mdc                  # glob: *.tsx
└─ styled-components rules
└─ z-index conventions

.claude/skills/bootcamp-sync/               # Complex SOP (~400 lines)
└─ SKILL.md: sync curriculum/ → prod
└─ scripts/diff-check.ts
└─ templates/

.claude/skills/lesson-design/
└─ SKILL.md

Result: a typical session loads ~8K of context (the CLAUDE.md); when a deploy or sync is needed, the AI auto-triggers the matching skill and pulls in another 5-10K. About 60% cheaper than putting everything in CLAUDE.md.

Common traps

  • Rules written too abstractly — "code should be clean and maintainable" is dead weight; AI can't act on it. Write "split any service file over 600 lines" instead.
  • Conflicting rules.cursorrules says "use tabs", CLAUDE.md says "4 spaces", AI behavior becomes unpredictable. Audit periodically.
  • Skill trigger conditions are vague — if SKILL.md description says "helps with code review", the AI will never auto-trigger it. Write "auto-triggers on PR review, takes a PR diff, outputs a 5-category issue list."
  • Rules go stale — team locked in "use React 17" six months ago, you've since upgraded to React 19, AI still writes legacy patterns. Audit quarterly.

Next

📚 Related resources

Common questions

Open a question to review the practical answer.

Do rule files prevent unauthorized actions?

Rules are context, not enforced permissions. Use effective tool permissions, server-side authorization and observed behavior checks.

When should rules be split?

Keep durable constraints in project rules, current requirements in a task brief and task-specific procedures in a skill. Split by scope, not an arbitrary line count.

How can I validate a rule?

Retest normal, out-of-scope and conflicting scenarios and record actions and errors. Do not claim fixed savings without comparable measurements.