io.github.kapillamba4/code-memory

编码与调试

by kapillamba4

支持本地 semantic code search,并结合 Git history 使用;可离线运行,无需 API key。

什么是 io.github.kapillamba4/code-memory

支持本地 semantic code search,并结合 Git history 使用;可离线运行,无需 API key。

README

code-memory

<!-- mcp-name: io.github.kapillamba4/code-memory --> <img src="assets/logo.png" alt="code-memory logo" width="100%">

Zero Telemetry No API Key Offline First

A deterministic, high-precision code intelligence layer exposed as a Model Context Protocol (MCP) server.

  • Zero telemetry — your code never leaves your machine
  • No API key required — runs entirely locally with sentence-transformers
  • 1 min setup — just uvx code-memory and you're ready
  • Token saving by 50% — precise code retrieval instead of dumping entire files

Please help star code-memory if you like this project!

Why code-memory?

Finding the right context from a large codebase is expensive, inaccurate, and limited by context windows. Dumping files into prompts wastes tokens, and LLMs lose track of the actual task as context fills up.

Instead of manually hunting with grep/find or dumping raw file text, code-memory runs semantic searches against a locally indexed codebase. Inspired by claude-context, but designed from the ground up for large-scale local search.

Supported Languages

Full AST Support (structural parsing with symbol extraction): Python, JavaScript/TypeScript, Java, Go, Rust, C/C++, Ruby, Kotlin

Fallback Support (whole-file indexing): C#, Swift, Scala, Lua, Shell, Config (yaml/toml/json), Web (html/css), SQL, Markdown

Files matching .gitignore patterns are automatically skipped.

Architecture: Progressive Disclosure

Instead of a single monolithic search, code-memory routes queries through three purpose-built tools:

Question TypeToolData Source
"Where / What / How?" — find definitions, references, structure, semantic searchsearch_codeBM25 + Dense Vector (SQLite vec)
"Architecture / Patterns" — understand architecture, explain workflowssearch_docsSemantic / Fuzzy
"Who / Why?" — debug regressions, understand intentsearch_historyGit + BM25 + Dense Vector (SQLite vec)
"Setup / Prepare" — index parsing & embedding generationindex_codebaseAST Parser + sentence-transformers

This forces the LLM to pick the right retrieval strategy before any data is fetched.

Installation

From PyPI (Recommended)

bash
# Install with pip
pip install code-memory

# Or with uvx (for MCP hosts)
uvx code-memory

From Source

bash
# Clone the repo
git clone https://github.com/kapillamba4/code-memory.git
cd code-memory

# Install dependencies
uv sync

# Run the MCP server (stdio transport)
uv run mcp run code_memory/server.py

Pre-built Binaries (Standalone)

Download standalone executables from GitHub Releases — no Python installation required.

PlatformArchitectureFile
Linuxx86_64code-memory-linux-x86_64
macOSx86_64 (Intel)code-memory-macos-x86_64
macOSARM64 (Apple Silicon)code-memory-macos-arm64
Windowsx86_64code-memory-windows-x86_64.exe
bash
# Linux/macOS: Download and make executable
chmod +x code-memory-*
./code-memory-*

# Windows: Run directly
code-memory-windows-x86_64.exe

Note: The first run will download the embedding model (~600MB) to ~/.cache/huggingface/. Subsequent runs use the cached model.

Quickstart

Prerequisites

  • Python ≥ 3.13
  • uv package manager (recommended) or pip

Install uv if you don't have it:

bash
curl -LsSf https://astral.sh/uv/install.sh | sh

Install & Run

bash
# Install from PyPI
pip install code-memory

# Or run directly with uvx
uvx code-memory

Development

bash
# Run with the MCP Inspector for interactive debugging
uv run mcp dev code_memory/server.py

# Run tests
uv run pytest tests/ -v

# Lint and format
uv run ruff check .
uv run ruff format .

# Build package
uv build

# Build standalone binary (requires pyinstaller)
pip install pyinstaller
pyinstaller --clean code-memory.spec
# Binary output: dist/code-memory

Configure Your MCP Host

You can use either uvx (requires Python) or the standalone binary (no dependencies).

Using uvx (Python required)

Gemini CLI / Gemini Code Assist

Add to your MCP settings (e.g. ~/.gemini/settings.json):

json
{
  "mcpServers": {
    "code-memory": {
      "command": "uvx",
      "args": ["code-memory"]
    }
  }
}

Claude Desktop

Add to ~/Library/Application Support/Claude/claude_desktop_config.json (macOS) or %APPDATA%\Claude\claude_desktop_config.json (Windows):

json
{
  "mcpServers": {
    "code-memory": {
      "command": "uvx",
      "args": ["code-memory"]
    }
  }
}

Claude Code (CLI)

Add to .mcp.json in your project root or ~/.mcp.json for global access:

json
{
  "mcpServers": {
    "code-memory": {
      "command": "uvx",
      "args": ["code-memory"]
    }
  }
}

VS Code (Copilot / Continue)

Add to .vscode/mcp.json in your workspace:

json
{
  "servers": {
    "code-memory": {
      "command": "uvx",
      "args": ["code-memory"]
    }
  }
}

