> ## Documentation Index
> Fetch the complete documentation index at: https://docs.coderabbit.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Teach CodeRabbit your review rules

> Choose between path instructions, instruction documents, AST rules, code guidelines and custom checks, and add path instructions that CodeRabbit follows.

CodeRabbit reviews code with built-in logic. Instructions add your team's rules on top. You can write them in several formats, and each format fits a different job.

## Choose how to give guidance

| Format | Best for | Where it lives | Own pass or fail result | Availability |
| - | - | - | - | - |
| Path instructions | Short rules for files that match a glob | `reviews.path_instructions`, in YAML or the app | No | Wherever CodeRabbit reads your settings |
| Instruction documents | Longer rules, kept as Markdown next to your code | `.coderabbit/instructions/*.md` | No | GitHub Cloud with CodeRabbit Cloud |
| AST rules | Syntax-aware patterns | Rule files that `reviews.tools.ast-grep` points to | Reports rule matches | Essentials Plan (This feature is available on Essentials (formerly Pro), Team (formerly Pro+), Advanced, and Enterprise. Please refer to our pricing page for more information about our plans and features.) |
| Code guidelines | Standards files you already keep, such as `AGENTS.md` | Your repository, found automatically | No | See [Code guidelines](https://docs.coderabbit.ai/knowledge-base/code-guidelines.md) |
| Custom checks | A pass or fail condition on every pull request | `.coderabbit/` documents or settings | Yes | Team Plan (This feature is available on Team (formerly Pro+), Advanced, and Enterprise. Please refer to our pricing page for more information about our plans and features.) |

Instructions steer comments. They don't change which files CodeRabbit reviews. To change that, use [path filters](https://docs.coderabbit.ai/pr-reviews/which-files.md).

## Add path instructions

A path instruction is a glob pattern plus the guidance for files that match it. Each entry takes up to 20,000 characters.

**1. Pick a path**

Choose a glob such as `src/controllers/**`. Glob matching follows `Minimatch` rules, including brace expansion.

**2. Write the guidance**

Say what to check and what to flag. Concrete rules work better than general advice.

**3. Save and test**

Apply the change, open a pull request that touches a matching file, and read the review.

### Configure

> [tab] In the app
>
> Open **Review settings**, choose **Organization defaults** or a repository, and set **View mode** to **All Settings**. Go to **Reviews > General** and find **Path instructions**. Select **Apply changes** and confirm.

> [tab] YAML V2
>
> ```yaml .coderabbit.yaml theme={null}
> reviews:
>   path_instructions:
>     - path: "src/controllers/**"
>       instructions: |
>         Check that each controller validates input and checks authorization.
>         Flag direct database queries that bypass the data access layer.
>     - path: "tests/**"
>       instructions: |
>         Review the following unit test code written using the Mocha test library. Ensure that:
>         - The code adheres to best practices associated with Mocha.
>         - Descriptive test names are used to clearly convey the intent of each test.
>         - Edge cases and error paths are covered.
>     - path: "docs/**/*.md"
>       instructions: |
>         Check for clarity, accuracy, and completeness.
>         Flag any references to deprecated APIs or outdated behavior.
> ```

> [tab] YAML V3
>
> Early Access (This feature is in early access. Enable it by setting `early_access: true` in your `.coderabbit.yaml`, or by toggling Early Access on the web interface.)
>
> V3 is a limited preview. Adding `version: 3` doesn't give your organization access.
>
> V3 has no `reviews.path_instructions` key, and a V3 file that sets it fails validation. Store each instruction as a Markdown document in `.coderabbit/instructions/` instead.
>
> ```markdown .coderabbit/instructions/controllers.md theme={null}
> ---
> id: controller-security
> name: Controller security
> paths:
>   - "src/controllers/**"
> ---
> Check that each controller validates input and checks authorization.
> Flag direct database queries that bypass the data access layer.
> ```

## Store instructions as documents

Instruction documents keep the same guidance as Markdown files with front matter. They apply alongside inline YAML entries, and you can use both. A document has no `mode` or `report` field, so it guides the review without its own check result. Use a custom check when you want one.

For the front matter fields, documents in nested directories, and moving entries out of YAML, see [Instruction and check documents](https://docs.coderabbit.ai/configuration/documents.md).

## Generate path instructions from past reviews

Comment `@coderabbitai emit path instructions` on a pull request. CodeRabbit collects suggestions from the past 7 days and opens a pull request that adds them to `.coderabbit.yaml` without overwriting existing entries. See the [command reference](https://docs.coderabbit.ai/reference/review-commands.md#emit-path-instructions).

## Add syntax-aware rules with ast-grep

ast-grep rules match code by its syntax tree instead of by path. Each rule is a YAML file that sets its own language and pattern, and you point CodeRabbit at your rule directories or shared rule packages under `reviews.tools.ast-grep`. CodeRabbit runs the rules during automated reviews, not in chat. See [ast-grep](https://docs.coderabbit.ai/tools/ast-grep.md) to write rules, use packages, and check the supported file types.

## Limits and availability

* Each path instruction is limited to 20,000 characters.
* CodeRabbit inserts instruction text into the review as you wrote it. Backticks, `${}` and backslashes aren't interpreted or removed.
* Only the `path` glob is parsed. If a glob is invalid, CodeRabbit skips that entry.
* Path instructions don't affect other features that read the same code. [Unit test generation](https://docs.coderabbit.ai/finishing-touches/unit-test-generation.md) has its own `code_generation.unit_tests.path_instructions` list.
* A path instruction that matches a guideline file such as `CLAUDE.md` applies only when a pull request changes that file. It doesn't load the file as a guideline. Use [code guidelines](https://docs.coderabbit.ai/knowledge-base/code-guidelines.md).
* Schema V3 is a limited preview.

## Troubleshoot

* An instruction has no visible effect: confirm the file matched the glob and wasn't removed by [path filters](https://docs.coderabbit.ai/pr-reviews/which-files.md), then print the resolved settings with [Check which configuration a review used](https://docs.coderabbit.ai/configuration/guides/check-effective-configuration.md).
* Both a YAML entry and a document cover the same files: CodeRabbit applies both. Remove the one you no longer want.

**All settings:** [`reviews.path_instructions`](https://docs.coderabbit.ai/reference/configuration#param-reviews-path-instructions) and [`reviews.tools.ast-grep`](https://docs.coderabbit.ai/reference/configuration#param-reviews-tools-ast-grep) in the configuration reference.

## What's next

> [card] [Write review instructions that work](https://docs.coderabbit.ai/configuration/guides/write-instructions.md)
>
> Turn a vague rule into one CodeRabbit follows.

> [card] [Instruction and check documents](https://docs.coderabbit.ai/configuration/documents.md)
>
> Put instructions in `.coderabbit/`.

> [card] [Code guidelines](https://docs.coderabbit.ai/knowledge-base/code-guidelines.md)
>
> Reuse the standards files your team already keeps.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.