█

AI/TLDR

Buy me a coffee
Buy me a coffee

osgrep

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

Code Indexing & SearchOpen source
Language
TypeScript
License
Apache-2.0
$npm install -g osgrep
IN SHORT

What is osgrep?

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.

Bar charts comparing a baseline with osgrep on average time per query, average cost per query and LLM preference
The project's benchmark: average time per query 157.1s vs 100.2s, average cost per query $0.369 vs $0.285, and LLM preference 7 wins for osgrep, 2 for the baseline and 1 tie.osgrep README ↗

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.

Install the CLI

bashbash
npm install -g osgrep

Download the models (recommended)

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

bashbash
osgrep setup

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.

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

Trace calls and inspect structure

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

bashbash
osgrep trace "function_name"
osgrep skeleton src/lib/auth.ts

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.

bashbash
osgrep install-claude-code
# or
osgrep install-opencode

Commands and code are distilled from the project's own documentation — always check the official repo for the latest.

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

How osgrep compares

osgrep alongside other open-source code indexing & search tools AI/TLDR tracks, ranked by GitHub stars.

ToolStarsWhat it does
CodeGraph★ 79.3kBuilds a local SQLite knowledge graph of a codebase with a Rust tree-sitter kernel, keeps it in sync through a file watcher, and serves symbols, call paths and blast radius to coding agents over MCP.
codebase-memory-mcp★ 49.4kA native MCP server that indexes a repository into a persistent tree-sitter knowledge graph of functions, call chains and routes, queried by agents through 15 tools.
GitNexus★ 49kIndexes a codebase into a knowledge graph of dependencies, call chains and execution flows, then exposes it to Claude Code, Cursor and Codex through MCP tools.
code-review-graph★ 33kA local-first code intelligence graph built with Tree-sitter that serves precise, incrementally-updated structural context to AI coding tools over MCP, so they read only the code a task needs.
XERJ★ 22.9kSingle-binary, Elasticsearch-compatible search engine whose autoindex command turns any folder of code, docs, logs or PDFs into typed indices that AI coding agents query via CLI or MCP instead of grepping.
Claude Context★ 12.7kAn MCP server that indexes your codebase into a vector database so AI coding agents can find relevant code by meaning instead of loading whole folders.
Graft★ 11.6kBuilds a persistent knowledge graph of your codebase as linked markdown files, then feeds the matching nodes to coding agents so they stop re-exploring the repo on every task.
osgrep★ 1.2kLocal, grep-style semantic code search built for coding agents