{"id":3506,"library":"grep-ast","title":"grep-ast","description":"grep-ast is a command-line tool designed to search through the Abstract Syntax Tree (AST) of source code files. Unlike traditional `grep` which operates on text, `grep-ast` provides a context-aware output, showing how matching lines fit into the broader code structure (functions, classes, etc.). It leverages `tree-sitter` and `tree-sitter-languages` for parsing various programming languages. The current version is 0.9.0, released in May 2025.","status":"active","version":"0.9.0","language":"en","source_language":"en","source_url":"https://github.com/paul-gauthier/grep-ast","tags":["AST","grep","code analysis","cli","tree-sitter","developer tool"],"install":[{"cmd":"pip install grep-ast","lang":"bash","label":"Install via pip"}],"dependencies":[{"reason":"Core parsing engine for AST generation, though not directly declared as a Python dependency on PyPI, it's fundamental to its operation.","package":"tree-sitter","optional":false},{"reason":"Provides language-specific parsers used by tree-sitter for diverse language support.","package":"tree-sitter-languages","optional":false}],"imports":[],"quickstart":{"code":"grep-ast \"function_name\" my_module.py\ngrep-ast \"class MyClass\" .","lang":"bash","description":"To quickly search for a pattern in a specific file or recursively in the current directory, use the `grep-ast` command followed by your pattern and optional filenames or paths. By default, it respects .gitignore. You can also use `gast` as an alias."},"warnings":[{"fix":"Ensure you are using the correct tool for your desired functionality; if you need AST-pattern matching or rewriting, consider `ast-grep` or `ast-grep-py`.","message":"This `grep-ast` tool is distinct from the `ast-grep` (Rust-based) project, despite similar names and AST-related functionality. `grep-ast` focuses on text-based regex search with AST-aware output, while `ast-grep` (and its Python binding `ast-grep-py`) uses AST patterns for search and rewrite.","severity":"gotcha","affected_versions":"All"},{"fix":"Formulate your patterns as standard regular expressions. If you require matching against the structural properties of the AST directly, tools like `ast-grep` are designed for that.","message":"The search patterns provided to `grep-ast` are regular expressions applied to the *text* of the code, not directly to AST nodes. The AST is used to provide context for the matched text lines, not for pattern matching itself.","severity":"gotcha","affected_versions":"All"},{"fix":"Explicitly specify target files or directories to limit the search scope. Use the `--no-gitignore` option if you need to bypass `.gitignore` filtering (check the latest CLI options for availability).","message":"By default, `grep-ast` recursively searches the current directory and respects `.gitignore`. This might lead to unexpected results if you intend to search files outside the Git repository's scope or want to override `.gitignore` rules.","severity":"gotcha","affected_versions":"All"}],"env_vars":null,"last_verified":"2026-04-11T00:00:00.000Z","next_check":"2026-07-10T00:00:00.000Z"}