Code Index

io.github.achreftlili由 GitHub 账号 achreftlili 发布v1.0.6更新于 Oct 24, 2026

SQLite-backed hybrid (vector + FTS) code search index for Claude Code over MCP.

已验证STDIO仅桌面知识与记忆开发者工具

概览

AI 生成的概览

本地 SQLite 混合(向量 + 全文)代码索引,让助手在仓库中检索符号、文件大纲和调用关系,而不必盲目 grep。

可以做什么
  • 用向量加全文的混合检索按概念搜索代码,或按精确名称查找符号
  • 列出单个文件或整个目录子树的符号大纲,并定位某行所在的符号及其外层调用链
  • 按符号 ID 获取代码片段,支持单条或批量
  • 追踪调用图:调用者、被调用者、引用、传递调用树以及文件导入关系
  • 列出最近若干次 git 提交中改动的文件,并生成同文件重命名的编辑清单
  • 管理索引:构建或刷新索引、检查环境、安装自动重建索引钩子、查看统计并校验完整性
适用场景
适合助手在中等或较大仓库中工作、需要回答某函数在哪里定义、谁调用了它、某类逻辑位于何处,而不想整文件通读的场景。对 Python、TypeScript/JavaScript、Go 和 Rust 代码库尤其合适,离线快速检索优于盲目读取文件。
运行要求
以 PyPI 包 mcp-code-index 形式通过 stdio 在本机运行,通常用 uvx 启动或用 pip 安装。需要 Python 3.10+ 且支持可加载 SQLite 扩展(sqlite-vec),首次初始化需约 600 MB 磁盘空间用于从 Hugging Face 下载嵌入模型。无需 API 密钥或账号。可用 CODE_INDEX_DB、CODE_INDEX_EMBED_DEVICE、CODE_INDEX_EMBED_BATCH 等环境变量调整索引路径和嵌入设备。
安装前请注意
首次初始化会从 Hugging Face 下载约 600 MB 的模型,需要一次联网。可选的钩子会写入项目的 .claude/settings.json,并在每次编辑后重建索引;索引数据库默认写在 .claude/index.db。在助手之外移动文件或切换分支后索引会过期,需重新运行 init。重命名工具只返回编辑清单,由助手自行应用。

安装

在 SourceWeft 中

  1. 打开 控制台中的 Code Index,将其添加到工作区。
  2. 为需要使用其工具的对话启用该服务。

Desktop only,通过 STDIO。 STDIO 服务会启动本地进程,因此需要 SourceWeft 桌面宿主。

其他 MCP 客户端

参照 仓库 中的启动说明。

README

code-index

A local, SQLite-backed code index for Claude Code, exposed over MCP. It replaces blind Read / Grep / Glob exploration with targeted retrieval — "where is parseAuthToken defined", "what calls Indexer.reindex_all", "find the rate-limiting code" — answered in milliseconds against an offline index.

No API keys. No external services. The embedder runs locally on your machine.

How it works (30-second tour)

  1. Parse your repo with tree-sitter (Python, TypeScript/JavaScript, Go, Rust).
  2. Chunk code per symbol and expand identifiers (getUserAuthToken → get user auth token) so search matches both styles.
  3. Embed each chunk locally with jina-embeddings-v2-base-code (768-dim) via sentence-transformers.
  4. Store symbols, chunks, vectors, and call/import edges in .claude/index.db (SQLite + sqlite-vec + FTS5).
  5. Serve 14 retrieval tools + 1 admin tool over MCP (see Tools).
  6. Stay fresh via an optional PostToolUse hook that incrementally re-indexes touched files.

Tools

Retrieval

ToolPurpose
code_searchHybrid (vector + FTS) search for conceptual queries (e.g., "auth flow", "where do we parse JSON").
symbol_lookupExact-name lookup of functions / classes / methods / types. Prefer over code_search for identifiers.
file_outlineSymbols (with signatures) in a file, in source order. Use instead of Read when you only need shape.
module_outlineSymbols across a directory subtree in one call. Use instead of looping file_outline.
where_am_iGiven path + line, returns the innermost symbol and the full enclosing chain.
get_symbol_bodyFull chunk for a symbol_id from symbol_lookup / code_search / file_outline.
get_symbol_bodiesBatch version of get_symbol_body (up to 20 ids per call).
callersSymbols that CALL the given symbol. depth (1-5) expands transitively.
calleesSymbols that the given symbol CALLS. depth (1-5) expands transitively.
referencesNon-call uses (subclasses, free identifier references). Companion to callers / callees.
traceBuild a call-graph tree from an entry symbol; flat=true returns nodes/edges for cheap LLM scans.
file_importsFiles this file imports (direction=imports) or that import it (direction=imported_by).
recent_changesFiles touched in the last N git commits.
propose_renamev1: same-file rename. Returns an edit list the agent applies via its own Edit tool; refuses on clash.

