Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
89 changes: 40 additions & 49 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,49 +66,38 @@

## Quick start

One command. 30 seconds.

```bash
uvx --from "code-context-engine[local]" cce init # install + index + configure, one shot
```

Or if you prefer a persistent install:

```bash
uv tool install "code-context-engine[local]" # or: pipx install "code-context-engine[local]"
cd /path/to/your/project
cce init # or: cce init --agent all
cce init
```

That's it. Your AI coding agent now searches your index instead of reading entire files.

> **Already have Ollama?** You can skip `[local]` and use `uv tool install code-context-engine` instead. CCE auto-detects Ollama at localhost:11434 and uses `nomic-embed-text`.
Restart your editor. Done. Every question now hits the index instead of re-reading files.

---
> **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
<details>
<summary><strong>System requirements</strong></summary>

- Python 3.11+ (tested on 3.11, 3.12, 3.13)
- A C compiler and `cmake` (needed to build tree-sitter grammars)
Python 3.11+ and a C compiler (for tree-sitter grammars).

| Platform | Setup |
|----------|-------|
| **macOS** | `xcode-select --install` (provides compiler and cmake) |
| **macOS** | `xcode-select --install` |
| **Ubuntu/Debian** | `sudo apt install build-essential cmake` |
| **Fedora/RHEL** | `sudo dnf install gcc gcc-c++ cmake` |
| **Windows** | Install [Visual Studio Build Tools](https://visualstudio.microsoft.com/visual-cpp-build-tools/) (C++ workload) and [CMake](https://cmake.org/download/) |

Tested on all three platforms in CI (macOS, Linux, Windows × Python 3.11/3.12/3.13).

## Install and see savings in 60 seconds

You need an embedding backend to index code. Pick one:

| Option | Install command | Size | Requires |
|--------|----------------|------|----------|
| **Local (recommended)** | `uv tool install "code-context-engine[local]"` | +60 MB | Nothing else |
| **Ollama** | `uv tool install code-context-engine` | Core only | Ollama running + `nomic-embed-text` pulled |

Then:
| **Windows** | [Visual Studio Build Tools](https://visualstudio.microsoft.com/visual-cpp-build-tools/) (C++ workload) + [CMake](https://cmake.org/download/) |

```bash
cd /path/to/your/project
cce init # index, install hooks, register MCP server
```

Restart your editor. Done. Every question now hits the index instead of re-reading files.
Tested on macOS, Linux, Windows with Python 3.11/3.12/3.13.
</details>

`cce init` auto-detects your editor and writes the right config. To target a
specific agent, use `--agent claude`, `--agent codex`, `--agent copilot`, or
Expand All @@ -132,18 +121,25 @@ section per project so multiple projects coexist; `cce uninstall` removes only
the section for the current project.

```
my-project · 38 queries
my-project · 38 queries · last query 5m ago

⛁ ⛁ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ 94% tokens saved
⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ 88% tokens saved

Without CCE 48.0k tokens $0.14
With CCE 3.4k tokens $0.01
Input savings 1.9M tokens $27.78
Output savings 4.8k tokens $0.36
──────────────────────────────────────────
Saved 44.6k tokens $0.13
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* <1% ▰▱▱▱▱▱▱▱▱▱ 4.8k $0.36 · 12 calls

Cost estimate based on Sonnet input pricing ($3/1M tokens)
Cost estimate based on Opus pricing (input $15.0/1M, output $75.0/1M)
```

Supports Anthropic, OpenAI, and Google model pricing. Configure via `pricing.model` in `~/.cce/config.yaml`.

---

## Why this matters
Expand Down Expand Up @@ -236,23 +232,15 @@ cce dashboard

![CCE Dashboard](https://raw.githubusercontent.com/elara-labs/code-context-engine/main/docs/dashboard.png)

**Dollar estimates** fetched from live Anthropic pricing:
**Dollar estimates** with multi-provider pricing (Anthropic, OpenAI, Google):

```bash
cce savings --all # see savings across all projects
```

---

## How is CCE different?

CCE is editor-agnostic, local-first, and gives you measurable token savings. Your code never leaves your machine. Unlike built-in indexing (Cursor, Continue), CCE works across Claude Code, VS Code, Cursor, Gemini CLI, and Codex with a single index. Unlike cloud tools (Greptile), it's free and private.

See the [full comparison with alternatives](docs/comparison.md) for an honest look at trade-offs.

---

## How it works (the short version)
## How it works

1. **Index:** Tree-sitter parses your code into semantic chunks (functions, classes, modules). Stored as vector embeddings locally.
2. **Search:** Claude calls `context_search`. Hybrid vector + BM25 retrieval finds the right chunks. Code graph adds related files automatically.
Expand Down Expand Up @@ -317,9 +305,9 @@ Memory entries compressed without LLM calls. Drops articles, fillers, pronouns.
</details>

<details>
<summary><strong>Dynamic Pricing</strong></summary>
<summary><strong>Multi-Provider Pricing</strong></summary>

Dollar estimates in `cce savings` come from live Anthropic pricing (HTML table parsed, cached 7 days, offline fallback). No manual updates when rates change.
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.
</details>

<details>
Expand Down Expand Up @@ -364,7 +352,9 @@ retrieval:
confidence_threshold: 0.5

pricing:
model: sonnet # sonnet | opus | haiku
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.
Expand Down Expand Up @@ -434,6 +424,7 @@ All other text files are chunked by line range. Binary files are skipped.

| 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 |
Expand All @@ -457,7 +448,7 @@ CCE replaces "dump the entire file" with "search for the relevant function." The

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.yaml`:
Set the level in `~/.cce/config.yaml` or `.context-engine.yaml`:

```yaml
compression:
Expand Down
68 changes: 60 additions & 8 deletions docs-src/src/content/docs/agents/codex.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,27 +11,79 @@ Codex CLI uses a global configuration file rather than per-project MCP config. C
cce init --agent codex
```

Or let CCE auto-detect (if `~/.codex/` exists or the VS Code OpenAI extension is installed):

```bash
cce init
```

## Files created

### `~/.codex/config.toml`

Codex CLI has no per-project MCP configuration. Instead, CCE adds a project section (keyed by a hash of the project path) to the user-global config file.
Codex CLI reads MCP servers from this single user-global file. CCE adds one section per project, keyed by a slug derived from the project's absolute path:

```toml
[projects."a1b2c3d4"]
path = "/Users/you/projects/my-project"

[projects."a1b2c3d4".mcpServers.context-engine]
[mcp_servers.cce-my-project-a3f2b1]
command = "cce"
args = ["serve"]
args = ["serve", "--project-dir", "/path/to/your/project"]
```

Multiple projects coexist in the same file. Each gets a unique section name (`cce-<basename>-<hash>`) so two projects named "api" in different directories won't collide.

### `AGENTS.md`

Contains instructions for Codex to use `context_search` for code exploration. The CCE block is wrapped in markers so your own content is preserved during upgrades.

## Important notes

- Codex CLI does not support per-project `.mcp.json` files. The global `~/.codex/config.toml` is the only location for MCP server registration.
- Each project gets its own section identified by a hash, so multiple projects can coexist in the same config file.
- Codex CLI does **not** support per-project `.mcp.json` files. The global `~/.codex/config.toml` is the only location for MCP server registration.
- Running `cce uninstall` removes only the section for the current project.
- If you're using Codex via the VS Code extension (not the CLI), CCE detects it by looking for `openai.*` directories under `~/.vscode/extensions/`.

## Verify it's working

1. After `cce init`, start a new Codex session in your project directory
2. Ask a code question:

```
How does error handling work in this project?
```

3. Check that Codex calls `context_search` in the tool output
4. Verify savings:

```bash
cce savings
```

## Cross-agent memory

Decisions recorded during Claude Code sessions (`record_decision`) are stored in the project's `memory.db` and shared across all agents. If you switch between Claude Code and Codex on the same project, `session_recall` returns decisions from both.

## Troubleshooting

### "cce: command not found" in Codex

Codex resolves commands from your shell's PATH. If you installed with `uv tool install`:

- **macOS/Linux:** Ensure `~/.local/bin` is in your PATH (add to `~/.zshrc` or `~/.bashrc`)
- **Windows:** Ensure `%USERPROFILE%\.local\bin` is in your system PATH

### Codex doesn't detect the MCP server

Check that `~/.codex/config.toml` exists and contains the `[mcp_servers.cce-...]` section:

```bash
cat ~/.codex/config.toml | grep cce
```

If missing, re-run `cce init --agent codex`.

### Multiple projects interfering

Each project section in `config.toml` includes `--project-dir` pointing to the correct path. If you renamed or moved a project, run `cce uninstall` in the old location and `cce init --agent codex` in the new one.

### Windows: config.toml path

On Windows, the config file is at `%USERPROFILE%\.codex\config.toml`. CCE handles backslash escaping in TOML automatically, but if you edit the file manually, use forward slashes or double backslashes in paths.
75 changes: 63 additions & 12 deletions docs-src/src/content/docs/agents/copilot.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,12 @@ CCE integrates with GitHub Copilot's chat agent in VS Code through MCP configura
cce init --agent copilot
```

Or let CCE auto-detect (if `.vscode/` exists in your project):

```bash
cce init
```

## Files created

### `.vscode/mcp.json`
Expand All @@ -19,31 +25,76 @@ Registers the CCE MCP server for Copilot's agent mode.

```json
{
"mcpServers": {
"servers": {
"context-engine": {
"command": "cce",
"args": ["serve"]
"args": ["serve", "--project-dir", "/path/to/your/project"]
}
}
}
```

Note: VS Code uses `"servers"` as the key, not `"mcpServers"`.

### `.github/copilot-instructions.md`

Contains instructions for Copilot to use `context_search` for code questions. The CCE block is wrapped in markers:
Contains instructions for Copilot to use `context_search` for code questions. The CCE block is wrapped in markers so your own Copilot instructions are preserved during upgrades.

## Verify it's working

1. After `cce init`, reload VS Code (Cmd/Ctrl+Shift+P, then "Developer: Reload Window")
2. Open Copilot Chat (Ctrl+Shift+I or the Copilot icon)
3. Switch to Agent mode (click the mode selector at the top of the chat panel)
4. Ask a code question:

```markdown
<!-- CCE:BEGIN -->
...instructions...
<!-- CCE:END -->
```
How does the payment processing work?
```

Copilot should call `context_search` and return results from your indexed codebase. Check the tool call output to confirm.

Then verify savings:

```bash
cce savings
```

Your own Copilot instructions above or below the markers are preserved during upgrades.
## Requirements

## Usage
- VS Code 1.99+ (MCP support was added in early 2025)
- GitHub Copilot extension installed and active
- Agent mode enabled in Copilot Chat settings

Once configured, Copilot's chat agent will have access to the `context_search` tool. Ask questions about your codebase in Copilot Chat and it will use CCE's compressed retrieval instead of sending full files.
If you don't see MCP tools in Copilot Chat, check that "Agent mode" is enabled:
Settings → Extensions → GitHub Copilot → enable "Chat: Agent"

## Working with existing MCP servers

If you already have a `.vscode/mcp.json` with other MCP servers, `cce init` merges the CCE entry without touching your existing servers.

## Troubleshooting

### Copilot doesn't use context_search

1. Confirm Agent mode is active (not "Edit" or "Chat" mode)
2. Check `.github/copilot-instructions.md` exists and contains the CCE block
3. Reload VS Code window after setup

### "cce: command not found"

VS Code inherits PATH from how it was launched. If you installed `cce` with `uv tool install`:

- **macOS/Linux:** Add `~/.local/bin` to your shell profile, then launch VS Code from a new terminal with `code .`
- **Windows:** The installer usually adds to PATH automatically. If not, add `%USERPROFILE%\.local\bin` to your system PATH, then restart VS Code

### Windows: UnicodeDecodeError during init

Upgrade to CCE v0.4.24+ which fixes Windows encoding issues. Run:

```bash
uv tool install "code-context-engine[local]" --upgrade
```

## Restarting after setup
### MCP server starts but Copilot can't connect

After running `cce init`, reload the VS Code window (Cmd+Shift+P, then "Developer: Reload Window") to pick up the MCP server.
Check that no firewall or antivirus is blocking localhost connections. CCE's MCP server communicates via stdio (not HTTP) by default, so this is rare.
Loading
Loading