What osgrep does and how it differs from grep
maingrep or ripgrep are used for fast, exact string matching, osgrep is used for concept matching—finding code based on intent (e.g., "where do we handle auth?").repository·main·Indexed 22 days ago
https://github.com/ryandonofrio3/osgrepA semantic, natural-language search tool for codebases designed for developers and coding agents. osgrep uses local embeddings via onnxruntime-node and TreeSitter for context-aware searching, call graph tracing, and symbol listing. It includes features such as code skeleton generation to reduce LLM token usage, a background server for fast responses, and plugins for Claude Code and Opencode.
grep or ripgrep are used for fast, exact string matching, osgrep is used for concept matching—finding code based on intent (e.g., "where do we handle auth?").osgrep automatically isolates repositories into unique indices (stores) to prevent cross-project pollution.
github.com/facebook/react → facebook-react.utils-7f8a2b3c).osgrep list (shows names, sizes, and last modified times).--store flag: osgrep --store custom-name "query".~/.osgrep/data/store-name.~/.osgrep/data.When a snippet provided by osgrep is insufficient, do not read the entire file. Instead, use the line ranges provided in the search results to read only the relevant section using the Read tool.
Example:
If osgrep reports: osgrep found src/auth/handler.ts:45-90 as ORCH,
Use: Read src/auth/handler.ts:45-120
The primary command for semantic search is osgrep "<query>". This returns approximately 10 results containing code snippets (typically 15+ lines each) to provide context.
Tips for better results:
"auth", use "where does the server validate JWT tokens".osgrep "where do we validate user permissions"To understand a codebase's architecture using osgrep, follow this pattern:
osgrep "where do requests enter the server"Read on the specific line range identified.osgrep trace <function_name> to understand the call hierarchy and data flow.osgrep is a semantic search tool for codebases designed for coding agents. It finds concepts rather than just strings and uses local embeddings via onnxruntime-node.
Install the CLI globally via npm:
npm install -g osgrepIt is highly recommended to run the setup command to download the required embedding models (~150MB) upfront:
osgrep setupcd my-repo
osgrep "where do we handle authentication?"trace to see call graphs (upstream and downstream dependencies) for a specific function.osgrep trace "function_name"osgrep symbolsnpm install -g osgrep
osgrep setup
osgrep "query"You can integrate osgrep directly into Claude Code or Opencode to enable semantic search capabilities for your coding agent.
osgrep install-claude-code.claude).osgrep serve background process.osgrep install-opencode.opencode).osgrep serve background process.osgrep install-claude-code
osgrep install-opencodeosgrep respects both .gitignore and .osgrepignore files. To exclude specific files or patterns from being indexed that are not already in your .gitignore, create a .osgrepignore file in your repository root.
.osgrepignore syntax:
.gitignore.!), and directory patterns (/).If any osgrep command returns a status indicating "Indexing", "Building", or "Syncing", the semantic index is not yet complete.
Important for AI Agents:
When performing a semantic search, osgrep categorizes results to help you understand the role of the code found:
1 is the best match.To remove the osgrep integration from OpenCode, use the uninstall-opencode command. This will:
~/.config/opencode/tool/osgrep.ts.osgrep MCP server from ~/.config/opencode/opencode.json.~/.config/opencode/plugin/.osgrep uninstall-opencodeThe Skeletonizer class reduces token usage (typically by 80-95%) by replacing function and method bodies with concise summaries. It preserves structural elements like class/interface declarations, signatures, type definitions, and decorators, while providing inline metadata about what the elided functions do (e.g., complexity, role, and referenced symbols).
You can use the Skeletonizer class directly or use the skeletonizeFile convenience function for a simpler API.
import { skeletonizeFile } from './path/to/skeletonizer';
const filePath = 'example.ts';
const content = '...'; // file content
const result = await skeletonizeFile(filePath, content, {
preserveDecorators: true,
includeSummary: true,
maxCallsInSummary: 4
});
if (result.success) {
console.log(result.skeleton);
} else {
console.error(result.error);
}