Admin

Tool / opPurpose
admin op=initBuild or refresh the index. Incremental by default; force=true rebuilds from scratch.
admin op=setup_checkDiagnose hook wiring + embedder + host. Round-trip-tests the hook end-to-end.
admin op=install_hookWire the auto-reindex PostToolUse hook into .claude/settings.json. Idempotent.
admin op=statsRead-only: file counts by language, symbol totals, embed model fingerprint, last-index time.
admin op=verifyIntegrity sweep: orphan rows, parse-failure files, dangling edges.

embed_query_debug is a dev-only ranking diagnostic, hidden from list_tools unless CODE_INDEX_DEBUG=1 is set.

All tools return bounded JSON; large bodies use get_symbol_body rather than inlining whole files.

Requirements

  • Python 3.10+ with loadable SQLite extension support (required by sqlite-vec).
    • Python 3.13 has this enabled by default.
    • On 3.10–3.12, install via the python.org installer or via pyenv with PYTHON_CONFIGURE_OPTS=--enable-loadable-sqlite-extensions pyenv install 3.12.x.
    • Homebrew Python often ships without the extension hook — use one of the two methods above instead.
  • uv / uvx (install) — recommended runner. Or pip if you prefer a permanent install.
  • ~600 MB free disk for the embedding model on first init.

Quick start (Claude Code)

One command, no API keys:

bash
claude mcp add-json -s user code-index "$(cat <<'JSON'{  "type": "stdio",  "command": "uvx",  "args": ["--refresh", "--from", "mcp-code-index", "code-index-mcp"]}JSON)"

Then open Claude Code in any repo and ask:

"Build the code index for this repo."

Claude calls the init MCP tool, which writes .claude/index.db. From then on, ask things like "where is parseAuthToken defined?" or "what calls Indexer.reindex_all?" — Claude routes them through symbol_lookup / callers / code_search instead of grepping.

What --refresh does — fetches the latest PyPI release on every Claude Code launch. Convenient during preview; drop it once you want to pin a version (saves ~1s of startup).

Project-only install — drop -s user to register the server in the current project's .claude/settings.json instead of the global ~/.claude.json.

First-run model download — the first init pulls jina-embeddings-v2-base-code (~600 MB) into ~/.cache/huggingface and caches it forever. Subsequent runs are fully offline. If your network blocks Hugging Face, pre-warm the cache from a machine that has access.

Already installed without --refresh? Run claude mcp remove code-index first, then re-run the command above.

Alternative: permanent install (no uvx)

bash
pip install mcp-code-indexclaude mcp add -s user code-index -- code-index-mcp

Optional: keep the index live as you edit

Without a hook, the index drifts when files change outside the agent (mv, git checkout, IDE saves) until you call init again. With one, every Edit / Write / MultiEdit Claude performs triggers an incremental reindex of the touched file.

Easiest path: ask Claude. On first use in a new project, ask "set up the code-index" — Claude calls setup_check → install_hook → init. The hook command is derived from how the MCP server was launched (uvx-aware), so it uses the same Python toolchain. Hook output goes to .claude/code-index-hook.log so failures are debuggable.

Manual install — add this block to the project's .claude/settings.json under hooks.PostToolUse (the version you want depends on how you launch the server — install_hook derives the right one for you):

json
{  "matcher": "Edit|Write|MultiEdit",  "hooks": [    {      "type": "command",      "command": "uvx --with 'sentence-transformers<5' --with 'numpy<2' --from mcp-code-index code-index-hook"    }  ]}

In other MCP-compatible agents

The server speaks standard MCP over stdio, so any client that supports MCP servers works (Cursor, Continue, Cody, Zed, etc.). Configure the client to launch uvx --refresh --from mcp-code-index code-index-mcp (or code-index-mcp after pip install mcp-code-index). Once connected, call the init tool from inside the client to bootstrap the index. Drop --refresh when you want to pin to a stable version instead of always pulling latest.

From source (development)

bash
git clone https://github.com/achreftlili/code-indexcd code-indexpip install -e .code-index init        # CLI alternative to the `init` MCP toolcode-index-mcp         # starts the MCP server on stdio (for manual wiring)

