# grepai

> Local semantic code search and call graphs for AI agents

- Category: Retrieval & Knowledge (RAG) / Code Indexing & Search
- Language: Go
- Licence: MIT
- Repository: https://github.com/yoanbernabeu/grepai
- Website: https://yoanbernabeu.github.io/grepai/
- Canonical page: https://ai-tldr.dev/tools/grepai/

## In short

grepai is Local semantic code search and call graphs for AI agents. Its stated aim is to cut the input tokens an AI coding agent spends by handing it relevant context instead of raw search results. It sits in the Code Indexing & Search category of the Retrieval & Knowledge (RAG) tools and is open-source, written in Go and licensed MIT.

## Overview

grepai is a privacy-first command-line tool for semantic code search — the project calls it "grep for the AI era". Where `grep` and `ripgrep` match exact text or regex, grepai embeds your code as vectors so a query such as "authentication logic" can find a function named `handleUserSession`, even when naming conventions vary. Its stated aim is to cut the input tokens an AI coding agent spends by handing it relevant context instead of raw search results.

Everything runs locally by default. `grepai init` creates a `.grepai/` directory with a `config.yaml`, and `grepai watch` scans the codebase, splits files into chunks, embeds each chunk and stores the vectors, then keeps watching for file changes so the index stays fresh. Embeddings come from Ollama (default model `nomic-embed-text`), LM Studio, or OpenAI; vectors live in a file-based GOB store by default, with PostgreSQL + pgvector or Qdrant as options for larger codebases and teams.

Beyond search, grepai traces call graphs — who calls a function, what it calls, and a depth-limited graph around it — using fast regex extraction by default or tree-sitter parsing in a precise mode. It exposes all of this to agents as an MCP server (`grepai mcp-serve`) with tools for search, tracing, property reads/writes, and an opt-in Repository Planning Graph that links files, symbols, chunks and feature hierarchy nodes. In a benchmark run by the maintainer on the Excalidraw repository with Claude Code, the project reports 97% fewer input tokens and 27.5% lower API cost than plain grep, and notes that results may differ on other codebases.

## What it does

- Natural-language search over a local vector index, with optional hybrid search that fuses vector and keyword results via Reciprocal Rank Fusion
- Call-graph tracing: `trace callers`, `trace callees` and `trace graph --depth`, plus `refs` for property and state readers/writers
- File watcher that re-indexes changed files automatically
- Pluggable embedders (Ollama, LM Studio, OpenAI) and vector stores (GOB file, PostgreSQL + pgvector, Qdrant)
- MCP server for Claude Code, Cursor, Windsurf and other MCP clients, and `agent-setup` to add grepai instructions to CLAUDE.md, AGENTS.md, GEMINI.md or Cursor/Windsurf rules
- Workspaces that index and search several projects through one shared vector store

## Getting started

Install the binary, pull an embedding model, then initialise and index a project. Ollama is the default embedding provider; LM Studio and OpenAI also work.

1. Install grepai

   Homebrew on macOS, the install script on Linux/macOS, or the PowerShell script on Windows.

```bash
brew install yoanbernabeu/tap/grepai
# or
curl -sSL https://raw.githubusercontent.com/yoanbernabeu/grepai/main/install.sh | sh
```

2. Pull an embedding model

   With Ollama, the recommended provider, pull the default embedding model.

```bash
ollama pull nomic-embed-text
```

3. Initialise and index your project

   `init` writes `.grepai/config.yaml`; `watch` builds the index and keeps it updated as files change.

```bash
cd /path/to/your/project
grepai init
grepai watch
```

4. Search and trace

   Query by meaning, then check who depends on a function before changing it.

```bash
grepai search "error handling"
grepai trace callers "Login"
grepai trace graph "ProcessOrder" --depth 3
```

5. Give your agent access

   Register grepai as an MCP server in Claude Code; Cursor, Windsurf and Opencode use the same `grepai mcp-serve` command in their MCP config.

```bash
claude mcp add grepai -- grepai mcp-serve
```

## When to use it

- Let a coding agent find relevant code by intent instead of reading whole files, to cut its input tokens
- Check a function's callers and callees before a refactor
- Search an unfamiliar codebase in plain English without guessing its function names
- Search across several services or a monorepo from one workspace, without sending code to a cloud service
