Search Code
searchFind code matches across files using regex, literal text, or AST patterns; returns paginated results and supports hybrid filtering for large codebases.
Instructions
Search code across files using ripgrep ('regex' default, 'text'), ast-grep ('ast' pattern, 'ast_rule' YAML rule), or 'hybrid' (ripgrep pre-filter + ast-grep for large repos). Returns paginated results with a 'searchId' when total matches exceed 'limit'. Prefer 'find_symbols' when you want structured symbol tables or a single-file outline, and 'count' when you only need match counts.
Tool call template
This tool declares no required parameters. Add optional parameters from the input schema as needed.
{
"id": 1,
"jsonrpc": "2.0",
"method": "tools/call",
"params": {
"arguments": {},
"name": "search"
}
}Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| path | No | File or directory to search in (relative to workspace root or absolute; default: '.'). | . |
| type | No | Search mode: 'regex' (default, ripgrep regex), 'text' (exact literal match), 'ast' (structural AST pattern), 'ast_rule' (YAML rule with relational checks like inside/has/not), or 'hybrid' (ripgrep pre-filter + ast-grep for large repos). | regex |
| limit | No | Maximum matches to return per page (1-500, default: 50). | |
| query | No | Required for a new search (omit when using 'searchId'). Interpretation depends on 'type': PCRE2/Rust regex ('regex'), literal substring ('text'), ast-grep code pattern with $VAR / $$$ARGS ('ast'/'hybrid'), or YAML rule with id/language/rule ('ast_rule'). | |
| offset | No | 1-based starting match index for pagination (default: 1). | |
| context | No | [regex/text only] Number of context lines before and after each match (0-20). | |
| language | No | [ast/hybrid only] Target language (e.g. 'typescript', 'tsx', 'javascript', 'python', 'rust', 'go', 'java'). Auto-detected from extension when 'path' is a single file; pass explicitly when searching a directory to avoid multi-language ambiguity. | |
| noIgnore | No | If true, also search files ignored by .gitignore. Default: false (respects .gitignore). | |
| searchId | No | Pagination ID (e.g. 's_a1b2c3d4') returned by a previous search when results exceeded 'limit'. When provided, omit 'query' and pass 'offset'/'limit' to read cached results instantly. | |
| multiline | No | [regex/text only] Allow pattern to match across multiple lines. | |
| wordMatch | No | [regex/text] Match whole words only. | |
| filePattern | No | Glob pattern(s) to include, comma-separated, e.g. '*.{ts,tsx}' or 'src/**/*.py'. | |
| outputFormat | No | Output format: 'content' (default, file:line + full match text), 'compact' (file:line: first-line snippet), 'files_only' (unique file paths), 'json' (structured JSON). | content |
| caseSensitive | No | [regex/text/hybrid] Force case-sensitive (true) or case-insensitive (false). Omitting uses smart-case (insensitive unless query has uppercase). | |
| includeHidden | No | Include hidden dotfiles and dot-directories (excludes .git unless noIgnore is true). | |
| excludePattern | No | Comma-separated glob patterns to exclude, e.g. '**/dist/**,**/*.test.ts'. |