searchgrep

Crates.iosearchgrep
lib.rssearchgrep
version0.1.0
created_at2026-01-01 19:43:12.480252+00
updated_at2026-01-01 19:43:12.480252+00
descriptionSemantic grep for the AI era - natural language code search
homepagehttps://github.com/RandomsUsernames/sgrep
repositoryhttps://github.com/RandomsUsernames/sgrep
max_upload_size
id2017367
size16,414,869
(RandomsUsernames)

documentation

README

sgrep

Semantic grep for the AI era
Natural language code search powered by Rust

Crates.io npm License GitHub release

Rust MCP Compatible Apple Silicon


Search your codebase using natural language. Ask questions like "where are authentication errors handled" or "database connection pooling logic" and get instant results.

# Install
brew install RandomsUsernames/sgrep/sgrep

# Index & Search
sgrep index .
sgrep search "error handling for API requests"

Why sgrep?

Traditional grep sgrep
grep -r "error" finds literal matches Finds code by meaning
Requires knowing exact terms Use natural language
Misses synonyms and related code Understands context
No AI integration Works with Claude, Cursor, etc.

Installation

Homebrew (macOS)

brew tap RandomsUsernames/sgrep
brew install sgrep

npm / npx

npx sgrep          # Run directly
npm install -g sgrep  # Install globally

From Source

git clone https://github.com/RandomsUsernames/sgrep.git
cd sgrep
cargo install --path .

Quick Start

# 1. Index your codebase
sgrep index .

# 2. Search with natural language
sgrep search "authentication middleware"

# 3. Get AI-powered answers
sgrep ask "how does the login flow work"

# 4. View codebase structure
sgrep map

Features

Semantic Search

Find code by meaning, not just keywords. The query "handle user login" will find authentication code even if it doesn't contain those exact words.

sgrep search "database connection pooling"
sgrep search "where are errors logged" --content

AI Answers

Get synthesized answers about your codebase using GPT.

sgrep ask "explain the authentication flow"
sgrep ask "what testing framework is used"

Codebase Map

Get a structural overview of your code - functions, classes, and their relationships.

sgrep map              # Full codebase map
sgrep map src/         # Specific directory

MCP Server

Integrates directly with Claude Code, Cursor, and other MCP-compatible tools.

sgrep setup   # Interactive setup for AI tools

Multiple Search Modes

Mode Flag Best For
Balanced (default) General search
Code --code Code-specific queries
Hybrid --hybrid Best quality (slower)

AI Tool Integration

Claude Code / Cursor / Continue

sgrep setup  # Interactive MCP setup

Or manually add to your MCP config:

{
  "mcpServers": {
    "sgrep": {
      "command": "sgrep",
      "args": ["mcp-server"]
    }
  }
}

Skills (Claude, Gemini CLI, OpenCode)

sgrep skill         # Interactive setup
sgrep skill claude  # Claude only
sgrep skill all     # All tools

Commands

Command Description
sgrep index <path> Index a directory
sgrep search <query> Semantic search
sgrep ask <question> AI-powered Q&A
sgrep map [path] Codebase structure map
sgrep setup Configure MCP for AI tools
sgrep skill [tool] Install as skill
sgrep status Show index status
sgrep config Configure settings

Search Options

sgrep search "query" [options]

  -m, --max-results <n>   Max results (default: 10)
  -c, --content           Show code snippets
  -a, --answer            Generate AI answer
  --code                  Code-optimized model
  --hybrid                Best quality (BGE + CodeRankEmbed)

How It Works

  1. Index - Files are chunked and converted to vector embeddings locally using BGE or CodeRankEmbed
  2. Store - Embeddings cached in ~/.sgrep/
  3. Search - Your query is embedded and compared using cosine similarity
  4. Rank - Results sorted by semantic relevance
  5. Answer - Optionally, top results sent to GPT for synthesis

Performance

  • Apple Silicon - Uses Accelerate framework for fast inference
  • Local Models - No API calls needed for search
  • Indexing - ~100 files/minute
  • Search - ~2s (single model), ~3.5s (hybrid)

Configuration

sgrep config --api-key sk-...   # Set OpenAI key (for answers)
sgrep config --show             # Show config

Environment Variables

Variable Description
OPENAI_API_KEY For --answer and ask commands
OPENAI_BASE_URL Custom API endpoint

Ignore Files

sgrep respects .gitignore and .sgrepignore.

Examples

# Find auth code
sgrep search "user authentication and sessions"

# With code preview
sgrep search "database queries" --content

# Best quality search
sgrep search --hybrid "vector embeddings"

# Architecture overview
sgrep ask "what's the project architecture"

# View structure
sgrep map src/

Contributing

Contributions welcome! Please open an issue or PR.

License

MIT

Commit count: 0

cargo fmt