Configuration

All settings are optional — the defaults work out of the box. Override them via environment variables. Inside Claude Code, set them in the env block of your code-index server entry in ~/.claude.json (then reconnect the MCP server).

Common knobs (most users only ever touch these):

VarDefaultWhen to set it
CODE_INDEX_EMBED_DEVICEautoForce the torch device: cpu, mps, or cuda. Set cpu on Apple Silicon if init fails with MPS out-of-memory.
CODE_INDEX_EMBED_BATCH32Encode batch size. Lower (e.g. 8 or 4) to cut peak GPU memory while staying on mps/cuda.
CODE_INDEX_DB.claude/index.dbOverride the SQLite index path (e.g. to share an index across sibling worktrees).

Advanced (rarely needed):

VarDefaultNotes
CODE_INDEX_EMBEDDERjinaOnly jina (local sentence-transformers) is supported today; the variable exists for future expansion.
CODE_INDEX_EMBED_MODELjinaai/jina-embeddings-v2-base-codeHuggingFace model id. Only override if you know the model is dim-compatible (768d).
CODE_INDEX_EMBED_DIM768Must match the embedding model's output dimension.

Troubleshooting

init fails with MPS backend out of memory on Apple Silicon. A large file produced a chunk batch bigger than your GPU's free VRAM. Quickest fix — re-run on CPU (slower but bulletproof):

json
"env": {  "CODE_INDEX_EMBED_DEVICE": "cpu"}

To stay on the GPU, shrink the batch instead: "CODE_INDEX_EMBED_BATCH": "8". Reconnect the MCP server (/mcp → reconnect, or restart Claude Code) so the new env takes effect. init is incremental — already-embedded files are skipped on the retry.

init fails with a Hugging Face network error on first run. Your network is blocking model downloads. Pre-warm the cache on a machine that has access:

bash
huggingface-cli download jinaai/jina-embeddings-v2-base-code# then copy ~/.cache/huggingface/ to the offline machine

sqlite3.OperationalError: not authorized or sqlite-vec fails to load. Your Python build doesn't have loadable SQLite extensions. See Requirements — install via python.org or a pyenv build with PYTHON_CONFIGURE_OPTS=--enable-loadable-sqlite-extensions.

code_search / symbol_lookup returns stale paths after a refactor or branch checkout. The auto-reindex hook only fires on Claude's Edit / Write / MultiEdit. After bulk file moves outside the agent (mv, git checkout, IDE rename), re-run init (it's incremental). Or wire up the hook so the index keeps up with agent edits automatically.

Layout

src/code_index/  db.py           SQLite schema, connection, sqlite-vec loading  parser.py       Tree-sitter wrapper, symbol + edge extraction  imports.py      Per-language import target → file path resolution  chunker.py      Per-symbol chunks, identifier expansion  embedder.py     Local Jina (sentence-transformers) backend  indexer.py      Pipeline: walk → parse → chunk → embed → write  reindexer.py    Per-root engine cache; one entry point for "reindex one file"  retriever.py    Hybrid search (vector + FTS5) with RRF  watcher.py      File watcher (watchdog)  admin.py        setup_check / install_hook / init logic (pure, no MCP state)  mcp_server.py   MCP wiring, shared helpers, schema fragments  tool_registry.py  Shared `@_tool` decorator + `_TOOLS` registry  tools/          Per-domain MCP handlers (graph, paths, refactor, …)  hook.py         `code-index-hook` console script — the PostToolUse entry point  cli.py          init / reindex / watch / stats

来源:README.md,提交 27a6bf8

工具

0
SourceWeft 尚未在沙箱中启动过该软件包,因此其工具未知。

版本历史

1
  1. v1.0.6最新Sep 16, 2026

评分

已满足适用检查项的 50%

该评分衡量此收录条目的完整程度,依据注册中心条目、端点与公开来源计算得出。它不是对服务器本身的评价,也不表示服务器安全或当前可用:可连通性是带日期的检查结果,评分也不包含安装量或用户评价。

  • 近 30 天内可连通25 分

    请保持端点能够响应 MCP 握手;SourceWeft 每 30 天探测一次。

  • 已声明认证方式10 分

    请在注册中心条目中声明凭据请求头,或保持端点能够响应探测,以便判定其认证方式。

  • 已列出工具15 分

    请让服务器在无凭据时响应 tools/list,或发布可在沙箱中无凭据启动的软件包。

  • 描述必需15 分
  • 图标10 分
  • 文档15 分
  • 许可证10 分