
Code Context Engine
io.github.ai-elara由 GitHub 帳號 ai-elara 發布v0.4.13更新於 Oct 24, 2026
Index your codebase. AI searches instead of re-reading files. 94% token savings.
概覽
本機程式碼庫索引,讓 AI 助理檢索語意程式碼片段並回想過往工作階段決策,而不必重讀整個檔案。
- 可以做什麼
- 以向量與關鍵字混合檢索在已索引的程式碼庫中尋找程式碼,並把壓縮後的結果展開為完整原始碼,或沿呼叫與匯入關係找出相關程式碼。回想過往工作階段:讀取先前記錄的決策與程式碼區域、瀏覽工作階段時間軸、檢視原始事件。記錄新的決策與程式碼區域,讓上下文在重新啟動後保留。檢查索引是否最新,並重新索引單一檔案或整個專案。調整助理回覆的精簡程度。
- 適用情境
- 適合助理需要在中大型程式碼庫中反覆工作、希望它定位相關函式而不是通讀整個檔案時使用,也適合希望架構決策能跨工作階段延續的情境。定位為本機、私密的索引,可服務多個編輯器。
- 執行需求
- 以本機程序方式透過 uvx 或 pip/pipx 安裝執行;需要 Python 3.11+ 以及供 tree-sitter 文法使用的 C 編譯器。嵌入向量在本機透過 ONNX 執行,或使用本機/遠端 Ollama。未宣告需要 API 金鑰或帳號。安裝過程會寫入編輯器設定檔與指令檔。
安裝
在 SourceWeft 中
- 開啟 儀表板中的 Code Context Engine,將其新增到工作區。
- 為需要使用其工具的對話啟用該服務。
Desktop only,透過 STDIO。 STDIO 服務會啟動本機處理程序,因此需要 SourceWeft 桌面主機。
其他 MCP 客戶端
參照 儲存庫 中的啟動說明。
README
Code Context Engine
Index your codebase. AI searches instead of re-reading files.
94% token savings, reproducibly benchmarked.
Website · Docs · Why CCE? · Benchmark · GitHub
[PyPI] [Downloads] [CI] [MCP Registry] [MIT License] [Stars]
Python 3.11+ · macOS · Linux · Windows
[Claude Code] [VS Code] [Cursor] [Gemini CLI] [Codex CLI] [OpenCode] [Tabnine] [Pi]
One command. Auto-detects your editor. Zero cloud, zero config.
[Talk: We Cut 94% of Our AI Coding Tokens — AI Engineer World's Fair 2026]
Talk: We Cut 94% of Our AI Coding Tokens — AI Engineer World's Fair 2026
Use cases
Quick start
One command. 30 seconds.
Or if you prefer a persistent install:
Restart your editor. Done. Every question now hits the index instead of re-reading files.
Agent Plugin support: Run
cce init --pluginto generate a portable Agent Plugin directory that works with VS Code, Cursor, Copilot, Codex, ChatGPT, and Kiro. The plugin usesuvxto launch CCE on demand, so users don't need to pre-install the Python package. See Agent Plugin below.
Already have Ollama? Skip
[local]and useuv tool install code-context-engineinstead. CCE auto-detects Ollama at localhost:11434 and usesnomic-embed-text.
System requirements
Python 3.11+ and a C compiler (for tree-sitter grammars).
Tested on macOS, Linux, Windows with Python 3.11/3.12/3.13.
cce init auto-detects your editor and writes the right config. To target a
specific agent, use --agent claude, --agent codex, --agent copilot, --agent pi, or
--agent all.
Multiple editors in the same project? All get configured in one command.
Codex note: Codex CLI reads MCP servers from ~/.codex/config.toml only —
it has no per-project config. cce init adds one [mcp_servers.cce-<project>-<hash>]
section per project so multiple projects coexist; cce uninstall removes only
the section for the current project.
Pi note: Pi does not support MCP natively. To use CCE with Pi, you need a
pi MCP adapter extension (e.g. pi-mcp-adapter)
that consumes the .mcp.json config and exposes CCE's tools to the Pi agent.
cce init sets up both .mcp.json and AGENTS.md (Pi loads the latter
automatically for startup instructions).
Supports Anthropic, OpenAI, and Google model pricing. Configure via pricing.model in ~/.cce/config.yaml.
Why this matters
Input tokens are 85-95% of your Claude Code bill. CCE cuts them by 94% (benchmarked on FastAPI).
Benchmark: FastAPI (reproducible)
We benchmarked CCE against FastAPI (53 source files, 180K tokens) with 20 real coding questions. No cherry-picking, no synthetic queries.
Methodology: For each query, "without CCE" means reading the full content of every file the query touches. "With CCE" means the relevant chunks after compression.
Important baseline note: The 94% number is measured against full-file reads, not against what Claude Code actually does. In practice, Claude Code already uses grep, partial file reads, and targeted tools, so the real-world savings compared to normal Claude Code behavior will be lower than 94%. We use full-file as the baseline because it's reproducible and deterministic (no agent behavior variability). The benchmark measures CCE's retrieval efficiency, not a head-to-head comparison with Claude Code's built-in exploration.
Per-Layer Savings (each measured independently)
Output compression (reducing Claude's reply length) provides additional savings (~65% estimated) but is not included in the headline number above.
Multi-language benchmarks
Django (2,347 files, 5.4M tokens) shows CCE scales to large codebases with 0.95 recall. Go's shorter files reduce the retrieval headroom (smaller baseline). Monorepos dilute recall at top-10 (fiber). Middleware queries with one-feature-per-file hit R=1.00 consistently.
Reproduce it yourself:
Full results in benchmarks/results/. Queries and methodology in benchmarks/.
What you get
11 MCP tools that Claude uses automatically:
Live dashboard with donut charts, file health, and session history:
Dollar estimates with multi-provider pricing (Anthropic, OpenAI, Google):
How it works
- Index: Tree-sitter parses your code into semantic chunks (functions, classes, modules). Stored as vector embeddings locally.
- Search: Claude calls
context_search. Hybrid vector + BM25 retrieval finds the right chunks. Code graph adds related files automatically. - Compress: Chunks are truncated to signatures + docstrings (or LLM-summarized if Ollama is running).
- Remember: Decisions and code areas persist across sessions via
session_recall. - Track: Every query is logged.
cce savingsshows exactly how much you saved.
Re-indexing after edits takes under 1 second (96% embedding cache hit rate). Git hooks keep the index current automatically.
What makes CCE different
It saves where the money is
Output compression tools (like Caveman) save 20-75% on output tokens. Output is 5-15% of your bill. Net savings: ~11%.
CCE saves on input tokens (94% retrieval savings on FastAPI, reproducibly benchmarked). Input is 85-95% of your bill.
It actually understands your code
Not a text search. Tree-sitter AST parsing creates semantic chunks. Hybrid retrieval merges vector similarity with BM25 keyword matching via Reciprocal Rank Fusion. A confidence scorer blends similarity (50%), keyword match (30%), and recency (20%). Graph expansion walks CALLS/IMPORTS edges to pull in related code.
It remembers
record_decision("use JWT for auth", reason="session tokens flagged by legal") is stored in SQLite and surfaces via session_recall in the next session. No re-explaining your architecture.
It tracks real savings
Not estimates. Actual tokens served vs full-file baseline, broken down by buckets (retrieval, compression, output, memory, grammar). Dollar costs fetched from Anthropic's pricing page. Savings summary shown at every session start.
It is secure by default
Secret files (.env, *.pem, credentials.json) are never indexed. Content is scanned for AWS keys, GitHub tokens, Slack tokens, Stripe keys, JWTs, and generic credentials. PII (emails, IPs, SSNs, credit cards) is scrubbed from memory writes. All MCP file paths are validated against path traversal.
Under the hood
Content-Hash Embedding Cache
SHA-256 fingerprint per chunk, salted with model name. Re-index skips unchanged code. Binary float32 storage (10x smaller than JSON). Typical re-index: 96% cache hit, under 1 second.
sqlite-vec: 2 MB instead of 217 MB
Replaced LanceDB with sqlite-vec. Same cosine-distance quality, 99% smaller install. WAL mode + PRAGMA NORMAL for 80% write speedup. Vectors, FTS5, code graph, and compression cache all in three SQLite files.
Deterministic Grammar Compression
Memory entries compressed without LLM calls. Drops articles, fillers, pronouns. Three levels (lite/full/ultra, 20-60% savings). Code, paths, URLs preserved byte-for-byte. Same input always yields same output.
Fail-Closed Hook Design
5 Claude Code lifecycle hooks capture session context. Every hook runs curl ... || true, so a crashed server never blocks the user. SessionStart injects bootstrap context; others capture silently.
Multi-Provider Pricing
Dollar estimates in cce savings support 15+ models across Anthropic, OpenAI, and Google. Static pricing ships with CCE, live Anthropic pricing is fetched and cached 7 days. Configure pricing.model (e.g. gpt-4o, gemini-2.5-pro, sonnet) or override with pricing.input / pricing.output for custom rates.
Resource Governor (Multi-Instance Safety)
Running dozens of cce serve processes (one per project per AI session) can exhaust system memory. The resource governor caps ONNX Runtime threads per process, uses advisory file locks so only one process indexes a given project at a time, backs off under Linux memory pressure (PSI), and auto-shuts down idle servers after 30 minutes. Configure via serve.idle_timeout_minutes and serve.max_ort_threads.
Memory Nudges
CCE's cross-session memory depends on the agent calling record_decision and record_code_area. Memory nudges make recording ambient: after N searches without a recording, context_search results include a short reminder. At session end, the Stop hook summarizes unrecorded activity. Nudges re-arm after the first recording so they stay useful without being noisy.
HTTP Search Endpoint
cce serve --http exposes a POST /search endpoint for custom agent integrations that speak HTTP instead of MCP stdio. Same hybrid retrieval pipeline, structured JSON response with confidence scores. Input validation clamps top_k (1..100) and confidence_threshold (0.0..1.0).
Append-Only Savings Ledger
7 buckets track every token saved: retrieval, chunk compression, output compression, memory recall, grammar, turn summarization, progressive disclosure. Survives restarts. Powers CLI and dashboard analytics.
Agent Plugin
Agent Plugins is an open standard (v1.0.0) backed by Amazon, Cursor, Microsoft, OpenAI, and Vercel for packaging AI skills and MCP servers into portable, zero-install bundles. CCE can generate a plugin directory that compatible editors can discover and load automatically.
What gets generated
Compatible editors
VS Code, GitHub Copilot, ChatGPT, Codex, Cursor, and Kiro. The plugin uses uvx to launch CCE on demand, so users do not need to pre-install the Python package. The MCP server auto-discovers the project root by walking up from its working directory, looking for .context-engine.yaml or .git/.
When to use --plugin vs --agent
Both can be used together. --agent handles per-editor MCP config, --plugin provides a portable alternative.
CLI at a glance
Run cce list for the full command reference.
Configuration
Zero-config by default. Override what you need in ~/.cce/config.yaml or .context-engine.yaml:
Remote Ollama: If you run Ollama on another machine in your network, set compression.ollama_url (e.g. http://nas.local:11434) or export CCE_OLLAMA_URL (the env var wins). CCE probes the endpoint and falls back to truncation-only compression when it's unreachable, so a flaky link won't break indexing.
Output Compression
CCE also compresses Claude's responses (same concept as Caveman):
Tell Claude: "switch to max compression" or "turn off compression". Code blocks and commands are never compressed.
Disk Footprint
No GPU required. With Ollama, embeddings are handled by the Ollama server. With the [local] extra, the embedding model runs on CPU via ONNX Runtime.
Supported Languages
AST-aware chunking (tree-sitter parsed, 11 extensions):
Language-aware fallback chunking (40+ extensions):
All other text files are chunked by line range. Binary files are skipped.
Documentation
FAQ
Does CCE affect response quality?
No. Quality stays the same or slightly improves.
CCE replaces "dump the entire file" with "search for the relevant function." The model still gets the code it needs (0.90 Recall@10 in benchmarks). Less irrelevant context means less noise competing for attention, which can improve the model's focus on your actual question.
How does output token savings work?
CCE writes output compression rules directly into your agent's instruction files (CLAUDE.md, AGENTS.md, .cursorrules, etc.) during cce init. These rules apply to the entire session, not just CCE tool responses, so every reply from the agent follows them.
Set the level in ~/.cce/config.yaml or .context-engine.yaml:
Then re-run cce init to update instruction files. Or change at runtime:
Default is standard. All levels include code output rules that tell the model to show only changed lines (not full file rewrites), which is where most output tokens go in coding sessions. The max level produces very terse prose (similar to "caveman mode"). Code blocks, paths, and commands are never compressed regardless of level.
Where do the savings come from?
Most savings are input tokens (what goes into the model):
Output tokens cost 5x more per token (e.g. Opus: $15/1M input vs $75/1M output), so even a small output reduction has outsized cost impact.
Roadmap
- Multi-repo benchmarks (FastAPI, chi, fiber)
- More benchmarks (Django, Express)
- Tree-sitter support for C, C++, Ruby, Swift, Kotlin
- Docker support for remote mode
- Port to mcp 2.x API
See CHANGELOG.md for shipped features.
Contributing
Contributions welcome. See https://github.com/elara-labs/code-context-engine/blob/main/CONTRIBUTING.md for setup.
License
MIT. See LICENSE.
Authors
Acknowledgments
Claude Code · MCP · sqlite-vec · Tree-sitter · fastembed · Ollama
If CCE saves you tokens, give it a star.
來源:README.md,提交 7507115
工具
0版本歷史
1- v0.4.13最新Sep 16, 2026
評分
已滿足適用檢查項的 50%
該評分衡量此收錄條目的完整程度,依據註冊中心條目、端點與公開來源計算得出。它不是對伺服器本身的評價,也不表示伺服器安全或目前可用:可連通性是帶日期的檢查結果,評分也不包含安裝量或使用者評價。
- 近 30 天內可連通25 分
請保持端點能夠回應 MCP 握手;SourceWeft 每 30 天探測一次。
- 已宣告認證方式10 分
請在註冊中心條目中宣告憑證請求標頭,或保持端點能夠回應探測,以便判定其認證方式。
- 已列出工具15 分
請讓伺服器在無憑證時回應 tools/list,或發布可在沙箱中無憑證啟動的軟體包。
- 描述必需15 分
- 圖示10 分
- 文件15 分
- 授權條款10 分