# ast-grep

> A CLI tool for code structural search, lint and rewriting

Source: https://talira.ai/catalog/ast-grep-5ehppe4z
Every listing: https://talira.ai/catalog.md

- Kind: Open source
- Types: Command-line tool
- Categories: [developer tools / cli / search](https://talira.ai/categories/developer-tools/cli/search), [developer tools / code quality / refactoring](https://talira.ai/categories/developer-tools/code-quality/refactoring)
- Platforms: macos, linux, windows, cli
- Licence: MIT
- Pricing: Free and open source
- Free tier: yes
- Self-hostable: yes

ast-grep (sg) searches code by syntax tree pattern rather than text: you write a pattern as ordinary code with $METAVARIABLE wildcards and it matches every node with the same structure. It can rewrite matches, run YAML lint rules, and installs from npm, pip, cargo, [Homebrew](https://talira.ai/catalog/homebrew-djy17yn9.md) and others. It is written in Rust on tree-sitter.

## Links

- Website: https://ast-grep.github.io/
- GitHub: https://github.com/ast-grep/ast-grep
- Docs: https://ast-grep.github.io/

## Ways to install

### Package managers

- [Homebrew](https://talira.ai/catalog/homebrew-djy17yn9.md): <https://formulae.brew.sh/formula/ast-grep>[^1]
- [mise](https://talira.ai/catalog/mise-0axr08xw.md): <https://mise-versions.jdx.dev/tools/ast-grep>[^2]

## Problems it solves

- find every call to a function with a specific argument shape, regex keeps matching the wrong things
- rewrite an API usage across thousands of files safely
- grep cannot tell code from comments and strings
- write custom lint rules for our codebase without writing an ESLint plugin
- codemod that works for many languages, not just JavaScript
- search for code patterns that span multiple lines
- let my AI agent do structural search and replace reliably
- enforce banned patterns in CI with simple rule files

## Features

- pattern code with metavariables
- rewrite
- YAML lint rules
- many languages
- playground
- npm/pip/cargo installs

## Capabilities

- Has a command line tool: plan not known

## Trust

Overall: 0.70 out of 1.
Signals: maintenance 1.00, adoption 0.84, momentum 0.76, community 0.81, backing 0.00, extensibility 0.20.

- last commit 9 days ago
- 166 commits in the last 90 days
- latest release 0.51.2 13 days ago
- 16.6k GitHub stars
- 105 contributors
- accepts sponsorship (Github)

## Alternatives

- [Semgrep](https://talira.ai/catalog/semgrep-v0kqhvdn.md): Code security: SAST, supply chain and secrets scanning with rules that look like code
- [ripgrep](https://talira.ai/catalog/ripgrep-q15ax1wq.md): Searches directories recursively for a regex pattern, skipping gitignored files
- [The Silver Searcher](https://talira.ai/catalog/the-silver-searcher-rntejqw7.md): A code-searching tool similar to ack, but faster
- [Renamify](https://talira.ai/catalog/renamify-s89ngahq.md): Smart search & replace for code and files with case-aware transformations and built-in undo/redo

## Sources

[^1]: https://formulae.brew.sh/api/formula.json (checked 21 Nov 2026)
[^2]: https://mise-versions.jdx.dev/tools.json (checked 21 Nov 2026)
