Skip to main content

Deterministic codebase context retrieval for LLMs

Project description

context-engine

Cut your AI coding costs by 99%. Inject only the code that matters.

demo

Record your own: bash demo/record_demo.sh

Benchmark (this repo, 185 nodes)

Query Baseline Tokens With CE Tokens Reduction % Nodes Files Selected Time (ms)
fix authentication bug 46,661 434 99.1% 3 intent.py, validator.py, patcher.py 187
add a new API endpoint 46,661 106 99.8% 1 ranker.py 203
how does the database connection work 46,661 278 99.4% 2 intent.py, retrieval.py 219
debug memory leak 46,661 428 99.1% 3 intent.py, cli.py, compressor.py 172
add input validation 46,661 0 100.0% 0 no match in this repo 125
explain the caching logic 46,661 418 99.1% 3 intent.py, pruner.py, retrieval.py 172
fix error handling 46,661 479 99.0% 3 intent.py, validator.py, patcher.py 187
add logging to the pipeline 46,661 58 99.9% 1 cli.py 141

46,661 tokens → 275 tokens average. Same accuracy. 176ms overhead (small repo).

Benchmark (external repo — fastapi, 946k token codebase)

Query Baseline Tokens With CE Tokens Reduction % Nodes Files Selected Time (ms)
fix authentication bug 946,210 87 >99.9% 1 api_key.py 359
add a new API endpoint 946,210 120 >99.9% 1 api_key.py 359
how does the database connection work 946,210 130 >99.9% 2 tutorial001_an_py310.py, param_functions.py 391
debug memory leak 946,210 436 >99.9% 5 applications.py, test_arbitrary_types.py, … 1062
add input validation 946,210 244 >99.9% 3 utils.py, tutorial004_py310.py, … 375
explain the caching logic 946,210 114 >99.9% 1 test_security_scopes_sub_dependency.py 313
fix error handling 946,210 221 >99.9% 3 tutorial003_py310.py, tutorial002_py310.py, … 406
add logging to the pipeline 946,210 136 >99.9% 1 tutorial002_an_py310.py 328

946,210 tokens → 186 tokens average. Repo never seen before. 449ms overhead.

How it works

User prompt → context-engine → top 5 relevant functions → Claude sees 275 tokens
                                        ↑
               (instead of your entire codebase at 46,661 tokens)

AST-parses your repo into a call graph. When you send a prompt, it scores every function by keyword relevance + call graph centrality and injects only the top matches — before Claude starts reasoning.

No embeddings. No vector DB. No LLM calls in the retrieval path.

Install

pip install llm-diet
context-engine index .

Use with Claude Code (automatic)

claude mcp add context-engine -- python -m context_engine.mcp_server

After this, every prompt you send to Claude Code is automatically prefixed with the minimal relevant context from your codebase.

Use as CLI

context-engine query "fix the auth bug"
context-engine apply "add input validation to the login endpoint"

Why not just use RAG / embeddings?

No LLM calls, no vector DB, no setup.

context-engine uses AST parsing + call graph traversal. It's deterministic — same query, same graph, same result every time. Works offline. Runs in ~176ms (small repo) / ~432ms (large repo like FastAPI). Embeddings need a model call just to retrieve context. We don't.

Feature context-engine code-review-graph
Languages Python, JS, TS, JSX, TSX 23 languages
Dependencies tree-sitter only tree-sitter + SQLite + more
Context injection UserPromptSubmit hook (Claude Code) / IDE rules (Cursor, Windsurf) MCP server
Autonomous apply ✅ plan → diff → validate → patch
Setup pip install + index pip install + build
Incremental updates auto on file save via context-engine watch auto on file save

We do less. What we do, we do surgically.

* Full token reduction applies to Claude Code. Cursor/Windsurf receive static rules files that guide the AI to prefer provided context — dynamic injection coming in a future release.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

llm_diet-0.1.2.tar.gz (61.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

llm_diet-0.1.2-py3-none-any.whl (68.3 kB view details)

Uploaded Python 3

File details

Details for the file llm_diet-0.1.2.tar.gz.

File metadata

  • Download URL: llm_diet-0.1.2.tar.gz
  • Upload date:
  • Size: 61.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.7

File hashes

Hashes for llm_diet-0.1.2.tar.gz
Algorithm Hash digest
SHA256 c25b05e7046b03faf4e3cc2dd7b9e985dd2c5db17938be73986ec2fc51d0e6c2
MD5 2d2fd67ea03f9fdb1221f774111088fb
BLAKE2b-256 da831943861c7c22760f8c2aee963e06f0d5ebc3ca89c1054ba6015fc15121df

See more details on using hashes here.

File details

Details for the file llm_diet-0.1.2-py3-none-any.whl.

File metadata

  • Download URL: llm_diet-0.1.2-py3-none-any.whl
  • Upload date:
  • Size: 68.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.7

File hashes

Hashes for llm_diet-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 72fc7bc560823b5ea48fe28cb0d9b081aff8dd7577f2bda32595ccbc464cf2a1
MD5 3cdc1deb47d70bf9dbd98c8fd9751c8a
BLAKE2b-256 c79b03e45339c0a333bd7545054e42aec222efdea0f0d235ea04dd66fd75af4c

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page