Back to Skills

creating-rules

verified

Creates Claude Code rules (.claude/rules/*.md) with YAML frontmatter and path-specific scoping. Use when creating project rules, coding standards, or conditional guidelines for specific file types.

View on GitHub

Marketplace

my-marketplace

kkhys/claude-code-marketplace

Plugin

base

Repository

kkhys/claude-code-marketplace
1stars

plugins/base/skills/creating-rules/SKILL.md

Last Verified

January 21, 2026

Install Skill

Select agents to install to:

Scope:
npx add-skill https://github.com/kkhys/claude-code-marketplace/blob/main/plugins/base/skills/creating-rules/SKILL.md -a claude-code --skill creating-rules

Installation paths:

Claude
.claude/skills/creating-rules/
Powered by add-skill CLI

Instructions

# Creating Claude Code Rules

Create modular, focused rules for `.claude/rules/` directory.

## Quick Start

**First, ask the user**:
- Rule scope: global (all files) or path-specific (certain file types)?
- Location: `.claude/rules/` (project) or `~/.claude/rules/` (personal)?

Then create a `.md` file:

```markdown
---
paths: src/**/*.ts
---

# TypeScript Guidelines

- Use strict mode
- Prefer interfaces over type aliases for object shapes
- Use explicit return types for exported functions
```

## Rule File Structure

### Global Rules (No Frontmatter)

Apply to all files:

```markdown
# Code Style

- Use 2-space indentation
- Prefer const over let
- No unused variables
```

### Path-Specific Rules (With Frontmatter)

Apply only when Claude works with matching files:

```markdown
---
paths: src/api/**/*.ts
---

# API Development Rules

- All endpoints must include input validation
- Use standard error response format
- Include OpenAPI documentation comments
```

## YAML Frontmatter

### `paths` Field

Single pattern:
```yaml
paths: src/**/*.ts
```

Multiple patterns with brace expansion:
```yaml
paths: src/**/*.{ts,tsx}
```

Comma-separated patterns:
```yaml
paths: {src,lib}/**/*.ts, tests/**/*.test.ts
```

### Glob Patterns Reference

| Pattern | Matches |
|---------|---------|
| `**/*.ts` | All TypeScript files anywhere |
| `src/**/*` | All files under `src/` |
| `*.md` | Markdown files in project root only |
| `src/components/*.tsx` | React components in specific directory |
| `**/*.{ts,tsx}` | TypeScript and TSX files |
| `{src,lib}/**/*.ts` | TypeScript in `src/` or `lib/` |

## Directory Organization

### Basic Structure

```
.claude/rules/
├── code-style.md      # General coding standards
├── testing.md         # Testing conventions
└── security.md        # Security requirements
```

### With Subdirectories

```
.claude/rules/
├── frontend/
│   ├── react.md
│   └── styles.md
├── backend/
│   ├── api.md
│   └── database.md
└── general.md
```

All `.md` files 

Validation Details

Front Matter
Required Fields
Valid Name Format
Valid Description
Has Sections
Allowed Tools
Instruction Length:
5298 chars