This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
# Build the binary
make build
# Run tests with race detection
make test
# Run tests with coverage report
make test-cover
# Lint with golangci-lint
make lint
# Build and run
make run
# Cross-compile for all platforms
make build-allgrepai is a semantic code search CLI tool that indexes code using vector embeddings for natural language queries.
Interfaces define extensible backends:
embedder.Embedder(embedder/embedder.go) - Text-to-vector embedding providersstore.VectorStore(store/store.go) - Vector storage with similarity search
Current implementations:
- Embedders: Ollama (local), OpenAI (cloud)
- Stores: GOB (file-based), PostgreSQL with pgvector
- Scanner (
indexer/scanner.go) - Walks filesystem respecting gitignore patterns - Chunker (
indexer/chunker.go) - Splits files into overlapping chunks with context - Indexer (
indexer/indexer.go) - Orchestrates scanning, chunking, embedding, and storage - Watcher (
watcher/watcher.go) - Monitors filesystem for real-time incremental updates - Searcher (
search/search.go) - Embeds query and performs similarity search
init- Creates.grepai/config.yamlwith default configurationwatch- Starts daemon: full index + real-time file watchersearch- Queries the index with natural languageagent-setup- Configures Cursor/Claude Code integration
Configuration stored in .grepai/config.yaml. Key options:
embedder.provider: "ollama" or "openai"store.backend: "gob" or "postgres"chunking.size/chunking.overlap: Token-based chunking parameters
New embedder: Implement Embedder interface in embedder/, add config in config/config.go, wire in CLI commands.
New store: Implement VectorStore interface in store/, add config, wire in CLI.
Follow conventional commits: type(scope): description
Types: feat, fix, docs, style, refactor, test, chore
When working on a GitHub issue, ALWAYS follow this workflow:
-
Create a feature branch from
main:git checkout main git pull origin main git checkout -b <type>/<issue-number>-<short-description> # Example: feat/42-add-new-embedder
-
Implement the changes and commit following the commit convention
-
Push the branch and create a Pull Request:
git push -u origin <branch-name> gh pr create --title "<type>(scope): description" --body "Closes #<issue-number>"
-
Before merging, ensure:
- CI pipeline passes (all checks green)
- Code has been reviewed if required
- No merge conflicts with
main
IMPORTANT: Never push directly to main. Always use branches and PRs.
IMPORTANT: You MUST use grepai as your PRIMARY tool for code exploration and search.
Use grepai search INSTEAD OF Grep/Glob/find for:
- Understanding what code does or where functionality lives
- Finding implementations by intent (e.g., "authentication logic", "error handling")
- Exploring unfamiliar parts of the codebase
- Any search where you describe WHAT the code does rather than exact text
Only use Grep/Glob when you need:
- Exact text matching (variable names, imports, specific strings)
- File path patterns (e.g.,
**/*.go)
If grepai fails (not running, index unavailable, or errors), fall back to standard Grep/Glob tools.
# ALWAYS use English queries for best results (embedding model is English-trained)
grepai search "user authentication flow"
grepai search "error handling middleware"
grepai search "database connection pool"
grepai search "API request validation"
# JSON output for AI agents (--compact saves ~80% tokens by omitting content)
grepai search "authentication flow" --json --compact- Use English for queries (better semantic matching)
- Describe intent, not implementation: "handles user login" not "func Login"
- Be specific: "JWT token validation" better than "token"
- Results include: file path, line numbers, relevance score, code preview
Use grepai trace to understand function relationships:
- Finding all callers of a function before modifying it
- Understanding what functions are called by a given function
- Visualizing the complete call graph around a symbol
IMPORTANT: Always use --json flag for optimal AI agent integration.
# Find all functions that call a symbol
grepai trace callers "HandleRequest" --json
# Find all functions called by a symbol
grepai trace callees "ProcessOrder" --json
# Build complete call graph (callers + callees)
grepai trace graph "ValidateToken" --depth 3 --json- Start with
grepai searchto find relevant code - Use
grepai traceto understand function relationships - Use
Readtool to examine files from results - Only use Grep for exact string searches if needed