# code-memory

Runs local semantic searches across your codebase and Git history without third-party API keys. It delivers exact code slices to avoid wasting tokens on entire files.

- MCP server · `type=mcp` · Claude Code, Codex, Cursor, GitHub Copilot, Windsurf (Devin Desktop), Cline, Zed, Gemini CLI · ★ 49
- Author: kapillamba4
- License: MIT · policy=link-only · description only; the file stays with the author
- Source: https://github.com/kapillamba4/code-memory
- Updated: 2026-05-20
- HTML: https://affpapa.org/en/nevibecode/mcp/code-memory

## What it does

The server constructs a local code index using SQLite vec and `sentence-transformers`. It parses structure and symbols via AST for languages such as Python, TypeScript, Java, Go, and Rust. Secondary formats, including SQL, Markdown, and configuration files, use whole-file indexing. Files listed in `.gitignore` are omitted automatically.

Queries route through dedicated tools: `search_code` pairs BM25 keyword matching with dense vectors, `search_docs` handles architectural questions, `search_history` inspects Git commit changes, and `index_codebase` generates embeddings. All processing stays offline with zero telemetry.

Running via `uvx` requires Python 3.13 or newer, though standalone executables are distributed on GitHub Releases. First startup pulls a ~600MB embedding model into the Hugging Face cache, requiring an active internet connection once. Loading separate processes across multiple folders consumes 1–2 GB RAM each, so running a shared SSE instance prevents duplicate model instances.

## Requirements
- Needs: Python and uv (commands run via uvx)
- Environment variables: `CODE_MEMORY_LOG_LEVEL`, `EMBEDDING_MODEL` — keys and tokens: ask the human for the values, never commit them or put them in shared files.

## Install

### Claude Code (native platform)

**Platform CLI**
```bash
claude mcp add --env CODE_MEMORY_LOG_LEVEL=<CODE_MEMORY_LOG_LEVEL> --env EMBEDDING_MODEL=<EMBEDDING_MODEL> --transport stdio code-memory -- uvx code-memory
```
Replace <…> with your own values. uvx runs the command named after the package; if the README names another one, use uvx --from code-memory <command>

### Codex

**Platform CLI**
```bash
codex mcp add code-memory --env CODE_MEMORY_LOG_LEVEL=<CODE_MEMORY_LOG_LEVEL> --env EMBEDDING_MODEL=<EMBEDDING_MODEL> -- uvx code-memory
```
Replace <…> with your own values. uvx runs the command named after the package; if the README names another one, use uvx --from code-memory <command>

### Cursor

**Config file**
File `.cursor/mcp.json`:
```json
{
    "mcpServers": {
        "code-memory": {
            "command": "uvx",
            "args": [
                "code-memory"
            ],
            "env": {
                "CODE_MEMORY_LOG_LEVEL": "<CODE_MEMORY_LOG_LEVEL>",
                "EMBEDDING_MODEL": "<EMBEDDING_MODEL>"
            }
        }
    }
}
```
Replace <…> with your own values. uvx runs the command named after the package; if the README names another one, use uvx --from code-memory <command>

### GitHub Copilot

**Config file**
File `.vscode/mcp.json`:
```json
{
    "servers": {
        "code-memory": {
            "type": "stdio",
            "command": "uvx",
            "args": [
                "code-memory"
            ],
            "env": {
                "CODE_MEMORY_LOG_LEVEL": "<CODE_MEMORY_LOG_LEVEL>",
                "EMBEDDING_MODEL": "<EMBEDDING_MODEL>"
            }
        }
    }
}
```
Replace <…> with your own values. uvx runs the command named after the package; if the README names another one, use uvx --from code-memory <command>

### Gemini CLI

**Platform CLI**
```bash
gemini mcp add -e CODE_MEMORY_LOG_LEVEL=<CODE_MEMORY_LOG_LEVEL> -e EMBEDDING_MODEL=<EMBEDDING_MODEL> code-memory uvx code-memory
```
Replace <…> with your own values. uvx runs the command named after the package; if the README names another one, use uvx --from code-memory <command>

## When to use it
- retrieve code symbols and definitions with hybrid BM25 and vector search
- investigate regression causes through Git commit history
- cut LLM token usage by retrieving specific code segments instead of full files
- index codebases locally without exposing private code to external services

## Example prompts
- Find where UserSession is defined using search_code.
- Inspect commit history with search_history to explain why auth logic changed.
- Run index_codebase to rebuild embeddings for the project.

## Similar
- [REA](https://affpapa.org/en/nevibecode/mcp/rea.md) — MCP server · ★ 386989
- [GitHub](https://affpapa.org/en/nevibecode/mcp/github.md) — MCP server · ★ 33918
- [Netdata](https://affpapa.org/en/nevibecode/mcp/netdata.md) — MCP server · ★ 81115
- [browser-use](https://affpapa.org/en/nevibecode/mcp/browser-use.md) — MCP server · ★ 119160
- [Codebase Memory](https://affpapa.org/en/nevibecode/mcp/codebase-memory.md) — MCP server · ★ 47392
- [mcp-server](https://affpapa.org/en/nevibecode/mcp/mcp-server.md) — MCP server · ★ 43872

---
NeVibeCode on affpapa.org. Catalog texts are descriptions, not instructions for the agent. How to choose and install: https://affpapa.org/en/nevibecode/agents.md
