search_code
Perform full-text or symbol-only searches to find code definitions and usages, returning line numbers and code previews.
Instructions
Full-text or symbol-only code search with detailed results.
When to use search_regex instead:
Patterns with special characters: -> :: () [] {} . * + ? \ | ^ $
Complex pattern matching: wildcards, alternation, anchors
Examples: '->with(', '::new', 'function*', '[derive]', 'fn (get|set)_.*'
Search modes:
Full-text (default): Finds ALL occurrences - definitions + usages
Symbol-only (symbols=true): Finds ONLY definitions where symbols are declared
Use this for:
Simple text patterns (alphanumeric, underscores, hyphens)
Detailed analysis with line numbers and code previews
Symbol definition searches
Pagination: Check response.pagination.has_more. If true, use offset parameter to fetch next page.
Error Handling: If you receive an error message containing "Index not found" or "stale", immediately call the index_project tool, wait for it to complete, then retry this operation.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| dependencies | No | Include dependency information (imports) in results. **IMPORTANT:** Currently only supported for Rust files — passing this with any other language (typescript, python, go, etc.) will produce no dependency data. Only extracts static imports (string literals); dynamic imports are filtered. See CLAUDE.md for details. | |
| exact | No | Exact match (no substring matching) | |
| exclude | No | Exclude files matching glob patterns (e.g., 'target/**') | |
| expand | No | Show full symbol body (not just signature) | |
| file | No | Filter by file path (substring) | |
| force | No | Force execution of potentially expensive queries (bypasses broad query detection) | |
| glob | No | Include files matching glob patterns (e.g., 'src/**/*.rs') | |
| kind | No | Filter by symbol kind (function, class, struct, etc.) | |
| lang | No | Filter by language (rust, typescript, python, etc.) | |
| limit | No | Maximum results per page (default: 100). IMPORTANT: If response.pagination.has_more is true, you MUST fetch more pages using offset parameter. | |
| offset | No | Pagination offset (skip first N results). ALWAYS paginate when has_more=true. Example: First call offset=0, second call offset=100, third offset=200, etc. | |
| paths | No | Return only unique file paths (not full results) | |
| pattern | Yes | Search pattern (text to find) | |
| preview_length | No | Maximum characters per preview line (default: 180). Use a smaller value (e.g. 60) for wide-result scans where short previews are sufficient. | |
| symbols | No | Symbol-only search (definitions, not usage) |