
Structural code search & rewrite tool
Free

ast-grep is a fast and versatile tool for structural code search, linting, and rewriting across numerous programming languages. It leverages Abstract Syntax Trees (ASTs) to provide syntax-aware search and replace capabilities, similar to grep/sed but with a deeper understanding of code structure. Unlike simple text-based search tools, ast-grep understands code semantics, enabling precise modifications and refactoring. It's built with Rust for performance and supports a wide range of languages, with the ability to add custom language support. Developers and teams benefit from its ability to automate code transformations, enforce coding standards, and identify potential bugs at scale. The tool offers a command-line interface, programmatic access via Node.js bindings, and a playground for experimentation.
ast-grep understands the syntax of your code, allowing you to search for code structures rather than just text. This means you can find and modify code based on its meaning, not just its appearance. For example, it can identify all instances of a function call with a specific argument, even if the argument's value varies.
Powered by Rust, ast-grep is designed for speed. It can process thousands of files quickly by leveraging parallel processing. This is crucial for large codebases where traditional search and replace tools can become slow and inefficient. Benchmarks show significant performance gains compared to similar tools.
ast-grep supports a wide range of programming languages out-of-the-box, including JavaScript, TypeScript, Python, Java, and more. It also allows you to add support for custom languages by integrating tree-sitter parsers. This broad language support makes it a versatile tool for diverse projects.
ast-grep provides interactive codemod capabilities, allowing you to preview and confirm changes before applying them. This feature helps prevent accidental modifications and ensures that the rewrites are correct. The playground also facilitates experimentation with patterns and rewrites.
ast-grep offers Node.js bindings, enabling programmatic access to syntax trees. This allows developers to integrate ast-grep functionality into their build processes, custom scripts, and other tools. The API provides jQuery-like utility methods for traversing syntax tree nodes.
Define custom rules for linting and code style enforcement using intuitive syntax. This allows teams to enforce specific coding standards and identify potential issues automatically. Rules can be configured using YAML or JSON files, making them easy to share and manage.
cargo install ast-grep or npm install -g @ast-grep/cli).,2. Use the command-line interface to search for code patterns. For example, ast-grep -p 'console.log($A)' searches for console.log statements.,3. Utilize the -r flag for rewriting code. For example, ast-grep -p 'console.log($A)' -r 'logger.info($A)' replaces console.log with logger.info.,4. Create rule configurations in YAML or JSON files for more complex search and replace operations, including linting rules.,5. Explore the ast-grep playground to experiment with patterns and rewrites interactively before applying them to your codebase.,6. Integrate ast-grep into your CI/CD pipeline for automated code quality checks and refactoring tasks.Developers can use ast-grep to automate repetitive refactoring tasks, such as renaming variables, updating API calls, or migrating to a new library version. For example, replace deprecated function calls across a large codebase with their new equivalents.
Teams can use ast-grep to enforce consistent code style and identify violations of coding standards. This helps improve code readability and maintainability. For instance, automatically detect and fix inconsistent use of semicolons or whitespace.
ast-grep can be used to create custom linting rules to identify potential bugs, security vulnerabilities, or code smells. For example, detect the use of unsafe functions or identify potential null pointer exceptions.
Use ast-grep to quickly search for specific code patterns across a large codebase. This is useful for understanding code dependencies, identifying areas for optimization, or assessing the impact of a code change. For example, find all instances of a specific class or function.
Software engineers benefit from ast-grep's ability to automate code refactoring, enforce coding standards, and identify potential bugs, saving time and improving code quality. They can use it to streamline their development workflow and reduce manual effort.
DevOps engineers can integrate ast-grep into CI/CD pipelines to automate code quality checks and ensure that code meets specific standards before deployment. This helps to catch issues early in the development lifecycle.
Engineering managers can use ast-grep to ensure code consistency across teams, enforce coding standards, and improve overall code quality. This helps to maintain a healthy codebase and reduce technical debt.
Open source contributors can use ast-grep to maintain and refactor large codebases, improve code quality, and ensure consistency across contributions. It simplifies the process of applying changes across a project.
Open Source (MIT License). Free to use.

Grok 4 Fast is an AI tool that excels in math and reasoning tasks while providing superior web search capabilities.


BLACKBOX IDE is an AI-powered development environment that helps you code faster and more efficiently.


Base44 is an AI-powered platform that allows users to create fully-functional apps without coding.
