ContextSmith is a local context engine designed to solve the problem of coding agents wasting context windows in large codebases. It indexes repositories into a code graph, hybrid search, and Git history, and returns the most relevant code based on the task and token budget.
Purpose
- Provide precise code context for coding agents (such as Claude Code, Cursor, Codex, and any MCP agent), reducing incorrect edits and "can't find it" loops.
- Help developers understand unfamiliar code: via
ctxsmith context "where are payment retries handled?"return relevant functions along with their files and line numbers. - Safe changes:
ctxsmith impact charge_cardlist all code that calls the function (transitive closure) to assess the impact of a change. - Record caveats:
ctxsmith note add "never call without the account lock" --symbol charge_cardpin comments to code so that future context automatically includes them.
Key capabilities
- Code graph: parses files, symbols, calls, and import edges.
- Hybrid search: combines lexical search (FTS5) and embedding vectors (BAAI/bge-small-en-v1.5) via reciprocal rank fusion.
- Git history: uses commit history as a signal (enabled by default, but ablation experiments show that removing it improves recall@1 by 4 percentage points on Django).
- Token-budget packing: uses a greedy knapsack algorithm to select function bodies, class outlines, and file outlines within the budget, ensuring the budget is not exceeded.
- Incremental indexing: compares file size and modification time, re-parsing and re-embedding only changed files; checking an unchanged 2800-file repository takes about 0.5 seconds.
- MCP server: via
ctxsmith mcp-config <client>generate configuration so agents can callget_contextto get ranked code. - Python library: can serve as the retrieval layer for your own agents, review bots, or internal assistants.
Usage
- Install:
pipx install "contextsmith[semantic]"(includes semantic search), or use uv without installation. - Index: run
ctxsmith indexin the repository. - Connect an agent: run
ctxsmith mcp-config <client>to get a configuration snippet and add it to the corresponding client (e.g., Cursor's mcp.json, Codex's ~/.codex/config.toml). - Command-line usage:
ctxsmith context、ctxsmith impact、ctxsmith note, etc. - Benchmark:
ctxsmith bench --repos django/django(about two hours the first time).
Use cases
- Agent sessions in large repositories: agents start from the correct function, reducing exploration.
- Code understanding: quickly locate where a feature is implemented.
- Change impact analysis: assess call chains that a modification might break.
- Team deployment: each developer installs locally; no hosted service required.
- CI integration: provide PR-related code to review bots, or publish impact reports.
- Offline/air-gapped environments: all processing runs locally.
Limitations
- Version v0.1, tested on Windows, macOS, Linux, and Python 3.11–3.13, but still early.
- Cross-encoder reranking (
--rerank)Disabled by default, as benchmarks show reduced top results (52%→34%) and 8× higher latency. - Removing the Git history signal can improve recall@1 on Django, but it is enabled by default because it was fixed before tuning.
- Supported languages: Python, JavaScript, TypeScript/TSX, Java, Go, Rust (via tree-sitter).
- The embedding model must be downloaded from Hugging Face (65 MB) on first use, with no telemetry.
- It does not replace the agent's own search; it only provides a better starting point.
- No LLM involvement, retrieval only.
- Features such as multi-repository indexing, comment staleness tracking, file watcher, graph view, and PR impact reports are not yet available.