# osgrep

> Local, grep-style semantic code search built for coding agents

- Category: Retrieval & Knowledge (RAG) / Code Indexing & Search
- Language: TypeScript
- Licence: Apache-2.0
- Repository: https://github.com/Ryandonofrio3/osgrep
- Canonical page: https://ai-tldr.dev/tools/osgrep/

## In short

osgrep is a command-line tool for natural-language code search that works like `grep`. Instead of matching exact strings, it finds concepts — a query such as "where do transactions get created?" returns the code that does it, even if no line contains those words. It sits in the Code Indexing & Search category of the Retrieval & Knowledge (RAG) tools and is open-source, written in TypeScript and licensed Apache-2.0.

## Overview

osgrep is a command-line tool for natural-language code search that works like `grep`. Instead of matching exact strings, it finds concepts — a query such as "where do transactions get created?" returns the code that does it, even if no line contains those words. The project describes it as fast, local and built for coding agents, and it is built on the foundation of MixedBread's mgrep.

Everything runs on your machine: embeddings are computed locally with `onnxruntime-node`, code is split into functions and classes with tree-sitter grammars, and chunks are stored in LanceDB under `~/.osgrep/data`. The first search in a repository indexes it automatically, and each repository gets its own isolated index derived from its Git remote or directory name. Searches query code and docs separately and rerank the results with ColBERT, and an optional background server (`osgrep serve`) keeps the index hot in memory and re-indexes files as they change.

Beyond search, osgrep traces call graphs (who calls a function and what it calls), labels results by role — `ORCHESTRATION` for high-level logic, `DEFINITION` for types and classes — and can print a compressed "skeleton" of a file that keeps signatures and elides function bodies. It ships one-command installers for Claude Code and OpenCode plugins whose hooks start and stop the server per session. In the project's own benchmarks, osgrep saves about 20% of LLM tokens and delivers a 30% speedup.

## What it does

- Semantic, grep-style search with flags for result count, matches per file, full chunk content, relevance scores, minimum score and file-paths-only output
- Call-graph tracing with `osgrep trace` and a symbol listing with `osgrep symbols`
- Role detection that separates `ORCHESTRATION` code from `DEFINITION` code so agents know where to read first
- `osgrep skeleton` output that shows a file's signatures and structure without function bodies
- 100% local embeddings, tree-sitter chunking for languages including TypeScript, Python, Go, Rust, Java, C# and C/C++, and automatic per-repository indexes that respect `.gitignore` and `.osgrepignore`
- A live-reloading HTTP server (`osgrep serve`) plus Claude Code and OpenCode plugins that start it automatically

## Getting started

osgrep installs from npm. Download the embedding models once, then run searches from inside any repository — the first search builds that repository's index.

1. Install the CLI

```bash
npm install -g osgrep
```

2. Download the models (recommended)

   Fetches the embedding models (~150MB) upfront; if you skip this, they download on first use.

```bash
osgrep setup
```

3. Search a repository

   The first search indexes the repository automatically. Add `--scores --min-score 0.5` to filter low-confidence matches, or `--compact` for file paths only.

```bash
cd my-repo
osgrep "where do we handle authentication?"
```

4. Trace calls and inspect structure

   See a function's upstream and downstream dependencies, or print a file's skeleton.

```bash
osgrep trace "function_name"
osgrep skeleton src/lib/auth.ts
```

5. Connect your coding agent

   Install the Claude Code or OpenCode plugin. Indexing the codebase first (`osgrep index`) is recommended; the plugin's hooks start `osgrep serve` in the background and stop it when the session ends.

```bash
osgrep install-claude-code
# or
osgrep install-opencode
```

## When to use it

- Give Claude Code or OpenCode a semantic search tool so it spends fewer tokens hunting for relevant code
- Find code by what it does in an unfamiliar codebase without knowing function or file names
- Check who calls a function and what it calls before changing it
- Search private code with embeddings computed entirely on your own machine
