count_occurrences
Count occurrences of a text pattern across your codebase. Get total matches and file count quickly without loading files, with support for language, file, and glob filters.
Instructions
Quick statistics - count how many times a pattern occurs.
Purpose: Get total occurrence count and file count without loading any content.
Use this when:
You need quick stats ("how many times is X used?")
Checking impact before refactoring
Validating search scope
Returns: {total: count, files: count, pattern: string}
Supports: All filters (lang, file, glob, exclude, symbols)
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.
Example output: {"total": 87, "files": 12, "pattern": "CourtCase"}
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| dependencies | No | Include dependency information (imports) in results. Only extracts static imports. | |
| exclude | No | Exclude files matching patterns | |
| file | No | Filter by file path substring | |
| force | No | Force execution of potentially expensive queries (bypasses broad query detection) | |
| glob | No | Include files matching patterns | |
| kind | No | Filter by symbol kind (function, class, etc.) | |
| lang | No | Filter by language | |
| pattern | Yes | Search pattern (text to find) | |
| symbols | No | Count symbol definitions only (not usages) |