
ContextSmith
io.github.RahulSankhla312由 GitHub 帳號 RahulSankhla312 發布v0.1.1更新於 Oct 25, 2026
Give your coding agent the right code: graph + hybrid search, packed into a token budget. Local.
概覽
本機程式碼脈絡引擎:為儲存庫建立索引,依任務回傳最相關的程式碼,並打包進指定的 token 預算。
- 可以做什麼
- 依任務取程式碼:在 token 預算內回傳最相關的函式、類別與檔案大綱
- 搜尋與導覽程式碼:符號排序搜尋、符號定位、呼叫者與被呼叫者、變更的傳遞影響範圍
- 了解結構:查看由程式碼關係與 git 共同變更關聯的檔案,以及語言、規模、核心與高頻變更檔案的概覽
- 記錄知識:把筆記釘在檔案或符號上,之後的對話會在脈絡中看到
- 維護索引:強制增量重建索引,只重新讀取有變動的檔案
- 適用情境
- 適合編碼助理在大型儲存庫中工作、因全文搜尋和整檔讀取而浪費脈絡的情況。也適合希望助理從正確的函式著手、快速理解陌生程式碼或評估改動影響範圍的開發者,以及要求檢索完全留在本機完成的團隊。
- 執行需求
- 以本機 stdio 程序執行,從 PyPI 安裝(pipx 或 pip,可選 semantic 附加套件,也可用 uvx)。需要 Python 3.11-3.13 與要索引的儲存庫,透過 CTXSMITH_ROOT 或 serve 的路徑參數指定。semantic 附加套件會在首次使用時從 Hugging Face 下載開源嵌入模型;可選變數 CTXSMITH_EMBED_MODEL、CTXSMITH_RERANK_MODEL 與 FASTEMBED_CACHE_PATH 可調整模型與快取位置。不需帳號或 API 金鑰。
安裝
在 SourceWeft 中
- 開啟 儀表板中的 ContextSmith,將其新增到工作區。
- 為需要使用其工具的對話啟用該服務。
Desktop only,透過 STDIO。 STDIO 服務會啟動本機處理程序,因此需要 SourceWeft 桌面主機。
其他 MCP 客戶端
參照 儲存庫 中的啟動說明。
README
ContextSmith
Give your coding agent the right code, not more code.
A local context engine for Claude Code, Cursor, Codex and any MCP agent. It indexes your repository into a code graph, hybrid search and git history, and answers every task with the code that matters, packed into a token budget you choose.
[CI] [PyPI] [Python] [License: MIT]
[ContextSmith indexing Flask, ranking files for a bug report, packing context into a token budget and printing the Claude Code setup]▶ Watch the 60-second video: indexing, context packing, live MCP calls and the benchmark.
Coding agents spend their context window on the wrong code. They grep, open whole files, and run out of room before they reach the function that needs the fix, and you pay for every token they read. ContextSmith answers one question as well as possible: given this task and N tokens, what code should the agent read?
Measured on 114 Django issues from SWE-bench Lite that no tuning step ever saw. Method and full results.
Quickstart (60 seconds)
Connect it to your agent (the command prints the exact line for your machine):
From then on the agent calls get_context itself and gets ranked, budgeted code instead of
grepping. Without the [semantic] extra everything still works, using keyword search only.
Who it's for
Developers
- Faster, better agent sessions on big repos. The agent starts from the right functions instead of exploring; fewer wrong edits and "I couldn't find it" loops.
- Understand unfamiliar code.
ctxsmith context "where are payment retries handled?"returns the relevant functions with their file and line numbers. - Change safely.
ctxsmith impact charge_cardlists everything that calls it, transitively: what a change could break, before you make it. - Remember the gotchas.
ctxsmith note add "never call without the account lock" --symbol charge_cardpins a note to the code; it shows up in every future context for that code, for you and for the agent.
Teams and companies
Typical rollout: each developer installs it with pipx, runs ctxsmith index in the
repositories they work on, and adds one MCP line to their agent. There is nothing to host.
See Using it at a company for CI and offline setups.
Builders of AI tools
ContextSmith is also a Python library. Use it as the retrieval layer of your own agent, review bot or internal assistant:
Results
The test: take a real GitHub issue from SWE-bench Lite, check the repository out at the issue's own commit (so no future code or history leaks in), give the issue text to the tool, and check whether the code the real fix changed comes back.
Final test on Django: 114 issues that no tuning step ever saw.
The baseline pastes BM25-ranked files whole until the budget runs out, which is what "search the repo and open files" agents do. ContextSmith spends the same tokens on the functions that matter and outlines of the rest, so the right file almost always makes it in.
All strategies and ablations
Full numbers: bench/results-django/summary.md.
What the ablations say, including what didn't work:
- Embeddings earn their place: adding them to the lexical ranker lifts top-5 from 79% to 85% and exact-line coverage from 42% to 48%.
- The cross-encoder re-rank hurts the top result (52% → 34%) at 8x the latency, so it is off by default and marked experimental. A general web-search re-ranker doesn't understand issue-to-code relevance; a code-trained one is on the roadmap.
- Git commit history is mixed: it helped on the tuning repositories, but on Django removing it raises recall@1 by 4 points. It stays on because the default was fixed before the Django run; changing it now would be tuning on the test set.
- At 8,000 tokens whole files catch up on exact lines (49% vs 51%): every Django fix here touches one file, and at that budget it often fits whole.
Method. Weights were chosen by grid search on 89 issues from 8 other repositories
(pytest, requests, flask, sphinx, pylint, xarray, astropy, seaborn) with
bench/tune.py and
bench/tune_pack.py,
then frozen before Django was run once. Reproduce it with
ctxsmith bench --repos django/django (first run: about two hours on a laptop).
How it works
One SQLite file per repository holds everything: files, symbols, call and import edges,
three FTS5 indexes, git statistics, team notes, and the vector index (a vec0 virtual table
from sqlite-vec; a numpy fallback runs where SQLite
can't load extensions).
Retrieval (RAG). Each signal produces its own ranked list of files; reciprocal-rank fusion combines them, so no single noisy signal dominates:
The weights come from a grid search (bench/tune.py) on 89 SWE-bench Lite issues from 8
repositories and were then checked on Django, which tuning never saw.
What gets embedded, and why. Not whole files and not raw chunks: one short summary per function or class — path, qualified name, signature, first docstring sentence. On a laptop CPU this is ~30x cheaper than embedding bodies, and it is what identifies "which function is this about". Vectors are cached by content hash, so a function that didn't change is never embedded twice — across re-indexes and across git checkouts. Test files are skipped.
Experimental re-rank. ctxsmith context --rerank re-scores the top 20 files with a
cross-encoder (ms-marco-MiniLM-L-6-v2). It is off by default because the benchmark shows it
hurts (see Results).
Packing. Candidates are function bodies (matched by name, docstring and body text), class outlines and file outlines. A greedy knapsack takes the best value per token, discounts repeats from one file, and enforces the budget on the final rendered text, so the answer is never over budget.
Always fresh. Re-indexing compares file size and mtime before reading anything and only re-parses and re-embeds what changed; checking an unchanged 2,800-file repository takes about half a second. The MCP server does this before answering (at most every 2 seconds), so the agent never reads code it has just edited from a stale index.
Use it from your agent (MCP)
ctxsmith mcp-config <client> prints the exact snippet for your machine.
Claude Code
No install, with uv (the server indexes the folder the agent opens):
Cursor, Windsurf and other clients (mcp.json):
Codex (~/.codex/config.toml):
CLI
Python API
Configuration
The index lives in <repo>/.contextsmith/ (git-ignored automatically). Without the
semantic extra everything still works, lexically.
Using it at a company
Per developer (the usual rollout). pipx install "contextsmith[semantic]", then
ctxsmith index in each repository and one ctxsmith mcp-config line per agent. Nothing to
host, no accounts, no shared service to secure.
In CI: give a review bot the code a pull request is about.
Feed pr-context.md to whichever review model you use, or post ctxsmith impact <function>
output as a comment so reviewers see the blast radius.
Offline and air-gapped machines.
What is stored, and where. One SQLite file per repository in <repo>/.contextsmith/:
symbols, search indexes, call graph, git statistics and commit messages, notes, and
embedding vectors. It is git-ignored automatically and never uploaded anywhere. ContextSmith
has no telemetry; the only downloads are the open embedding model from Hugging Face on first
use (none without the semantic extra) and, if you run ctxsmith bench, the public benchmark.
FAQ
Does my code leave my machine? No. Parsing, search, embeddings and the MCP server all run locally. Your agent still sends the context it receives to its own model provider, as it would with any file it reads; ContextSmith just makes that context smaller and more relevant.
How big a repository can it handle? Measured on Django (2,800 files, 38,000 functions and classes) on a laptop CPU: 16 s to build the code graph, search and git index from scratch, about 3.5 minutes to embed everything the first time, 0.2 s per query, 0.5 s to check for changes, 136 MB on disk. After the first run only changed files are re-parsed and re-embedded.
Does it replace my agent's own search? No, it gives it a better starting point. The agent can still open any file; it just starts from the right functions instead of grepping.
Which models does it use? BAAI/bge-small-en-v1.5 for embeddings (ONNX, CPU, 65 MB),
changeable with CTXSMITH_EMBED_MODEL. No large language model is involved: ContextSmith
retrieves, your agent reasons.
What does it cost? Nothing. MIT licence, including commercial use.
Is it production-ready? It is v0.1: tested on Windows, macOS and Linux with Python 3.11–3.13, benchmarked in public, and honest about what doesn't work yet (see Results). Issues and pull requests are welcome.
Languages
Python, JavaScript, TypeScript/TSX, Java, Go and Rust, parsed with tree-sitter.
How it compares
Graphify, codebase-memory-mcp, GitNexus, Serena and Claude Context are good tools; this is where ContextSmith differs:
Roadmap
Multi-repo indexes, note staleness tracking, a file watcher, a graph view, a PR impact report, and more languages. Ideas and benchmark-backed pull requests are welcome: see CONTRIBUTING.md.
Licence
MIT
來源:README.md,提交 d33e602
工具
0版本歷史
1- v0.1.1最新Oct 25, 2026
評分
已滿足適用檢查項的 50%
該評分衡量此收錄條目的完整程度,依據註冊中心條目、端點與公開來源計算得出。它不是對伺服器本身的評價,也不表示伺服器安全或目前可用:可連通性是帶日期的檢查結果,評分也不包含安裝量或使用者評價。
- 近 30 天內可連通25 分
請保持端點能夠回應 MCP 握手;SourceWeft 每 30 天探測一次。
- 已宣告認證方式10 分
請在註冊中心條目中宣告憑證請求標頭,或保持端點能夠回應探測,以便判定其認證方式。
- 已列出工具15 分
請讓伺服器在無憑證時回應 tools/list,或發布可在沙箱中無憑證啟動的軟體包。
- 描述必需15 分
- 圖示10 分
- 文件15 分
- 授權條款10 分
