Sandbox
@Helweg/open-codebase-index

Semantic code search for Claude Code and MCP hosts

This repo gives agents a local index of a codebase, then lets them search by meaning, look up definitions, and follow caller and dependency paths. It works through a TypeScript host layer plus a Rust native layer for parsing, vectors, SQLite, and BM25 search.

190 stars29 forksTypeScriptUpdated 6d ago
Who it's for

Builders who want Claude Code, Codex, OpenCode, or another MCP client to search a repository by meaning instead of exact filenames.

What it delivers

You can ask a repo question and get evidence from the right files, symbols, and call paths instead of re-explaining the codebase.

What it does

Semantic and keyword search

Find code by meaning with embeddings and BM25, then rank the best matches together.

Definition and call graph lookup

Jump from a symbol to its definition, callers, callees, and dependency paths.

Branch-aware incremental indexing

Reuse unchanged chunks across runs and keep results scoped to the active branch.

MCP and plugin integrations

Works with OpenCode, Claude Code, Codex, Pi, Jcode, and other MCP clients through host-specific packaging.

Local storage and parsing

Uses SQLite, usearch vectors, tree-sitter parsing, and native call extraction.

CLI workflows

Provides `cbi` commands for status, indexing, search, and symbol inspection outside an MCP client.

How to get it

  1. 1Install the package
    npm install open-codebase-index
  2. 2Legacy installs continue to work with
    npm install opencode-codebase-index

README

open-codebase-index

npm version License: MIT Downloads Build Status Node.js

Search a codebase by meaning, then follow the result into definitions, callers, and dependency paths.

open-codebase-index is a local semantic code index for OpenCode, Jcode, Pi, Codex, Claude Code, and other MCP clients. It combines embeddings, BM25 keyword search, branch-aware filtering, symbol lookup, and a call graph behind agent-friendly tools.

New installs should use open-codebase-index and open-codebase-index-mcp. The legacy package opencode-codebase-index and opencode-codebase-index-mcp remain supported aliases.

For terminal use outside an MCP client, install the package globally and use the concise cbi command:

npm install -g open-codebase-index
cbi status --project /path/to/repo --host jcode
cbi search "retry recovery" --project /path/to/repo

cbi provides status, indexing, search, definition lookup, and direct caller or callee inspection. See Installation and host setup for the full command reference.

Highlights

  • Semantic and hybrid retrieval for questions where you do not know the identifier.
  • Low-token discovery through codebase_context and codebase_peek.
  • Definition and graph navigation through implementation_lookup, call_graph, and call_graph_path.
  • Incremental, branch-aware indexing with file watching and content-hash reuse.
  • Local storage backed by SQLite, usearch vectors, and a BM25 inverted index.
  • Multiple embedding providers: Ollama, OpenAI, Google, or a custom OpenAI-compatible endpoint.
  • Native parsing for TypeScript/TSX, JavaScript/JSX, Python, Rust, Swift, Go, Java, C#, Ruby, C/C++, Metal, PHP, Apex, Bash, Zig, GDScript, MATLAB, JSON, TOML, YAML, Markdown, HTML, XML, and SVG, plus text fallback for other formats.

Quick start with OpenCode

Requires Node.js 22.13 or newer. Node.js 24 LTS is recommended.

  1. Install the package:

    npm install open-codebase-index
    

    Legacy installs continue to work with:

    npm install opencode-codebase-index
    
  2. Add it to opencode.json:

    {
      "plugin": ["open-codebase-index"]
    }
    

    Legacy alias:

    {
      "plugin": ["opencode-codebase-index"]
    }
    
  3. Run /status, then /index.

  4. Ask a repository question, for example:

    Where is authentication state validated before an API request?

The first index creates embeddings. Later runs reuse unchanged content and process only relevant changes.

Choose your host

HostRecommended integrationStorage
OpenCodeNative plugin.opencode/
JcodePer-session MCP server.codebase-index/
PiPi package.codebase-index/
CodexMarketplace plugin with MCP and skill guidance.codebase-index/
Claude CodeMarketplace plugin with MCP and skill guidance.claude/
Cursor, Windsurf, other MCP clientsopen-codebase-index-mcp (legacy alias: opencode-codebase-index-mcp)Selected by --host; default is OpenCode-compatible

See Installation and host setup for complete instructions.

Recommended workflow

  1. Check readiness with index_status or /status.
  2. Index when needed with index_codebase or /index.
  3. Start repository discovery with codebase_context.
  4. Use codebase_peek when you only need likely locations.
  5. Use implementation_lookup for a known symbol or definition question.
  6. Use codebase_search when you need full matching source content.
  7. Use grep for exact identifiers or exhaustive text matches.
  8. Use call-graph tools for callers, callees, and dependency paths.

Which search tool should I use?

NeedTool
Route a repository question to a bounded evidence packcodebase_context
Find likely files and symbols without source bodiescodebase_peek
Retrieve full matching codecodebase_search
Find an authoritative definitionimplementation_lookup
Find analogous implementations or duplicatesfind_similar
Find direct callers or calleescall_graph
Find a path between two symbolscall_graph_path
Analyze a branch or pull request blast radiuspr_impact

See Tools and commands for host availability, tool details, MCP prompts, and slash commands.

How it works

source files
   │
   ├─ file discovery and git-aware change detection
   ├─ tree-sitter parsing and semantic chunking
   ├─ embedding generation and content-hash reuse
   ▼
