search_ast
Search codebase for code structure using Tree-sitter AST patterns. Scans all files to match structural elements like functions or classes. Requires glob to limit scope.
Instructions
Structure-aware search using Tree-sitter AST patterns (S-expressions). ⚠️ SLOW: bypasses trigram optimization and scans the ENTIRE codebase (500ms-10s+). In 95% of cases, prefer search_code with symbols: true instead (10-100x faster).
Use this only when you must match code structure rather than text: "all async functions containing a match expression", "every class with a serialize method", etc. You MUST pass glob to limit scope — without it, every file in the codebase is parsed.
Example patterns — Rust: (function_item) @fn; Python: (function_definition) @fn; TypeScript: (class_declaration) @class. Refer to Tree-sitter grammar docs for each language. On "Index not found" / "stale" error, call index_project, then retry.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| file | No | Filter by file path (substring) | |
| glob | No | Include files matching glob patterns (STRONGLY RECOMMENDED to limit scope, e.g., ['src/**/*.rs']) | |
| lang | Yes | Language (REQUIRED: rust, typescript, javascript, python, go, java, c, cpp, csharp, php, ruby, kotlin, zig) | |
| force | No | Force execution of potentially expensive queries (bypasses broad query detection) | |
| limit | No | Maximum number of results (use with offset for pagination) | |
| paths | No | Return only unique file paths | |
| offset | No | Pagination offset (skip first N results after sorting) | |
| exclude | No | Exclude files matching glob patterns (e.g., ['target/**', 'node_modules/**']) | |
| pattern | Yes | AST pattern (Tree-sitter S-expression, e.g., '(function_item) @fn') | |
| dependencies | No | Include dependency information (imports) in results. Only extracts static imports. |