Cross-project code intelligence: ask questions about several codebases at once, with answers grounded in the code itself.
Context-AI is a CLI that indexes multiple repositories into a local vector store and answers questions with Claude, using retrieved code as context. It is built for the question every multi-repo team asks before writing something new: "do we already have this somewhere?"
context-ai generate ./design-system --name ds
context-ai generate ./checkout-app --name checkout
context-ai ask "Do we already have a file-upload component I can reuse?" generate select query / ask / chat
───────── ────── ──────────────────
repo ──► chunk ──► embed ──► ChromaDB question ──► embed
(LangChain (sentence- (one │
splitters) transformers, collection ▼
local) per project) ──► search every active collection
│
normalize scores per collection
│
merge + rank across projects
│
fit into token budget (tiktoken)
│
Claude + prompt mode ──► answer
- Index.
generatewalks a repository (respecting.gitignore-style patterns), splits code with LangChain's recursive splitter using per-language separators, embeds each chunk locally with sentence-transformers, and stores it in its own ChromaDB collection under~/.context-ai/storage/. - Select.
selectchooses which indexed projects are active for the next questions. - Retrieve.
querysearches every active collection, normalizes the scores and returns one ranked list across projects. - Answer.
askandchatpack the best results into Claude's context window under an explicit token budget, and answer using one of four prompt modes.
The core problem: ChromaDB returns raw distances per collection, and they are not comparable across collections. Each index has its own distance distribution:
design_system_results = [0.1, 0.3, 0.8]
backend_api_results = [0.05, 0.15, 0.4]
legacy_code_results = [0.2, 0.6, 1.2]Ranking those numbers directly lets the tightest index win every query, even when its best match is mediocre. Context-AI normalizes within each collection before merging:
normalized = (distance - min_distance) / (max_distance - min_distance)
similarity = 1.0 - normalized # 0–1, higher is better
final_score = similarity * weight_factorThen all collections are merged and sorted by final_score, so a result from the design system and a result from the checkout app compete on equal terms.
Known limitations, documented rather than hidden (ADR-011):
- A collection that returns a single result always normalizes to 1.0.
- Min-max is relative: it says which result is best within a project, not how good that result is in absolute terms.
The full design is in Similarity Scoring.
Every answer is assembled against an explicit budget over Claude's 200K-token window, with tokens counted by tiktoken:
| Slice | Budget |
|---|---|
| Retrieved context | 65% of the window (130K) |
Chat history, in chat mode |
30% of the context slice; always keeps the last 3 turns, up to 10 |
| Response | 4K–12K tokens reserved |
The fixed split is predictable but less adaptive than the greedy-fill strategies used by Cursor, Continue.dev and Cody. ADR-012 compares them and plans a move to relevance-ordered greedy fill with a minimum response reservation. See Context Window Management.
Every significant choice is recorded as an Architecture Decision Record in docs/adr/, with the alternatives that were rejected and the costs that were accepted.
| ADR | Decision | Trade-off accepted |
|---|---|---|
| 001 | Modular monolith with clean-architecture layers (commands → services → core → config) |
Requires discipline to keep the dependency rule; new interfaces plug in without touching business logic |
| 002 | CLI first; a VS Code extension (context-ai-vscode/) and a planned REST API share the same service layer |
Less interactivity than a web UI; scriptable and CI-friendly |
| 003 | Local embeddings with sentence-transformers | Zero cost per query and code never leaves the machine; ~0.5–1 GB model and a slow first load |
| 004 | ChromaDB, one collection per project | No infrastructure; the index is per machine, not shared |
| 006 | Provider abstraction via Python Protocols | New providers need no core changes; today the abstraction is validated by Claude only |
| 008 | LangChain recursive splitter with per-language separators (YAML) | Heuristic, not AST-aware, can split mid-function; tree-sitter planned |
| 010 | Prompts as Markdown + YAML files, not strings in code | Prompt modes editable and A/B-testable without code changes; no validation of prompt files |
| 011 | Min-max normalization per collection | Fair cross-project ranking; relative, not absolute, scores |
| 012 | Fixed 65/35 token split | Predictable; greedy fill planned |
| 013 | Lazy imports for heavy dependencies | CLI startup ~5s → ~1s; ~2–3s cold start on first embedding use |
The remaining records (005, 007, 009, 014) cover the singleton/factory pattern, token counting and the VS Code extension layout.
Requires Python 3.9–3.12 and an Anthropic API key.
pipx install git+https://github.com/gabemule/context-ai.git
context-ai config set --claude-key sk-ant-xxxxxxxxxxxx
context-ai config test
context-ai generate ./my-design-system --name "design-system-v1"
context-ai generate ./current-project --name "project-main-v2"
context-ai select # pick active projects
context-ai query "authentication patterns" --verbose
context-ai ask "Do we have existing components for file uploads?"
context-ai chat| Command | Purpose | Example |
|---|---|---|
generate |
Index a project | context-ai generate ./my-project --name "v1" |
select |
Choose active projects | context-ai select |
query |
Retrieve ranked context, no LLM | context-ai query "auth patterns" --format json |
ask |
One question, answered with context | context-ai ask "How is login implemented?" |
chat |
Multi-turn session with history | context-ai chat --prompt-mode comprehensive |
config |
API key and settings | context-ai config set --claude-key sk-ant-xxx |
storage |
Inspect and clean indexes | context-ai storage info |
Output formats: JSON, XML, Markdown and plain text.
| Mode | Use case | What goes into the prompt |
|---|---|---|
minimal |
Quick lookups | Context + question |
standard (default) |
Daily development | Context + coding guidelines |
comprehensive |
Architecture planning | Full cross-project analysis |
strict |
Code review, code generation | Enforced coding standards |
git clone https://github.com/gabemule/context-ai
cd context-ai
make setup && source venv/bin/activate # venv + all dependencies
make dev # format + lint + testOther targets: make test, make lint, make type-check, make build, make test-publish. For a global editable install, use pipx install -e ..
Tooling: pytest, black, isort, flake8 and mypy.
- Documentation index
- Architecture: Similarity Scoring · Context Window Management · Prompt Modes
- Architecture Decision Records
- Commands: generate · select · query · ask · chat · config · storage
MIT. See LICENSE.