$npx -y skills add AgentWorkforce/relay --skill creating-claude-rules-skillUse when creating or fixing .claude/rules/ files - provides correct paths frontmatter (not globs), glob patterns, and avoids Cursor-specific fields like alwaysApply
| 1 | # Creating Claude Rules |
| 2 | |
| 3 | ## Overview |
| 4 | |
| 5 | Rules in `.claude/rules/` are modular instructions scoped to specific files via glob patterns. They load automatically with same priority as `CLAUDE.md`. |
| 6 | |
| 7 | ## When to Use |
| 8 | |
| 9 | - Creating new rules in `.claude/rules/` |
| 10 | - Fixing rules that use wrong frontmatter (`globs` instead of `paths`) |
| 11 | - Migrating Cursor rules to Claude format |
| 12 | - Organizing project-specific conventions |
| 13 | |
| 14 | ## Quick Reference |
| 15 | |
| 16 | | Field | Claude | Cursor | |
| 17 | | ------------- | -------------- | ------------------- | |
| 18 | | Path patterns | `paths` | `globs` | |
| 19 | | Always apply | Omit `paths` | `alwaysApply: true` | |
| 20 | | Description | Not documented | `description` | |
| 21 | |
| 22 | ## Frontmatter |
| 23 | |
| 24 | ### Path-Scoped Rules |
| 25 | |
| 26 | ```yaml |
| 27 | --- |
| 28 | paths: |
| 29 | - 'src/api/**/*.ts' |
| 30 | - 'tests/**/*.test.ts' |
| 31 | --- |
| 32 | ``` |
| 33 | |
| 34 | Or single pattern: |
| 35 | |
| 36 | ```yaml |
| 37 | --- |
| 38 | paths: src/**/*.{ts,tsx} |
| 39 | --- |
| 40 | ``` |
| 41 | |
| 42 | ### Global Rules |
| 43 | |
| 44 | Omit frontmatter entirely - applies to all files: |
| 45 | |
| 46 | ```markdown |
| 47 | # TypeScript Conventions |
| 48 | |
| 49 | Use .js extensions in imports. |
| 50 | ``` |
| 51 | |
| 52 | ## Common Mistakes |
| 53 | |
| 54 | ```yaml |
| 55 | # ❌ WRONG - globs is Cursor format |
| 56 | --- |
| 57 | globs: |
| 58 | - '**/*.ts' |
| 59 | --- |
| 60 | # ✅ CORRECT - Claude uses paths |
| 61 | --- |
| 62 | paths: |
| 63 | - '**/*.ts' |
| 64 | --- |
| 65 | ``` |
| 66 | |
| 67 | ```yaml |
| 68 | # ❌ WRONG - alwaysApply is Cursor-only |
| 69 | --- |
| 70 | alwaysApply: true |
| 71 | --- |
| 72 | # ✅ CORRECT - just omit paths for global rules |
| 73 | # (no frontmatter needed) |
| 74 | ``` |
| 75 | |
| 76 | ```yaml |
| 77 | # ❌ WRONG - unquoted patterns |
| 78 | --- |
| 79 | paths: |
| 80 | - **/*.ts |
| 81 | --- |
| 82 | |
| 83 | # ✅ CORRECT - quote glob patterns |
| 84 | --- |
| 85 | paths: |
| 86 | - "**/*.ts" |
| 87 | --- |
| 88 | ``` |
| 89 | |
| 90 | ## Directory Structure |
| 91 | |
| 92 | ``` |
| 93 | .claude/rules/ |
| 94 | ├── testing.md # Path-scoped or global |
| 95 | ├── typescript.md |
| 96 | └── frontend/ # Subdirectories supported |
| 97 | └── react.md |
| 98 | ``` |
| 99 | |
| 100 | Files discovered recursively. Use subdirectories to organize. |
| 101 | |
| 102 | ## Glob Patterns |
| 103 | |
| 104 | | Pattern | Matches | |
| 105 | | ------------------- | ---------------------- | |
| 106 | | `**/*.ts` | All .ts files anywhere | |
| 107 | | `src/**/*` | Everything under src/ | |
| 108 | | `*.md` | Markdown in root only | |
| 109 | | `**/*.{ts,tsx}` | .ts and .tsx files | |
| 110 | | `{src,lib}/**/*.ts` | .ts in src/ or lib/ | |
| 111 | |
| 112 | ## Reference |
| 113 | |
| 114 | https://code.claude.com/docs/en/memory#modular-rules-with-claude/rules/ |