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

# ast-grep

> Search and rewrite syntax trees in the workspace.

Install `mirage-ai[ast-grep]` to load the shared Rust parser with Wasmtime.

```python theme={null}
from mirage.commands.cli.builtin.ast_grep import AST_GREP

ws.register_cli("ast-grep", AST_GREP)
```

See [setup and shell examples](https://docs.mirage.strukto.ai/home/setup/cli/ast-grep.md) for supported languages, rules and resource limits.

## Supported commands

Run `ast-grep <command> --help` for the supported flags and operands.
This list is generated from Mirage's registered command tree.

| Command | Description |
| - | - |
| `ast-grep run` | Search or rewrite a code pattern |
| `ast-grep scan` | Scan with YAML rules |
| `ast-grep outline` | Outline source symbols |

## Usage

```bash theme={null}
ast-grep -l ts -p 'console.log($ARG)' src
ast-grep scan -r rules/logging.yml src
ast-grep outline src/bytes.ts --match 'encodeText|decodeText'
```

## Behavior

The CLI reads source files and rules through the workspace VFS. A rewrite previews the edits by default and writes them when given `-U`. Set the parser’s memory ceiling on the CLI installation and the directory walk limit on the workspace. [Configuration and examples](https://docs.mirage.strukto.ai/home/setup/cli/ast-grep.md)

## License

| Project | Role in Mirage | License |
| - | - | - |
| [ast-grep](https://github.com/ast-grep/ast-grep) 0.51.3 | Rust search, rule and outline engine | [MIT](https://github.com/strukto-ai/mirage/blob/main/licenses/third_party/ast-grep.txt) |
| [Mirage](https://github.com/strukto-ai/mirage) | Command implementation | [Apache-2.0](https://github.com/strukto-ai/mirage/blob/main/LICENSE) |

See [compatibility and licenses](https://docs.mirage.strukto.ai/home/setup/clis.md#compatibility-and-licenses).


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