- Node.js v22+ (required for native ESM and global
fetch) - Ollama (default) running locally, OR an OpenAI-compatible API endpoint
- OpenCode (optional) for agent plugin features
If you don't have Ollama installed, download it from ollama.com and start the service. Then pull the required model:
# Small embedding model (required for vector search)
ollama pull qwen3-embedding:0.6b
# Small description model (optional, for LLM-generated chunk descriptions)
ollama pull qwen2.5:3b
# Small vision model (optional, for describing images)
ollama pull minicpm-v4.6OpenCodeRAG uses three models:
- Embedding model - converts code chunks into vectors for semantic search. Configured via
embedding.model(default:qwen3-embedding:0.6b). - Description model - generates natural-language descriptions of code chunks before embedding. Configured via
description.model(default:qwen2.5:3b). - Vision model - generates natural-language descriptions of images before embedding. Configured via
imageDescription.model(default:minicpm-v4.6).
Tip: Smaller embedding models (≤3B) work well on CPU. For better search results, use a larger embedding model like
qwen3-embedding:1.7band activate description and image descripion model usage in OpenCodeRAG config (dedicated GPU recommended).opencode-rag initauto-detects whether your Ollama runs on CPU or GPU and tunes the embedding batch settings accordingly — no manual tuning needed.
# Install globally via npm
npm install -g opencode-rag-plugin
# Set up the OpenCode runtime
opencode-rag setup
# Initialize in your local workspace (creates config, skill, and AGENTS.md)
cd /path/to/your/workspace
opencode-rag init
opencode-rag setupis a machine-level step — it installs the plugin runtime into~/.opencode/once per machine.opencode-rag initis a workspace-level step — run it in every workspace where you want OpenCodeRAG. Both commands explain their exact use cases in their help output (opencode-rag setup --help/opencode-rag init --help).
Tree-sitter grammars ship as pre-built WASM files (bundled in wasm/ and @vscode/tree-sitter-wasm). Native dependencies (sharp, @lancedb/lancedb) use pre-built platform binaries. The plugin is workspace-local — OpenCode loads it from .opencode/plugins/. Data (vector store, manifest) lives in the workspace.
The global CLI (~/.local/bin/opencode-rag) is a thin wrapper that runs node ~/.opencode/node_modules/opencode-rag-plugin/dist/cli.js. To update:
From npm (published release):
npm update -g opencode-rag-plugin
opencode-rag setup # sync the runtime symlink
opencode-rag init # update workspace files (AGENTS.md, skill, config)From source (local development):
cd /path/to/OpenCodeRAG
npm run build # compile src/ → dist/
npm link # link local package globally
opencode-rag setup --force # sync runtime
npm i -g opencode-rag-plugininstalls the latest published npm version. After making local source changes in this repo, runnpm run build && npm link && opencode-rag setup --forceinstead. Runningnpm i -gfrom the repo directory replaces the local symlink with the published version.
Download the package tarball from the GitHub Releases page and run:
npm install -g ./opencode-rag-plugin-<version>.tgz
opencode-rag setupgit clone https://github.com/MrDoe/OpenCodeRAG.git
cd OpenCodeRAG
npm install --legacy-peer-deps
npm run build
opencode-rag setup --forceNote:
--legacy-peer-depsis only needed when developing in the cloned repo (where@opencode-ai/pluginis both a dev and peer dependency). End users installing vianpm install -gnever need this flag.
opencode-rag setup --uninstall
npm uninstall -g opencode-rag-pluginThis removes all copies and config entries of OpenCodeRAG.
The install script only installs the CLI globally. Initialize each workspace where you want to use OpenCodeRAG:
cd /path/to/your/workspace
opencode-rag initThis creates:
opencode-rag.json— Workspace-specific RAG configuration (never overwritten without interactive confirmation). Embedding batch settings are auto-tuned to your Ollama backend (see below).opencode/plugins/rag-plugin.js— Plugin entry (re-exports from workspacenode_modules/).opencode/plugins/rag-tui.js— TUI plugin module.opencode/opencode.json— OpenCode workspace config.opencode/tui.json— TUI plugin settings.opencode/package.json— Workspace dependencies (links to the globally-installed plugin).opencode/skills/opencode-rag/SKILL.md— AI agent skill file.opencode/.gitignore— ignoresnode_modules/andrag_db/AGENTS.md— Always-loaded tool-usage directive (merged into existing content, never overwrites; includes mandatory tool guidance, decision tree, proactive triggers, anti-patterns, and conditional quirk-capture rules)- Runs
npm installto install workspace dependencies
The AGENTS.md directive is wrapped in sentinel markers (<!-- BEGIN opencode-rag --> / <!-- END opencode-rag -->) so re-running init replaces the section in-place without duplicating it. Existing content outside the markers is always preserved.
Use --skip-install to skip the npm install step. Use --force to overwrite existing files except opencode-rag.json (requires interactive confirmation). Use --skip-health-check to skip provider validation (useful in offline environments).
After writing config, init validates that your embedding provider is reachable and all configured models (embedding, description & visual) are available. For Ollama, if models are missing, you will be asked to pull them automatically.
When generating a new opencode-rag.json, init probes Ollama (GET /api/ps) and detects whether models run on the GPU or CPU, then writes matching embedding batch settings into the indexing section:
| Detected backend | embedBatchSize |
embedConcurrency |
ollamaMaxBatchSize |
|---|---|---|---|
| GPU (any model in VRAM) | 40 |
4 |
40 |
| CPU | 20 |
1 |
20 |
| Ollama unreachable / undetermined | 100 (default) |
3 (default) |
100 (default) |
GPU settings (batch 40 + concurrency 4) reach ~97% of the measured GPU throughput ceiling on a GeForce RTX 4090 with qwen3-embedding:0.6b, while keeping batches safely under Ollama's 4096-token context window. CPU settings keep batches small and sequential since CPU throughput is flat regardless of batch size. Override any of these via indexing.* in the config if your workload differs.
npx opencode-rag init
npx opencode-rag index
npx opencode-rag query "your search query"The package is published as opencode-rag-plugin on npm:
npm install --save-dev opencode-rag-plugin
⚠️ Note: Do not confuse with the npm packageopencode-rag, which is a discontinued project by a different author.
opencode-rag statusThis shows the index statistics, store path, provider, model, manifest status, and keyword index status.
OpenCode supports Language Server Protocol (LSP) for richer code intelligence. It is recommended to enable LSP in your opencode.json:
{
"$schema": "https://opencode.ai/config.json",
"lsp": true
}Then ask OpenCode to install the LSPs for the programming languages you are using. This gives agents more info about code structure and definitions, and error diagnostics to complement OpenCodeRAG's semantic search with precise type-aware context.
Once installed, OpenCodeRAG provides three tools for AI agents to retrieve and explore code:
| Tool | Purpose |
|---|---|
search_semantic |
Retrieve relevant code chunks by query or meaning |
get_file_skeleton |
Get structural overview of a file (functions, classes, interfaces) |
find_usages |
Find all references to a symbol across the codebase |
For detailed usage instructions, parameters, and examples, see the ## Code Navigation section of the workspace's AGENTS.md (created by opencode-rag init) or the AGENTS.md file in the project root.