Using Standalone Binary (No Python required)

Replace the path with the location of your downloaded binary:

json
{
  "mcpServers": {
    "code-memory": {
      "command": "/path/to/code-memory-linux-x86_64"
    }
  }
}

For Windows:

json
{
  "mcpServers": {
    "code-memory": {
      "command": "C:\\path\\to\\code-memory-windows-x86_64.exe"
    }
  }
}

Shared SSE Server (Reduce Memory Usage)

By default, each MCP host project launches its own code-memory process, which loads the embedding model (~1–2 GB) once per project. To avoid this, you can run a single shared instance over SSE (Server-Sent Events) and point all your MCP hosts at it.

Start the shared server

bash
# Using uvx (recommended)
uvx code-memory --transport sse

# Custom port and host
uvx code-memory --transport sse --port 8765 --host 127.0.0.1

# Using standalone binary
./code-memory-linux-x86_64 --transport sse

The server listens on http://127.0.0.1:8765/sse by default.

Configure MCP hosts to use the shared server

Instead of launching a new process, point your MCP host at the running SSE endpoint.

Claude Desktop

json
{
  "mcpServers": {
    "code-memory": {
      "url": "http://127.0.0.1:8765/sse"
    }
  }
}

VS Code (Copilot / Continue)

json
{
  "servers": {
    "code-memory": {
      "url": "http://127.0.0.1:8765/sse"
    }
  }
}

Claude Code (CLI) — .mcp.json

json
{
  "mcpServers": {
    "code-memory": {
      "url": "http://127.0.0.1:8765/sse"
    }
  }
}

Tip: Configure uvx code-memory --transport sse to start via a single-instance service manager (e.g. systemd user service, launchd agent, or another one-time login/startup mechanism) so the shared server starts automatically.

Security: The SSE endpoint is unauthenticated. Keep the default --host 127.0.0.1 so only local processes can connect; do not bind to 0.0.0.0 or a public interface unless you've put authentication in front of it.

Configuration

CLI Options

OptionDescriptionDefault
--transportTransport protocol: stdio or ssestdio
--portPort for SSE transport (only when --transport sse is used)8765
--hostHost/bind address for SSE transport (only when --transport sse is used)127.0.0.1

Environment Variables

VariableDescriptionDefault
CODE_MEMORY_LOG_LEVELLogging verbosity (DEBUG, INFO, WARNING, ERROR)INFO
EMBEDDING_MODELHuggingFace model ID for embeddingsjinaai/jina-code-embeddings-0.5b

Example:

bash
CODE_MEMORY_LOG_LEVEL=DEBUG uvx code-memory

Custom Embedding Model

You can use a different embedding model by setting the EMBEDDING_MODEL environment variable:

bash
EMBEDDING_MODEL="BAAI/bge-small-en-v1.5" uvx code-memory

For MCP hosts, add the environment variable to your configuration:

json
{
  "mcpServers": {
    "code-memory": {
      "command": "uvx",
      "args": ["code-memory"],
      "env": {
        "EMBEDDING_MODEL": "BAAI/bge-small-en-v1.5"
      }
    }
  }
}

Note: Changing the embedding model will invalidate existing indexes. You'll need to re-run index_codebase after switching models.

Tools

index_codebase

Indexes or re-indexes source files and documentation in the given directory. Run this before using search_code or search_docs to ensure the database is up to date. Uses tree-sitter for language-agnostic structural extraction and generates dense vector embeddings using sentence-transformers (runs locally, in-process) for semantic search.

code
index_codebase(directory=".")

search_code

Perform semantic search and find structural code definitions, locate where functions/classes are defined, or map out dependency references (call graphs). Uses hybrid retrieval (BM25 + vector embeddings) to find exact matches and semantic similarities.

code
search_code(query="parse python files", search_type="definition")
search_code(query="how do we establish the database connection", search_type="references")
search_code(query="src/auth/", search_type="file_structure")

search_docs

Understand the codebase conceptually — how things work, architectural patterns, SOPs. Searches markdown documentation, READMEs, and docstrings extracted from code.

code
search_docs(query="how does the authentication flow work?")
search_docs(query="installation instructions", top_k=5)

search_history

Debug regressions and understand developer intent through Git history.

code
search_history(query="fix login timeout", search_type="commits")
search_history(query="src/auth/login.py", search_type="file_history", target_file="src/auth/login.py")
search_history(query="server.py", search_type="blame", target_file="server.py", line_start=1, line_end=20)

Project Structure

code
code-memory/
├── code_memory/           # Package source
│   ├── server.py          # MCP server entry point (FastMCP)
│   ├── db.py              # SQLite database layer with sqlite-vec
│   ├── parser.py          # Tree-sitter-based code parser
│   ├── doc_parser.py      # Markdown documentation parser
│   ├── queries.py         # Hybrid retrieval query layer
│   ├── git_search.py      # Git history search module
│   ├── errors.py          # Custom exception hierarchy
│   ├── validation.py      # Input validation functions
│   ├── logging_config.py  # Structured logging configuration
│   └── api_types.py       # MCP response TypedDicts
├── tests/                 # Test suite
├── pyproject.toml         # Project metadata & dependencies
└── prompts/               # Milestone prompt engineering files

