MCPcopy Index your code
hub / github.com/Aider-AI/grep-ast

github.com/Aider-AI/grep-ast @main

Chat with this repo
repository ↗ · DeepWiki ↗ · + Follow
19 symbols 69 edges 8 files 0 documented · 0% 2 cross-repo links
What it actually does AI analysis from the code graph — generated when you open this
loading…
README

grep-ast

Grep source code files and see matching lines with useful context that show how they fit into the code. See the loops, functions, methods, classes, etc that contain all the matching lines. Get a sense of what's inside a matched class or function definition. You see relevant code from every layer of the abstract syntax tree, above and below the matches.

By default, grep-AST recurses the current directory to search all source code files. It respects .gitignore, so it will usually "do the right thing" in most repos if you just do grep-ast <regex> without specifying any filenames.

You can also invoke grep-ast as gast for convenience.

Grep-AST is built with tree-sitter and tree-sitter-languages. So it supports a lot of popular code languages.

Install

python -m pip install git+https://github.com/paul-gauthier/grep-ast.git

Usage

Basic usage:

grep-ast [pattern] [filenames...]

Full options list:

usage: grep_ast.py [-h] [-i] [--color] [--no-color] [--encoding ENCODING] [--languages] [--verbose]
                   [pat] [filenames ...]

positional arguments:
  pat                  the pattern to search for
  filenames            the files to display

options:
  -h, --help           show this help message and exit
  -i, --ignore-case    ignore case distinctions
  --color              force color printing
  --no-color           disable color printing
  --encoding ENCODING  file encoding
  --languages          print the parsers table
  --verbose            enable verbose output

Examples

Here we search for "encoding" in the source to this tool. These results mainly highlight how grep-ast shows you how the matches fit into the code base.

aider screencast

Here we search for "TreeContext" in the source to this tool. These results mainly highlight how grep-ast helps you understand the contents of a matching named code block (class, function, method, etc).

aider screencast

Core symbols most depended-on inside this repo

add_parent_scopes
called by 3
grep_ast/grep_ast.py
get_last_line_of_scope
called by 2
grep_ast/grep_ast.py
grep
called by 1
grep_ast/grep_ast.py
add_lines_of_interest
called by 1
grep_ast/grep_ast.py
add_context
called by 1
grep_ast/grep_ast.py
add_child_context
called by 1
grep_ast/grep_ast.py
find_all_children
called by 1
grep_ast/grep_ast.py
close_small_gaps
called by 1
grep_ast/grep_ast.py

Shape

Method 11
Function 7
Class 1

Languages

Python100%

Modules by API surface

grep_ast/grep_ast.py12 symbols
grep_ast/main.py3 symbols
grep_ast/dump.py2 symbols
tests/test_parsers.py1 symbols
grep_ast/parsers.py1 symbols

Used by 2 indexed graphs manifest dependencies, hub-wide

For agents

$ claude mcp add grep-ast \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact

Ask about this repo answers extend the page