KC

kapillamba4/code-memory

开发工具

本页由 AI 翻译,技术细节请以原文为准。 查看原文

50 stars 11 forks 质量 79 趋势 17MIT

MCP服务器支持本地向量搜索,支持你的代码库。智能索引、语义搜索、Git历史——全部离线。

概览

一个确定性高精度的模型上下文协议(MCP)服务器。 —— 你的代码永远不会离开你的机器 —— —— 完全本地运行,使用句子变换器 —— —— 仅用 UVX 代码内存,你就准备好了 —— 精确的代码检索,而不是转发整个文件 从庞大的代码库中找到合适的上下文是 、 和 。把文件导入提示词会浪费代币,且随着上下文填充,LLM会丢失实际任务的跟踪。 代码内存不是手动用 grep/find 寻找或导出原始文件文本,而是对本地索引代码库运行语义搜索。灵感来自 claude-context,但从零开始设计用于大规模本地搜索。 (带符号提取的结构解析):Python、JavaScript/TypeScript、Java、Go、Rust、C/C++、Ruby、Kotlin (全文件索引):C#、Swift、Scala、Lua、Shell、Config(yaml/toml/json)、Web(html/css)、SQL、Markdown 与 .gitignore 模式匹配的文件会自动跳过。

概述(AI 翻译)

一个确定性、高精度的代码智能层,作为模型上下文协议(MCP)服务器暴露。

  • 零遥测 — 你的代码永远不会离开你的机器
  • 无需API密钥 — 完全本地运行,使用句子变换器
  • 1分钟准备 — 只需按uvx code-memory,你就准备好了
  • 令牌节省50% — 精确检索代码,而非倾倒整个文件

如果你喜欢这个项目,请帮忙用星号代码记忆!

为什么是代码记忆?

从庞大的代码库中找到合适的上下文昂贵、不准确,而且受上下文窗口限制**。把文件导入提示词会浪费令牌,而且随着上下文满,LLM会丢失实际任务的跟踪。

code-memory 无需手动检索 grep/find 或转储原始文件文本,而是对本地索引代码库进行语义搜索。灵感来自 claude-context,但从零开始设计用于大规模本地搜索。

支持的语言

完整AST支持(结构解析带符号提取):Python、JavaScript/TypeScript、Java、Go、Rust、C/C++、Ruby、Kotlin

本页由 AI 翻译,技术细节请以原文为准。

README

以下为原文 README 节选,完整内容请查看原文。

code-memory

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 Type Tool Data Source
“Where / What / How?” — find definitions, references, structure, semantic search search_code BM25 + Dense Vector (SQLite vec)
“Architecture / Patterns” — understand architecture, explain workflows search_docs Semantic / Fuzzy
“Who / Why?” — debug regressions, understand intent search_history Git + BM25 + Dense Vector (SQLite vec)
“Setup / Prepare” — index parsing & embedding generation index_codebase AST Parser + sentence-transformers

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

Installation

# Install with pip
pip install code-memory

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

From Source

# 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)

在 GitHub 查看完整 README

安装

uvx code-memory
新手?先看 mcpskill.org 教程 →

配置

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