code-context-engine
Save 94% on AI coding tokens. Index your codebase, agents search instead of reading files. Works with Claude Code, Codex, Copilot, Cursor, Gemini CLI. Local MCP server, free, open source.
Documentation
Code Context Engine
Index your codebase. AI searches instead of re-reading files.94% token savings, reproducibly benchmarked.
· · · ·
Python 3.11+ · macOS · Linux · Windows
One command. Auto-detects your editor. Zero cloud, zero config.
Talk: — AI Engineer World's Fair 2026
Use cases
| Use case | How CCE helps | |
|---|---|---|
| 💰 | Reduce Claude Code costs | 94% fewer input tokens per session |
| 🔒 | Keep code private | Everything local, no cloud indexing |
| 🔄 | Multi-editor teams | One index across Claude Code, Cursor, VS Code, Gemini CLI |
| 🧠 | Cross-session memory | Decisions and context survive restarts |
| ⚡ | Faster responses | Less context = faster Claude replies |
| 📊 | Track actual savings | Dollar amounts, not estimates |
Quick start
One command. 30 seconds.
uvx --from "code-context-engine[local]" cce init # install + index + configure, one shotOr if you prefer a persistent install:
uv tool install "code-context-engine[local]" # or: pipx install "code-context-engine[local]"
cd /path/to/your/project
cce initRestart your editor. Done. Every question now hits the index instead of re-reading files.
> Agent Plugin support: Run `cce init --plugin` to generate a portable
> Agent Plugin directory that works with
> VS Code, Cursor, Copilot, Codex, ChatGPT, and Kiro. The plugin uses
> `uvx` to 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 use `uv tool install code-context-engine` instead. CCE auto-detects Ollama at localhost:11434 and uses `nomic-embed-text`.
System requirements
Python 3.11+ and a C compiler (for tree-sitter grammars).
| Platform | Setup |
|---|---|
| macOS | `xcode-select --install` |
| Ubuntu/Debian | `sudo apt install build-essential cmake` |
| Fedora/RHEL | `sudo dnf install gcc gcc-c++ cmake` |
| Windows | Visual Studio Build Tools (C++ workload) + CMake |
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`.
| Editor | Config written | Instructions |
|---|---|---|
| Claude Code | `.mcp.json` | `CLAUDE.md` |
| VS Code / Copilot | `.vscode/mcp.json` | `.github/copilot-instructions.md` |
| Cursor | `.cursor/mcp.json` | `.cursorrules` |
| Gemini CLI | `.gemini/settings.json` | `GEMINI.md` |
| OpenAI Codex | `~/.codex/config.toml` (user-global, per-project section) | `AGENTS.md` |
| OpenCode | `opencode.json` | |
| Tabnine | `.tabnine/agent/settings.json` | `TABNINE.md` |
| Pi | `.mcp.json` | `AGENTS.md` |
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--]`
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).
my-project · 38 queries · last query 5m ago
⛁ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ 88% tokens saved
Input savings 1.9M tokens $27.78
Output savings 4.8k tokens $0.36
──────────────────────────────────────────
Total saved 1.9M tokens $28.15
Breakdown:
retrieval 84% ▰▰▰▰▰▰▰▰▰▰ 1.8M $26.76 · 12 calls
chunk compression 3% ▰▱▱▱▱▱▱▱▱▱ 68.5k $1.03 · 12 calls
output compression*
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](https://agent-plugins.org) 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.cce init --plugin # Generate at .cce/plugin/
cce init --plugin --plugin-dir ~/plugins/cce # Custom location
cce init --agent claude --plugin # Both: agent config + plugin
### What gets generated.cce/plugin/
├── plugin.json # Agent Plugins v1.0.0 manifest
├── mcp.json # MCP server config (uvx + stdio)
├── skills/
│ └── code-context/
│ ├── SKILL.md # Agent instructions (frontmatter + body)
│ └── references/
│ └── tools.md # Per-tool parameter docs (loaded on demand)
└── LICENSE
### 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`
| | `--agent` (default) | `--plugin` |
|---|---|---|
| Install method | Writes editor-specific config files | Generates a portable plugin directory |
| Zero-install | No, CCE must be on PATH | Yes, `uvx` fetches CCE on demand |
| Instruction updates | Stale until `cce init` re-run | Stale until `cce init --plugin` re-run |
| Best for | Your own machine | Sharing with a team or distributing |
Both can be used together. `--agent` handles per-editor MCP config, `--plugin` provides a portable alternative.
---
## CLI at a glancecce init # Index + install hooks + register MCP
cce init --plugin # Generate Agent Plugin for VS Code, Cursor, etc.
cce # Status banner
cce savings # Token savings with dollar estimates
cce savings --all # All projects
cce dashboard # Web dashboard with live charts
cce search "auth flow" # Test a query
cce status # Index health + config
cce services # Ollama + dashboard + MCP status
cce commands add-rule '...' # Project rules for Claude
cce uninstall # Clean removal of all CCE artifacts
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`:compression:
| level: standard # minimal | standard | full | |
|---|---|---|---|
| output: standard # off | lite | standard | max |
ollama_url: http://localhost:11434 # point at a remote Ollama if desired
retrieval:
top_k: 20
confidence_threshold: 0.5
pricing:
model: opus # opus | sonnet | haiku | gpt-4o | gemini-2.5-pro | ...
# input: 15.0 # override $/1M input tokens
# output: 75.0 # override $/1M output tokens
**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):
| Level | Style | Savings |
|-------|-------|---------|
| `off` | Full output | 0% |
| `lite` | No filler or hedging | ~30% |
| `standard` | Fragments, drop articles | ~65% |
| `max` | Telegraphic | ~75% |
Tell Claude: "switch to max compression" or "turn off compression". Code blocks and commands are never compressed.
---
## Disk Footprint
| Component | Size |
|-----------|------|
| Core install (Ollama backend) | ~17 MB |
| With `[local]` extra (fastembed + ONNX) | ~189 MB |
| Embedding model (one-time download) | ~60 MB (fastembed) or managed by Ollama |
| Index per project (small/medium/large) | 5-60 MB |
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 | Extensions |
|----------|-----------|
| Python | `.py` |
| JavaScript | `.js`, `.jsx` |
| TypeScript | `.ts`, `.tsx` |
| PHP | `.php` |
| Go | `.go` |
| Rust | `.rs` |
| Java | `.java` |
| C# | `.cs` |
**Language-aware fallback chunking (40+ extensions):**
| Category | Languages |
|----------|-----------|
| Web | HTML, CSS, SCSS, LESS, Vue, Svelte |
| Systems | C, C++, Zig, Nim |
| Mobile | Swift, Kotlin, Dart |
| Functional | Haskell, Scala, Clojure, Elixir, Erlang, F# |
| Scripting | Ruby, Perl, Lua, R, Bash/Zsh |
| Data/Config | JSON, YAML, TOML, XML, SQL, GraphQL, Protobuf |
| DevOps | Terraform, HCL, Dockerfile |
| Docs | Markdown |
All other text files are chunked by line range. Binary files are skipped.
---
## Documentation
| Page | Content |
|------|---------|
| [How Much Are You Spending on AI Coding Tokens?](https://elara-labs.github.io/code-context-engine/blog/real-cost-of-ai-coding-tokens.html) | The math on input vs output tokens |
| [What is CCE? (Complete Guide)](https://elara-labs.github.io/code-context-engine/blog/what-is-code-context-engine.html) | Setup, tools, how it works, FAQ |
| [How to Save Claude Code Tokens](https://elara-labs.github.io/code-context-engine/blog/save-claude-code-tokens.html) | Cost breakdown and savings guide |
| [Benchmark Deep Dive](https://elara-labs.github.io/code-context-engine/blog/benchmark-fastapi.html) | Full FastAPI benchmark methodology |
| [Comparison with Alternatives](https://elara-labs.github.io/code-context-engine/comparison.html) | CCE vs Cursor, Aider, Continue, Greptile |
| [Examples](https://github.com/elara-labs/code-context-engine/blob/main/docs/wiki/Examples.md) | Real conversations with Claude |
| [How It Works](https://github.com/elara-labs/code-context-engine/blob/main/docs/wiki/How-It-Works.md) | Full 9-stage pipeline |
| [CLI Reference](https://github.com/elara-labs/code-context-engine/blob/main/docs/wiki/CLI-Reference.md) | Every command with output |
| [Configuration](https://github.com/elara-labs/code-context-engine/blob/main/docs/wiki/Configuration.md) | All config options |
---
## 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`:compression:
output: max # off | lite | standard | max
Then re-run `cce init` to update instruction files. Or change at runtime:set_output_level output_level=max
| Level | Savings | What it does |
|-------|---------|--------------|
| `off` | 0% | No compression |
| `lite` | ~25% | Removes filler/hedging/pleasantries + diff-only for code changes |
| `standard` | ~70% | Drops articles, fragments, short synonyms + diff-only for code |
| `max` | ~80% | Telegraphic style + diff-only for code |
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):
| Layer | Type | Typical savings |
|-------|------|-----------------|
| Retrieval | Input | 94% (full files → relevant chunks) |
| Chunk compression | Input | 89% (chunks → signatures) |
| Grammar compression | Input | 13% (article/filler removal) |
| Turn summarization | Input | varies (session history) |
| Progressive disclosure | Input | varies (tool payloads) |
| Output compression | Output | 25-80% (depends on level) |
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
- [x] Multi-repo benchmarks (FastAPI, chi, fiber)
- [x] 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](CHANGELOG.md) for shipped features.
---
## Contributing
Contributions welcome. See [https://github.com/elara-labs/code-context-engine/blob/main/CONTRIBUTING.md](https://github.com/elara-labs/code-context-engine/blob/main/CONTRIBUTING.md) for setup.
---
## License
MIT. See [LICENSE](LICENSE).
## Authors
- [Fazle Elahee](https://github.com/fazleelahhee)
- [Raj](https://github.com/rajkumarsakthivel)
## Acknowledgments
[Claude Code](https://docs.anthropic.com/en/docs/claude-code) · [MCP](https://modelcontextprotocol.io) · [sqlite-vec](https://github.com/asg017/sqlite-vec) · [Tree-sitter](https://tree-sitter.github.io/) · [fastembed](https://github.com/qdrant/fastembed) · [Ollama](https://ollama.com/)
---
If CCE saves you tokens, give it a star.Frequently asked questions
What is code-context-engine?
code-context-engine is Save 94% on AI coding tokens. Index your codebase, agents search instead of reading files. Works with Claude Code, Codex, Copilot, Cursor, Gemini CLI. Local MCP server, free, open source.
How do I install code-context-engine?
Open the GitHub repository and follow its README. Most MCP servers are added to your client's MCP config, then called by your agent.
Is code-context-engine open source?
Yes — it is hosted on GitHub at https://github.com/elara-labs/code-context-engine and has 410 stars.
Related MCP tools
Cut AI token costs 95%+ on code exploration. The leading MCP server for precise, symbol-level GitHub code retrieval via tree-sitter AST. Works with Claude Code, Cursor & any MCP client. 313B+ tokens saved.
Open-source cross-agent memory layer for coding agents via MCP. Compatible with Claude Code, Codex, Cursor, Windsurf, Gemini CLI, Antigravity, OpenClaw, Hermes Agent, Oh-my-Pi, Pi, Copilot, Kiro, OpenCode, and Trae.
Open-source coding agent memory. Records issues, attempts, fixes and decisions, then warns your agent before it repeats an approach that already failed. Native MCP server for Claude Code, Cursor, Antigravity and Codex. 100% local, no cloud, no telemetry. MIT.
Give your AI agents persistent, collective memory — with deduplicating absorb, supersession lineage, semantic search, and a graph UI. Speaks MCP.
Control Gmail, Google Calendar, Docs, Sheets, Slides, Chat, Forms, Tasks, Search & Drive with AI - Comprehensive Google Workspace MCP Server & CLI Tool
AI Skills, MCP Tools, and CLI for Unity Engine. Full AI develop and test loop. Use cli for quick setup. Efficient token usage, advanced tools. Any C# method may be turned into a tool by a single line. Works with Claude Code, Gemini, Copilot, Cursor and any other absolutely for free.
Run your own MCP server? See who uses it and what to fix.
Measure it with TrackMCP