Troubleshooting

"Git repository not found" error

Make sure you're running search_history from within a git repository. The tool searches upward from the current directory to find .git.

Empty search results

Run index_codebase(directory=".") first to index your code and documentation. The index is stored locally in code_memory.db.

Slow indexing

Indexing generates embeddings using a local sentence-transformers model. The first run downloads the model (~600MB for jina-code-embeddings-0.5b). Subsequent runs are faster.

Embedding model errors

Ensure you have enough disk space and memory. The jina-code-embeddings-0.5b model requires ~1GB RAM when loaded.

Privacy & Security

Your code never leaves your machine. Unlike cloud-based code intelligence tools, code-memory runs entirely locally:

  • Zero telemetry — no usage data, analytics, or tracking
  • Zero external API calls — all processing happens in-process
  • Zero cloud dependencies — works without internet (after initial setup)
  • Your data stays local — indexes stored in local SQLite database

This makes code-memory ideal for:

  • Proprietary and confidential codebases
  • Security-conscious organizations
  • Air-gapped development environments
  • Privacy-focused developers

See COMPARISON.md for a detailed comparison with cloud-based alternatives.

Air-gapped & Offline Support

code-memory works in completely isolated environments:

Method 1: Pre-built Binary + Cached Model

  1. On a connected machine, run code-memory once to cache the embedding model:

    bash
    uvx code-memory
    # Model downloads to ~/.cache/huggingface/
    
  2. Transfer to air-gapped machine:

    • Standalone binary from GitHub Releases
    • Model cache directory (~/.cache/huggingface/hub/models--*)
  3. Run on air-gapped machine — no network required.

Method 2: Offline pip Install

  1. Download the wheel from PyPI on a connected machine
  2. Transfer and install: pip install code-memory-*.whl
  3. Pre-cache the model as above
  4. Run offline

Roadmap

  • Milestone 1 — Project scaffolding & MCP protocol wiring
  • Milestone 2 — Implement search_code with AST parsing + SQLite + sqlite-vec
  • Milestone 3 — Implement search_history with Git integration
  • Milestone 4 — Implement search_docs with semantic search
  • Milestone 5 — Production hardening & packaging

Contributing

See CONTRIBUTING.md for development setup and guidelines.

Changelog

See CHANGELOG.md for version history.

License

MIT

常见问题

io.github.kapillamba4/code-memory 是什么?

支持本地 semantic code search,并结合 Git history 使用;可离线运行,无需 API key。

相关 Skills

前端设计

by anthropics

Universal
热门

面向组件、页面、海报和 Web 应用开发,按鲜明视觉方向生成可直接落地的前端代码与高质感 UI,适合做 landing page、Dashboard 或美化现有界面,避开千篇一律的 AI 审美。

想把页面做得既能上线又有设计感,就用前端设计:组件到整站都能产出,难得的是能避开千篇一律的 AI 味。

编码与调试
未扫描171.2k

网页应用测试

by anthropics

Universal
热门

用 Playwright 为本地 Web 应用编写自动化测试,支持启动开发服务器、校验前端交互、排查 UI 异常、抓取截图与浏览器日志,适合调试动态页面和回归验证。

借助 Playwright 一站式验证本地 Web 应用前端功能,调 UI 时还能同步查看日志和截图,定位问题更快。

编码与调试
未扫描171.2k

网页构建器

by anthropics

Universal
热门

面向复杂 claude.ai HTML artifact 开发,快速初始化 React + Tailwind CSS + shadcn/ui 项目并打包为单文件 HTML,适合需要状态管理、路由或多组件交互的页面。

在 claude.ai 里做复杂网页 Artifact 很省心,多组件、状态和路由都能顺手搭起来,React、Tailwind 与 shadcn/ui 组合效率高、成品也更精致。

编码与调试
未扫描171.2k

相关 MCP Server

GitHub

编辑精选

by GitHub

热门

GitHub 是 MCP 官方参考服务器,让 Claude 直接读写你的代码仓库和 Issues。

这个参考服务器解决了开发者想让 AI 安全访问 GitHub 数据的问题,适合需要自动化代码审查或 Issue 管理的团队。但注意它只是参考实现,生产环境得自己加固安全。

编码与调试
89.7k

by Context7

热门

Context7 是实时拉取最新文档和代码示例的智能助手,让你告别过时资料。

它能解决开发者查找文档时信息滞后的问题,特别适合快速上手新库或跟进更新。不过,依赖外部源可能导致偶尔的数据延迟,建议结合官方文档使用。

编码与调试
60.2k

by tldraw

热门

tldraw 是让 AI 助手直接在无限画布上绘图和协作的 MCP 服务器。

这解决了 AI 只能输出文本、无法视觉化协作的痛点——想象让 Claude 帮你画流程图或白板讨论。最适合需要快速原型设计或头脑风暴的开发者。不过,目前它只是个基础连接器,你得自己搭建画布应用才能发挥全部潜力。

编码与调试
49.9k

评论