# Rules

Write always-on instructions the AI follows in your project, and scope rules to the files they apply to.

Rules are markdown files in your project that tell the AI how to work. They are added to every conversation in the project.

Settings open on Customize, Rules chip, with the Project Rules editor and the Rule Files list.

## What you can do

- Write project rules that apply to every task.
- Add rule files for topics, and limit them to some files with a path pattern.
- Share content between rule files with an include line.

## Where rules live

| File                       | When it applies                                                                   |
| -------------------------- | --------------------------------------------------------------------------------- |
| `.lyna_ai/rules.md`        | Every turn, in every conversation.                                                |
| `.lyna_ai/rules/<name>.md` | Every turn, or only when matching files are involved if it has a `paths` pattern. |

## Write project rules

1. ### Open Rules

   Open **Settings > AI > Customize** and pick the **Rules** chip. You can also type `/rules` in the chat.
2. ### Edit Project Rules

   Type your rules in **Project Rules**. They are saved automatically (**Auto-saved**).

   ```markdown
   # Project rules

   - Style with Tailwind CSS utility classes. Do not add CSS files.
   - Use TypeScript. Never use the any type.
   - Keep components small. Prefer function components and hooks.
   ```
3. ### Add rule files (optional)

   Under **Rule Files**, choose **Add Rule File**, enter a name and create it. Edit or delete files from the same list.

## Scope a rule to some files

Add a `paths` block at the top of a rule file. The rule then applies only when a matching file is in play.

```markdown
---
paths: src/routes/**, src/components/**/*.tsx
---

# Routing conventions

- Load page data in the route's loader, not in an effect.
- Read route data with useLoaderData.
```

A rule file without `paths` applies everywhere.

## Share content between rules

Inside a rule file, include another text file:

```markdown
@include ./shared/naming.md
```

Includes are relative to the rule file and can nest up to five levels.

> [!NOTE]
>
> **Rules are always on**
>
> Rules are added to every conversation, so keep them short. Put deep, task-specific guidance in a [skill](/features/ai/skills) instead: it loads only when needed.

## Tips

- Write each rule as a short, testable order.
- Keep universal rules in `rules.md` and situational ones in scoped files.
- Ask the AI to write a rule for you with `/newrule`.

## Related

- [Skills](/features/ai/skills): Guidance loaded on demand.
- [Knowledge and memory](/features/ai/knowledge-and-memory): Product facts and preferences.
- [Hooks](/features/ai/hooks): Run checks automatically.
