# OpenGrep User Guide
Welcome to OpenGrep, the AST-aware code search tool with AI-powered insights!
## Quick Start
### Installation
Install OpenGrep using cargo:
```bash
cargo install opengrep
```
Or download prebuilt binaries from our releases page.
### Basic Usage
Search for a pattern in the current directory:
```bash
opengrep "TODO"
```
Search in specific files or directories:
```bash
opengrep "function" src/
opengrep "impl" file1.rs file2.rs
```
### Advanced Features
#### AST Context
Show function and class context for matches:
```bash
opengrep -a "error_handling"
```
This will show you the containing function, struct, or class for each match.
#### AI Insights
Enable AI-powered code analysis:
```bash
export OPENAI_API_KEY=your-api-key
opengrep --ai-insights "unsafe"
```
AI insights provide:
- Summary of findings
- Code explanations
- Improvement suggestions
- Related code locations
#### Regular Expressions
Use regex patterns for complex searches:
```bash
opengrep -e "fn\s+\w+_test" # Find test functions
opengrep -e "struct\s+\w+<" # Find generic structs
```
#### Output Formats
Generate reports in different formats:
```bash
opengrep -o json "TODO" > todos.json
opengrep -o html "FIXME" > report.html
```
### Configuration
Create a configuration file at `~/.config/opengrep/config.toml`:
```toml
[search]
ignore_case = false
regex = false
context = 2
threads = 4
[output]
color = true
line_numbers = true
ast_context = true
[ai]
model = "gpt-4o-mini"
insights = true
max_tokens = 1000