OpenGrep
Advanced AST-aware code search with AI-powered insights. OpenGrep understands your code structure and provides intelligent search capabilities beyond simple pattern matching.
Features
- AST-Aware Search: Uses tree-sitter to understand code structure
- Multi-Language Support: Supports 15+ programming languages
- AI Integration: Optional OpenAI integration for intelligent insights
- High Performance: Parallel search with efficient file traversal
- Flexible Output: Text, JSON, HTML, XML, and CSV output formats
- Interactive Mode: Built-in interactive search interface
- Docker Ready: Containerized for easy deployment
- Configurable: Extensive configuration options
Quick Start
Installation
From crates.io (Recommended)
From Source
# Clone the repository
# Build and install
Using Docker
# Pull the image
# Run a search
Basic Usage
# Search for a pattern in current directory
# Case-insensitive regex search
# Show AST context around matches
# Interactive mode
# JSON output
Supported Languages
- Rust
- Python
- JavaScript/TypeScript
- Go
- Java
- C/C++
- C#
- Ruby
- Bash
- JSON
- TOML
- CSS
Advanced Examples
AST-Aware Search
# Find all function definitions
# Search with AST context display
AI-Powered Analysis
# Enable AI insights (requires OPENAI_API_KEY)
# Get AI explanations for matches
Output Formats
# HTML report
# CSV for spreadsheet analysis
# Structured JSON
Filtering and Performance
# Filter by programming language
# Exclude directories
# Limit file size and use more threads
Configuration
OpenGrep can be configured via CLI arguments or configuration files:
Configuration File
Create ~/.config/opengrep/config.toml
:
[]
= false
= false
= 8
= 10485760
[]
= true
= true
= 2
= 2
= false
[]
= "gpt-4o-mini"
= false
= false
= 1000
Environment Variables
# Logging level
Building
Prerequisites
- Rust 1.75+
- Git
Development Build
Release Build
All Build Commands
Docker Usage
Build Docker Image
Run with Docker
# Basic search
# Interactive mode
# With AI features
Testing
# Run all tests
# Run specific test module
# Run with output
# Integration tests
API Integration
OpenGrep can be used as a library:
use ;
use PathBuf;
async
FastAPI Integration
For web service integration, see the examples directory for FastAPI endpoint implementations.
Performance
OpenGrep is optimized for performance:
- Parallel Processing: Multi-threaded file traversal and searching
- Smart Filtering: Respect .gitignore and file type filters
- Memory Efficient: Streaming file processing
- AST Caching: Intelligent AST parsing and caching
Benchmarks
# Run benchmarks
# Compare with other tools
Troubleshooting
Common Issues
-
AI features not working
-
Out of memory errors
-
Slow performance
-
Language not detected
Debug Mode
RUST_LOG=debug
Contributing
- Fork the repository
- Create your feature branch (
git checkout -b feature/amazing-feature
) - Commit your changes (
git commit -m 'Add amazing feature'
) - Push to the branch (
git push origin feature/amazing-feature
) - Open a Pull Request
Development Setup
License
This project is dual-licensed under either:
- MIT License (LICENSE-MIT or http://opensource.org/licenses/MIT)
- Apache License, Version 2.0 (LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0)
at your option.
Acknowledgments
- tree-sitter for AST parsing
- tokio for async runtime
- clap for CLI interface
- OpenAI for AI integration