octocode 0.20.0

AI-powered code intelligence with semantic search, knowledge graphs, and built-in MCP server. Transform your codebase into a queryable knowledge graph for AI assistants.
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
<div align="center">

<img src="https://raw.githubusercontent.com/Muvon/octocode/master/logo.svg" width="240" alt="Octocode">

### **Structural Code Intelligence for AI Agents β€” MCP Server + Knowledge Graph + Semantic Search**

[![GitHub stars](https://img.shields.io/github/stars/Muvon/octocode?style=social)](https://github.com/Muvon/octocode/stargazers)
[![License](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](https://opensource.org/licenses/Apache-2.0)
[![Rust](https://img.shields.io/badge/Rust-1.95%2B-orange.svg)](https://www.rust-lang.org)
[![Release](https://img.shields.io/github/v/release/Muvon/octocode)](https://github.com/Muvon/octocode/releases)

**Give your AI assistant a brain for your codebase.** Octocode transforms your project into a navigable knowledge graph that Claude, Cursor, and other AI agents can search, understand, and navigate.

[πŸš€ Quick Start](#-quick-start) β€’ [πŸ€– MCP Integration](#-mcp-server-integration) β€’ [πŸ“– Documentation](#-documentation) β€’ [🌐 Website](https://octocode.muvon.io)

<a href="https://glama.ai/mcp/servers/Muvon/octocode">
  <img width="300" src="https://glama.ai/mcp/servers/Muvon/octocode/badge" alt="Octocode MCP server" />
</a>

</div>

---

## πŸ€– Built for AI Agents

**The Problem:** AI assistants are blind to your codebase. They can't search your files, understand dependencies, or remember context across sessions.

**The Solution:** Octocode's MCP server gives AI agents:
- πŸ” **Semantic search** β€” Find code by meaning, not keywords
- πŸ•ΈοΈ **Knowledge graph** β€” Navigate imports, calls, and dependencies
- πŸ“ **Code signatures** β€” View structure without reading entire files
- 🧭 **LSP precision** β€” Go-to-definition, find-references, and hover docs via your language server

**Works with:** Claude Desktop β€’ Cursor β€’ Windsurf β€’ Any MCP-compatible AI

```json
// Add to your AI assistant config
{
  "mcpServers": {
    "octocode": {
      "command": "octocode",
      "args": ["mcp", "--path", "/your/project"]
    }
  }
}
```

Now your AI assistant can:
```
You: "Where is authentication handled?"
AI: *searches your codebase* "Authentication is in src/middleware/auth.rs,
    which imports jwt.rs for token validation and calls user_store.rs for lookup."

You: "What files depend on the payment module?"
AI: *queries knowledge graph* "src/api/handlers/payment.rs imports payment/mod.rs,
    which is also used by src/workers/refund.rs and src/cron/billing.rs"

You: "Find every call site of this function"
AI: *uses LSP find-references* "process_payment() is called from 4 places:
    checkout.rs:87, refund.rs:134, billing.rs:56, and tests/payment_test.rs:23"
```

## πŸ€” Why Octocode?

**Standard RAG treats your code as flat text chunks.** It finds similar-sounding snippets but has no idea that `auth_middleware.rs` imports `jwt.rs`, calls `user_store.rs`, and is wired into `router.rs`. Octocode understands *structure*.

```
# Semantic search finds the right code
octocode search "authentication middleware"
β†’ src/middleware/auth.rs | Similarity 0.923

# GraphRAG reveals the full dependency chain
octocode graphrag get-relationships --node_id src/middleware/auth.rs
Outgoing:
  imports β†’ jwt (src/auth/jwt.rs): token validation logic
  calls   β†’ user_store (src/db/user_store.rs): user lookup by token
Incoming:
  imports ← router (src/router.rs): wires auth into the request pipeline
```

Octocode uses **tree-sitter AST parsing** to extract real symbols (functions, imports, dependencies), builds a **GraphRAG knowledge graph** of relationships between files, and exposes everything via **MCP** β€” so AI tools can *navigate* your project architecture, not just search it.

## πŸ”¬ How It Works

```
Source Code β†’ Tree-sitter AST β†’ Symbols & Relationships β†’ Knowledge Graph
                                        ↓
                    Embeddings + Hybrid Search + Reranking β†’ MCP Server
```

1. **AST Parsing** β€” tree-sitter extracts real code symbols (functions, classes, imports), not arbitrary text chunks
2. **Knowledge Graph** β€” GraphRAG maps relationships between files: `imports`, `calls`, `implements`, `extends`, `configures`, and 9 more types β€” each with importance weighting
3. **Hybrid Search** β€” semantic similarity + BM25 full-text search + reranking β€” not just vector embeddings
4. **MCP Server** β€” exposes `semantic_search`, `view_signatures`, and `graphrag` tools to any MCP-compatible client

## ✨ What Makes It Different

| | Standard RAG | Doc Lookup Tools | **Octocode** |
|---|---|---|---|
| **Indexes** | Text chunks | External library docs | Your codebase structure (AST) |
| **Understands** | Similar text | API specs & usage | Functions, imports, dependencies |
| **Cross-file** | No | No | Yes β€” navigates the dependency graph |
| **Relationships** | No | No | `imports`, `calls`, `implements`, `extends`... |
| **AI integration** | Varies | MCP | Native MCP server + LSP |

> **Doc tools give AI the manual for libraries you use. Octocode gives AI the blueprint of how you put them together.**

**Built with Rust** for performance. **Local-first** for privacy. **Open source** (Apache 2.0) for transparency.

## πŸ“Š Retrieval Quality

Octocode ships a **reproducible retrieval benchmark** ([`benchmark/`](benchmark/)): 127 curated code-search queries with line-range ground truth, run against octocode's own source (pinned at `b1771ba` so annotations never drift). The numbers below use a **fully local, no-API-key** stack β€” `jina-embeddings-v2-base-code` via fastembed, **no reranker** β€” so they are a floor, not a ceiling:

| Config | Hit@5 | Hit@10 | MRR | NDCG@10 | Recall@10 |
|---|---|---|---|---|---|
| Dense vector only | 0.598 | 0.717 | 0.485 | 0.528 | 0.671 |
| Hybrid, default RRF weights (0.7/0.3) | 0.598 | 0.717 | 0.485 | 0.528 | 0.671 |
| **Hybrid, keyword-tuned (0.3/0.7)** | **0.732** | **0.835** | **0.572** | **0.620** | **0.807** |

Tilting RRF fusion toward the BM25/keyword signal β€” which carries disproportionate weight for code's exact identifiers β€” lifts **Hit@5 by +22%** and **Recall@10 by +20%** at zero added cost.

The benchmark also flags what _doesn't_ help here (full 6-variant matrix in [`benchmark/RESULTS.md`](benchmark/RESULTS.md)): a **generic** local cross-encoder reranker (`bge-reranker-base`) actually **regressed** results (Hit@5 0.732 β†’ 0.598) β€” code retrieval needs a _code-aware_ reranker (e.g. `voyage:rerank-2.5`), not an off-the-shelf one.

```bash
git worktree add /tmp/corpus b1771ba        # pin the corpus to the ground-truth commit
CORPUS=/tmp/corpus python3 benchmark/run_matrix.py
```

See [benchmark/README.md](benchmark/README.md) for methodology and metric definitions.

## πŸš€ Quick Start

### 1. Install

```bash
# Universal installer (Linux, macOS, Windows)
curl -fsSL https://raw.githubusercontent.com/Muvon/octocode/master/install.sh | sh

# macOS with Homebrew
brew install muvon/tap/octocode
```

<details>
<summary><strong>Other installation methods</strong></summary>

```bash
# Cargo (build from source)
cargo install --git https://github.com/Muvon/octocode

# Download binary from releases
# https://github.com/Muvon/octocode/releases
```

See [Installation Guide](INSTALL.md) for platform-specific instructions.
</details>

### 2. Set Up API Keys

```bash
# Required: Embedding provider (Voyage AI has 200M free tokens/month)
export VOYAGE_API_KEY="your-voyage-api-key"

# Optional: LLM for commit messages, code review
export OPENROUTER_API_KEY="your-openrouter-api-key"
```

**Get your Voyage API key:** [voyageai.com](https://www.voyageai.com/) (free tier available)

<details>
<summary><strong>Other embedding providers</strong></summary>

Octocode supports multiple embedding providers:

```bash
# OpenAI
export OPENAI_API_KEY="your-key"
octocode config --code-embedding-model "openai:text-embedding-3-small"

# Jina AI
export JINA_API_KEY="your-key"
octocode config --code-embedding-model "jina:jina-embeddings-v3"

# Google
export GOOGLE_API_KEY="your-key"
octocode config --code-embedding-model "google:text-embedding-005"
```

See [API Keys guide](doc/API_KEYS.md) for all supported providers.
</details>

### 3. Index Your Codebase

```bash
cd /your/project
octocode index
# β†’ Indexed 12,847 blocks across 342 files
```

### 4. Search Your Code

```bash
# Natural language search
octocode search "authentication middleware"

# Multi-query for broader results
octocode search "auth" "middleware" "session"

# Filter by language
octocode search "database connection pool" --lang rust

# Search commit history
octocode search "authentication refactor" --mode commits
```

### 5. Connect Your AI Assistant

Add to your MCP client config (Claude Desktop, Cursor, Windsurf):

```json
{
  "mcpServers": {
    "octocode": {
      "command": "octocode",
      "args": ["mcp", "--path", "/your/project"]
    }
  }
}
```

Done! Your AI assistant now understands your codebase structure.

## πŸ”Œ MCP Server Integration

Octocode includes a **built-in MCP server** that exposes your codebase as tools to AI assistants. This is the primary way to use Octocode β€” give your AI assistant direct access to search and navigate your code.

### Available Tools

| Tool | What It Does |
|------|--------------|
| `semantic_search` | Find code by meaning β€” "authentication flow", "error handling", "database queries" |
| `view_signatures` | View file structure β€” function signatures, class definitions, imports |
| `graphrag` | Query relationships β€” "what calls this function?", "what does this module import?" |
| `structural_search` | AST pattern matching β€” find `.unwrap()` calls, `new` instantiations, specific patterns |
| `lsp_goto_definition` | Jump to a symbol's definition (requires `--with-lsp`) |
| `lsp_find_references` | Find all usages of a symbol across the workspace (requires `--with-lsp`) |
| `lsp_hover` | Type info and documentation for a symbol (requires `--with-lsp`) |
| `lsp_document_symbols` / `lsp_workspace_symbols` / `lsp_completion` | File symbols, workspace-wide symbol search, completions (requires `--with-lsp`) |

Enable the LSP tools by starting the server with your language server:

```bash
octocode mcp --path /your/project --with-lsp="rust-analyzer"
```

### Conversational AI Examples

Once connected, your AI assistant can answer questions about your codebase:

```
You: "Where is user authentication implemented?"
AI: *uses semantic_search* "Found in src/auth/login.rs. The authenticate() function
    validates credentials against the database, generates a JWT token, and stores
    the session in Redis."

You: "What files depend on the payment module?"
AI: *uses graphrag* "src/api/handlers/payment.rs imports payment/mod.rs, which is also
    used by src/workers/refund.rs and src/cron/billing.rs. The payment module exports
    process_payment() and validate_transaction() functions."

You: "Show me all error handling in the API layer"
AI: *uses structural_search* "Found 23 error handling patterns in src/api/:
    - 15 use Result<T, ApiError> with explicit error types
    - 8 use .unwrap() (potential panics in handlers/user.rs:42, handlers/auth.rs:87)
    - 3 use .expect() with custom messages"
```

### Quick Setup

**Octomind (Recommended)** β€” Zero setup, Octocode pre-configured:
```bash
curl -fsSL https://raw.githubusercontent.com/muvon/octomind/master/install.sh | bash
octomind run developer:rust
```

**Claude Code (CLI)** β€” Command-line setup:
```bash
claude mcp add octocode -- octocode mcp --path /path/to/your/project
```

**Claude Desktop / Cursor / Windsurf** β€” Add to config:
```json
{
  "mcpServers": {
    "octocode": {
      "command": "octocode",
      "args": ["mcp", "--path", "/path/to/your/project"]
    }
  }
}
```

**Config locations:**
- Claude Desktop: `~/Library/Application Support/Claude/claude_desktop_config.json` (macOS)
- Cursor: `~/.cursor/mcp.json` or Settings β†’ MCP Servers
- Windsurf: Settings β†’ MCP

πŸ“– **[Complete MCP Client Setup Guide](doc/MCP_CLIENTS.md)** β€” Detailed instructions for 15+ clients including VS Code (Cline/Continue), Zed, Replit, and more.

## 🎯 What Can You Do With It?

**New developer onboarding:**
```
You: "How does the authentication system work?"
AI: *searches and navigates* "Authentication starts in src/middleware/auth.rs which
    validates JWT tokens. It calls src/auth/jwt.rs for token verification, which uses
    the public key from config. Failed auth returns 401 via src/errors/auth_error.rs.
    Sessions are stored in Redis via src/cache/session.rs."
```

**Code archaeology:**
```
You: "Find all places we handle database errors"
AI: *structural search* "Found 47 error handling patterns:
    - 32 use Result<T, DbError> with proper error types
    - 15 use .unwrap() (potential issues in src/db/user.rs:23, src/db/order.rs:156)
    - Recommend adding proper error handling to those locations"
```

**Refactoring with confidence:**
```
You: "What depends on the PaymentProcessor trait?"
AI: *queries graph* "src/api/handlers/checkout.rs, src/workers/refund_worker.rs,
    and src/cron/billing.rs all depend on PaymentProcessor. The trait is defined
    in src/domain/payment.rs and implemented by src/infrastructure/stripe.rs
    and src/infrastructure/paypal.rs."
```

**Code review assistance:**
```
You: "Review this PR for security issues"
AI: *analyzes changes* "The PR adds password hashing in src/auth/hash.rs. However,
    it uses SHA256 which is fast and vulnerable to brute force. Recommend using
    bcrypt or argon2 instead. Also found 3 instances of .unwrap() that could panic
    in production."
```

## 🌐 Supported Languages

16 languages with full tree-sitter AST parsing:

| Language | Extensions | Features |
|----------|------------|----------|
| **Rust** | `.rs` | Full AST parsing, pub/use detection, module structure |
| **Python** | `.py` | Import/class/function extraction, docstring parsing |
| **TypeScript/JavaScript** | `.ts`, `.tsx`, `.js`, `.jsx` | ES6 imports/exports, type definitions |
| **Go** | `.go` | Package/import analysis, struct/interface parsing |
| **PHP** | `.php` | Class/function extraction, namespace support |
| **C++** | `.cpp`, `.cc`, `.cxx`, `.c++`, `.c`, `.h`, `.hpp`, `.hxx`, `.cppm`, `.ixx`, `.mxx`, `.ccm`, `.cxxm` | Include analysis, class/function extraction, C++20 module support |
| **Ruby** | `.rb` | Class/module extraction, method definitions |
| **Java** | `.java` | Import analysis, class/method extraction |
| **Swift** | `.swift` | Class/struct/protocol extraction, import analysis |
| **Svelte** | `.svelte` | Component structure, script/style block extraction |
| **Lua** | `.lua` | Function and table extraction |
| **CSS** | `.css` | Rule and selector extraction |
| **JSON** | `.json` | Structure analysis, key extraction |
| **Bash** | `.sh`, `.bash` | Function and variable extraction |
| **Markdown** | `.md` | Document section indexing, header extraction |

## πŸ“š Documentation

- **[Getting Started]doc/GETTING_STARTED.md** β€” First steps and basic workflow
- **[Installation Guide]INSTALL.md** β€” Detailed methods and building from source
- **[MCP Client Setup]doc/MCP_CLIENTS.md** β€” Connect to Claude, Cursor, Windsurf, and 15+ clients
- **[MCP Integration]doc/MCP_INTEGRATION.md** β€” MCP server details and advanced configuration
- **[Commands Reference]doc/COMMANDS.md** β€” Complete CLI reference
- **[Configuration]doc/CONFIGURATION.md** β€” Templates and customization
- **[API Keys]doc/API_KEYS.md** β€” Provider setup guide
- **[Architecture]doc/ARCHITECTURE.md** β€” How it works under the hood
- **[Contributing]doc/CONTRIBUTING.md** β€” Development setup

## πŸ”’ Privacy & Security

- **🏠 Local-first** β€” local embedding models available on supported platforms (macOS ARM default builds); cloud providers on all platforms
- **πŸ” Secure** β€” API keys stored locally, env vars supported
- **🚫 Respects .gitignore** β€” Never indexes sensitive files
- **πŸ›‘οΈ MCP security** β€” Local-only server, no external network for search
- **πŸ“€ Cloud-safe** β€” Embeddings process only metadata, never source code

<details>
<summary><strong>πŸ“Š Retrieval Quality Benchmark</strong></summary>

We measure semantic search quality using a hand-annotated ground truth dataset of 254 queries (127 code + 127 docs) with precise line-range annotations. Each query has 1–3 expected results scored by relevance.

Tested on commit [`b1771ba`](https://github.com/Muvon/octocode/commit/b1771ba) with [benchmark config](benchmark/config.toml) (contextual retrieval, Voyage reranker, RaBitQ quantization).

<details>
<summary><strong>Documentation search</strong> (<code>--mode docs</code>) β€” Hit@10: 0.953, MRR: 0.776</summary>

| Metric | Score |
|--------|-------|
| Hit@5 | 0.929 (118/127) |
| Hit@10 | 0.953 (121/127) |
| MRR | 0.776 |
| NDCG@10 | 0.801 |
| Recall@5 | 0.902 |
| Recall@10 | 0.921 |

**Missed queries** (6 of 127):

| # | Query | Expected | Got (top 1) |
|---|-------|----------|-------------|
| 43 | how to set up MCP proxy for managing multiple repositories | `doc/MCP_INTEGRATION.md:286-311` | `doc/MCP_INTEGRATION.md:286-4` |
| 51 | what are the prerequisites before using octocode | `doc/GETTING_STARTED.md:6-12` | `doc/CONTRIBUTING.md:7-33` |
| 59 | what to do when hitting API rate limits | `doc/GETTING_STARTED.md:209-216` | `doc/PERFORMANCE.md:304-356` |
| 75 | typical performance metrics for small medium and large projects | `doc/PERFORMANCE.md:4-13` | `doc/PERFORMANCE.md:414-14` |
| 112 | how to install octocode on different operating systems | `INSTALL.md:4-14` | `INSTALL.md:49-70` |
| 115 | how to fix macOS Gatekeeper blocking the binary | `INSTALL.md:199-206` | `INSTALL.md:198-119` |

</details>

<details>
<summary><strong>Code search</strong> (<code>--mode code</code>) β€” Hit@10: 0.992, MRR: 0.895</summary>

| Metric | Score |
|--------|-------|
| Hit@5 | 0.992 (126/127) |
| Hit@10 | 0.992 (126/127) |
| MRR | 0.895 |
| NDCG@10 | 0.906 |
| Recall@5 | 0.962 |
| Recall@10 | 0.974 |

**Missed queries** (1 of 127):

| # | Query | Expected | Got (top 1) |
|---|-------|----------|-------------|
| 105 | how does the system ensure two developers get the same database path | `src/storage.rs:60-83` | `src/mcp/proxy.rs:631-644` |

</details>

Metrics: **Hit@k** (did the answer appear?), **MRR** (how high?), **NDCG@10** (are best results ranked first?), **Recall@k** (how many found?). See [benchmark/](benchmark/) for methodology, scoring script, and the full dataset.

</details>

## 🀝 Community & Support

- ⭐ **Star us on GitHub** β€” It really helps!
- πŸ› [Report Issues]https://github.com/Muvon/octocode/issues
- πŸ’¬ [Discussions]https://github.com/Muvon/octocode/discussions
- πŸ“§ [opensource@muvon.io]mailto:opensource@muvon.io
- 🌐 [muvon.io]https://muvon.io

## βš–οΈ License

Apache License 2.0 β€” See [LICENSE](LICENSE) for details.

---

<div align="center">

**Built with πŸ¦€ Rust by [Muvon](https://muvon.io) in Hong Kong**

[⭐ Star](https://github.com/Muvon/octocode) β€’ [🍴 Fork](https://github.com/Muvon/octocode/fork) β€’ [πŸ“£ Share](https://twitter.com/intent/tweet?text=Octocode%20-%20AI-powered%20code%20intelligence%20with%20built-in%20MCP%20server&url=https://github.com/Muvon/octocode)

</div>

mcp-name: io.github.Muvon/octocode