# Agent Rules

> The Agent Rules are instruction files that apply to a coding agent only in specific folders or file types.

## What are rules files for AI coding agents?

The instruction files that apply only in certain parts of a project, for example rules for tests or for a 'packages/ui' folder. Keep the main instructions file short and give the agent detailed guidance only where it is relevant.

- Topic: Agent Customization
- Type: concept

## Example

Wrong:

```markdown
---
description: Testing
---
Write good tests.
```

Right:

```markdown
---
description: Rules for unit tests
globs: "**/*.test.ts"
---
- Use `vi.fn()` for mocks; do not mock modules globally.
- One `describe` per exported function.
- No real network calls: use the fixtures in `test/fixtures/`.
```

A file pattern limits the rule to test files, and concrete rules can be checked by reading the code.

## Key points

- Each rule states a concrete, checkable convention, not a vague wish.
- Rules do not contradict the main instructions file.

## Interview questions

### What is the difference between agent rules and AGENTS.md?

AGENTS.md applies to the whole project and loads at the start. Rules apply only to matching folders or files, so detailed guidance loads only when needed.

### When should I split instructions into rules?

When a section applies only to part of the code, such as tests, a UI package or database migrations, and would clutter the main file.

### Do rules files work the same in every AI tool?

No. File locations and frontmatter fields differ between tools, so check the tool's docs for the exact format.

## Related cards

- [Agent Instructions File](https://wonderium.dev/ai/agent-instructions-file.md)
- [Agent Skills](https://wonderium.dev/ai/agent-skills.md)
- [Context Engineering](https://wonderium.dev/ai/context-engineering.md)

---

- Level: [Artificial Intelligence](https://wonderium.dev/ai.md)
- HTML version: https://wonderium.dev/ai/agent-rules
- Last updated: 2026-11-25