SQLite metadata + usearch vectors + BM25 index
   │
   ├─ semantic candidates
   ├─ keyword candidates
   ├─ branch and request filters
   ├─ deterministic fusion and ranking
   ▼
locations, source results, definitions, and call-graph evidence

The TypeScript layer handles host integration, configuration, indexing orchestration, providers, ranking, and tools. The Rust NAPI module handles parsing, vector storage, SQLite operations, BM25 indexing, hashing, and call extraction.

Read Architecture for the detailed data flow and design decisions.

Embedding providers

With embeddingProvider: "auto", providers are tried in this order:

  1. Ollama
  2. OpenAI
  3. Google

Ollama is the simplest local option:

ollama pull nomic-embed-text
{
  "embeddingProvider": "ollama"
}

A custom OpenAI-compatible embeddings endpoint is also supported. Provider, indexing, search, reranking, include/exclude, knowledge-base, storage, and debug settings are documented in Configuration.

Configuration example

OpenCode project config lives at .opencode/codebase-index.json. Codex, Pi, and Jcode use .codebase-index/config.json; Claude uses .claude/codebase-index.json.

{
  "embeddingProvider": "auto",
  "scope": "project",
  "indexing": {
    "autoIndex": false,
    "watchFiles": true,
    "requireProjectMarker": true,
    "semanticOnly": false
  },
  "search": {
    "maxResults": 20,
    "minScore": 0.1,
    "fusionStrategy": "rrf",
    "rerankTopN": 20
  },
  "mcp": {
    "stallTimeoutMs": 300000
  }
}

Only specify values you want to override. See Configuration for defaults and host-specific paths.

Branch-aware indexing

The index stores reusable content by hash and maintains branch catalogs for chunks and symbols. On a branch switch, unchanged content can be reused while results remain scoped to the active branch. Linked worktrees without a local project config share the main checkout's portable project index; adding a worktree-local config creates an isolated index boundary.

Knowledge bases and reranking

OpenCode, Pi, and every MCP client can index additional directories as knowledge bases. Configure them with knowledgeBases, or use the knowledge-base tools:

  • MCP and OpenCode: add_knowledge_base, list_knowledge_bases, remove_knowledge_base
  • Pi: knowledge_base_add, knowledge_base_list, knowledge_base_remove

Optional external reranking supports Cohere, Jina, and custom compatible endpoints. Local filtering and evidence classes are applied before external candidates are submitted.

See Configuration for examples and privacy considerations.

Troubleshooting

Start with:

  1. /status or index_status
  2. index_health_check
  3. a normal /index retry
  4. a forced rebuild only when status reports incompatibility or corruption

Common provider, native module, stale index, branch, and performance issues are covered in Troubleshooting.

MCP operations report structured, redacted failures and durable phase diagnostics through index_status. If a client has already lost its stdio transport, start a fresh client session before retrying.

Evaluation and performance

The repository includes reproducible retrieval datasets, latency and quality budgets, baseline comparison, and cross-repository benchmarking tools.

Performance depends on repository size, parser coverage, provider latency, embedding cache reuse, and the selected indexing limits. Prefer measured evaluation over fixed marketing claims.

Development

npm ci
npm run build
npm run typecheck
npm run lint
npm run test:run

Native changes require Rust and npm run build:native. See Contributing, Architecture, and Adding language support.

Documentation

License

MIT. See LICENSE.

Files in the repo

Repository payload32 top-level entries
  • .agents
  • .claude-plugin
  • .codex-plugin
  • .github
  • benchmarks
  • commands
  • docs
  • hooks
  • native
  • scripts
  • skill
  • skills
  • src
  • tests
  • .gitignore
  • .mcp.json
  • AGENTS.md
  • ARCHITECTURE.md
  • CHANGELOG.md
  • CODE_OF_CONDUCT.md
  • CONTRIBUTING.md
  • eslint.config.js
  • LICENSE
  • package-lock.json
  • package.json
  • README.md
  • SECURITY.md
  • THIRD_PARTY_LICENSES.md
  • TROUBLESHOOTING.md
  • tsconfig.json
  • tsup.config.ts
  • vitest.config.ts

Discussion (0)

Ask about usage, or say what you built with it

Sign in to join the discussion.

No comments yet. Be the first to say what this is good for.

More connectors

Real-time global intelligence dashboard. AI-powered news aggregation, geopolitical monitoring, and infrastructure tracking in a unified situational awareness interface

86k

High-performance code intelligence MCP server. Indexes codebases into a persistent knowledge graph — average repo in milliseconds. 158 languages, sub-ms queries, 99% fewer tokens. Single static binary, zero dependencies.

43k

Universal provider proxy for OpenAI Codex & Claude Code — use any LLM (Claude, Gemini, Grok, DeepSeek, Ollama…) with Codex CLI, App, SDK, and Claude Code

14k
okf-memory/
okf-agent-memory

Git-native persistent memory for AI coding agents. Implements Google OKF v0.2 with sub-300µs in-memory BM25 search, embedded MCP server, and progressive disclosure. Slashes token bloat by 80% with zero external databases or dependencies. Built in pure Go.

547
tirth8205/
code-review-graph

Local-first code intelligence graph for MCP and CLI. Builds a persistent map of your codebase so AI coding tools read only what matters, with benchmarked context reductions on reviews and large-repo workflows.

31k
2akouwu/
reverify

Stop your AI from making things up — it proposes, deterministic tools decide, every claim checked against ground truth with evidence. Grounded facts and context survive resets. Reverse engineering is the proving ground. MCP server + CLI.

1.1k