> ## 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.

# ast-grep

> How CodeRabbit runs ast-grep to find code patterns and report rule matches in pull requests.

All Platforms (This feature is available on all supported platforms: GitHub, GitLab, Azure DevOps, and Bitbucket.)

[ast-grep](https://ast-grep.github.io) is an open-source static analysis tool that uses abstract syntax trees (AST) to find patterns in your codebase, helping identify security vulnerabilities and enforce code quality standards. CodeRabbit runs ast-grep on supported changed files using the essentials package and any custom rules you configure.

CodeRabbit runs ast-grep `v0.51.1`.

## Configuration

**enabled** `boolean` (default: true)

**Enable ast-grep**

**rule\_dirs** `array of string`

List of rules directories.

**util\_dirs** `array of string`

List of utils directories.

**essential\_rules** `boolean` (default: true)

Use ast-grep essentials package.

**packages** `array of string`

Predefined packages to be used.

> [tab] .coderabbit.yaml
>
> ```yaml .coderabbit.yaml theme={null}
> reviews:
>   tools:
>     ast-grep:
>       enabled: true
>       rule_dirs: []
>       util_dirs: []
>       essential_rules: true
>       packages: []
> ```

> [tab] Web UI
>
> In your organization or repository settings, go to **Reviews → Tools** and turn the tool on or off with its toggle. To change its other settings, click the settings icon next to the toggle.

`rule_dirs` lists directories with your custom ast-grep rules, and `util_dirs` lists directories with utility configs that support rule management. Both take paths relative to the repository root. `packages` takes GitHub repositories in `owner/repository` format.

Paths in `rule_dirs` and `util_dirs` must point to directories available in the reviewed commit, with matching case. CodeRabbit rejects entries that use absolute paths or parent-directory traversal, or contain control or shell-sensitive characters.

If configured directories remain unavailable after recovery attempts, CodeRabbit reports incomplete custom-rule coverage and continues with the available rule and package directories. Unavailable or unauthorized rule packages also cause an incomplete-coverage report. CodeRabbit skips scanning when no usable rule directories remain.

> [!NOTE]
>
> CodeRabbit will only run ast-grep if you have configured at least one of the following:
>
> * Custom rule directories (`rule_dirs`)
> * Essential rules enabled (`essential_rules: true`)
> * Custom packages (`packages`)
>
> `util_dirs` can be used to support shared utility configs, but by itself it does not cause ast-grep to run.
>
> CodeRabbit also skips ast-grep when the pull request contains no changed files with a supported extension. Individual files that are 8 MiB or larger are skipped.

## Links

* [ast-grep Documentation](https://ast-grep.github.io)
* [Writing ast-grep Rules](https://ast-grep.github.io/reference/yaml.html)
* [ast-grep Rule Object Properties](https://ast-grep.github.io/reference/rule.html)
* [ast-grep Essentials Package](https://github.com/coderabbitai/ast-grep-essentials)

## Files

ast-grep runs on changed files with the following extensions:

* `.bash`
* `.c`
* `.cpp`
* `.cs`
* `.css`
* `.erb` (parsed as HTML)
* `.ex`
* `.exs`
* `.go`
* `.h`
* `.hpp`
* `.hs`
* `.html`
* `.java`
* `.js`
* `.json`
* `.jsx`
* `.kt`
* `.lua`
* `.php`
* `.py`
* `.rb`
* `.rs`
* `.scala`
* `.sh`
* `.sql`
* `.swift`
* `.ts`
* `.tsx`
* `.yaml`
* `.yml`


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