---
source: CrewKit documentation
url: https://crewkit.io/docs/rules.md
title: "Rules"
description: "Path-based rules that auto-load context for Claude Code."
---


Rules are markdown files that provide context and constraints to Claude Code. They auto-load based on file paths — edit a backend route handler and the backend rules kick in automatically.

---

## How rules work

Rules live in `.claude/rules/` and are scoped by file path patterns. When Claude Code is working on a file, matching rules are injected into context.

```
.claude/rules/
├── backend.md      # Loaded when editing backend/**/*
├── web.md          # Loaded when editing web/**/*
├── mobile.md       # Loaded when editing mobile/**/*
└── general.md      # Loaded for all files
```

---

## Rule file format

Rules are plain markdown. No special frontmatter required.

```markdown
# Backend Rules

## Tech Stack
- Express (JSON API endpoints)
- MySQL 8
- Jest for testing

## Patterns
- Route handlers are thin — business logic lives in services
- Authorization checks live in middleware, not handlers
- All queries scoped to the current account
```

---

## Path-based auto-loading

crewkit uses the file path pattern in the rule name to determine when to load it:

| Rule file | Loaded when editing |
|-----------|-------------------|
| `backend.md` | Files under `backend/` |
| `web.md` | Files under `web/` |
| `mobile.md` | Files under `mobile/` |
| `general.md` | All files |

The routing is the file name, nothing else — crewkit writes no configuration block for it. If you want the mapping spelled out for your agent, write it in your own project instructions by hand:

```markdown
> Component-specific rules auto-load by path:
> `backend/**/*` -> `.claude/rules/backend.md`
> `web/**/*` -> `.claude/rules/web.md`
> `mobile/**/*` -> `.claude/rules/mobile.md`
```

---

## Sync behavior

Rules sync the same way as agents — fetched from the API, written to `.claude/rules/`, checksummed to avoid overwriting local edits.

---

## Rule tiers

Rules can exist at platform, organization, or project level. See [Inheritance](/docs/inheritance).

---

## Next steps

- [Commands](/docs/commands)
- [Agents](/docs/agents)
- [Inheritance](/docs/inheritance)
