# grep_search

> **Function** in `langchain_anthropic`

📖 [View in docs](https://reference.langchain.com/python/langchain-anthropic/middleware/file_search/StateFileSearchMiddleware/__init__/grep_search)

Fast content search tool that works with any codebase size.

Searches file contents using regular expressions.

Supports full regex syntax and filters files by pattern with the include
parameter.

## Signature

```python
grep_search(
    runtime: ToolRuntime[None, AnthropicToolsState],
    pattern: str,
    path: str = '/',
    include: str | None = None,
    output_mode: Literal['files_with_matches', 'content', 'count'] = 'files_with_matches',
) -> str
```

## Parameters

| Name | Type | Required | Description |
|------|------|----------|-------------|
| `pattern` | `str` | Yes | The regular expression pattern to search for in file contents. |
| `path` | `str` | No | The directory to search in. If not specified, searches from root. (default: `'/'`) |
| `include` | `str \| None` | No | File pattern to filter (e.g., `'*.js'`, `'*.{ts,tsx}'`). (default: `None`) |
| `output_mode` | `Literal['files_with_matches', 'content', 'count']` | No | Output format.  Options:  - `'files_with_matches'`: Only file paths containing matches - `'content'`: Matching lines with file:line:content format - `'count'`: Count of matches per file (default: `'files_with_matches'`) |

## Returns

`str`

Search results formatted according to `output_mode`.

Returns `'No matches found'` if no results.

---

[View source on GitHub](https://github.com/langchain-ai/langchain/blob/8fec4e7ceee2c368b068c49f9fed453276e210e7/libs/partners/anthropic/langchain_anthropic/middleware/file_search.py#L159)