Local context compiler for AI coding assistants — smallest correct context bundle with rationale
Project description
context-compiler
A local-first MCP server that indexes your Python and TypeScript codebase into a dependency graph and returns the smallest correct context bundle for any coding task — with a one-line rationale for every included file.
No cloud. No LLM API calls. No data leaves your machine.
The problem
When you ask Claude to fix a bug or add a feature, it reads files by guessing which ones are relevant. It over-reads (wastes tokens) or misses the file that actually matters. The bigger the codebase, the worse this gets.
How it works
Your task: "fix the payment retry logic"
↓
Classify → BUG_FIX
↓
Find entry nodes → payment_processor.py (BM25 + docstring matching)
↓
Traverse graph → payment_processor.py + retry_handler.py + test_processor.py
↓
Score + budget → 870 tokens (within 8000 limit)
↓
Return bundle with rationale per file
Everything — classification, traversal, scoring, rationale — is deterministic. Same repo + same task = same bundle, every time.
Getting started
pip install claude-context-compiler
cd /your/project
context-compiler init
That's it. init does three things in one step:
- Indexes your codebase into a local dependency graph
- Registers the MCP server with Claude Code
- Adds context-retrieval instructions to
CLAUDE.md
Then open Claude Code in your project — it will call get_context automatically before reading files.
Requires Python 3.11+.
Other commands
# Re-index after large changes
context-compiler index
# Preview what context a task would produce (no Claude needed)
context-compiler explain --task "<Prompt>"
All commands default to the current directory. Pass --repo <path> to target a different path.
Optional: semantic fallback
[ This is not in prod yet; work in progress ]
For better matching when task terms don't appear in symbol names (e.g. "fix login flow" → finds authenticate_user):
pip install "claude-context-compiler[semantic]"
Downloads a 23MB ONNX model once, no PyTorch required.
MCP tools
get_context(task, budget=8000)
Returns the minimal file bundle for a coding task.
{
"files": ["payments/processor.py", "payments/retry_handler.py", "tests/test_processor.py"],
"rationale": [
"Included PaymentProcessor as primary task location (matched 'payment')",
"Included RetryHandler because it is called by PaymentProcessor (depth 1)",
"Included test_processor.py — test coverage for PaymentProcessor"
],
"confidence": 1.0
}
refresh(changed_files)
Re-indexes the repository after file changes.
What makes it different
Task-type-aware traversal. A bug fix traverses inbound callers and test coverage at depth 2. A new feature traverses imports and sibling modules. A refactor traverses everything at depth 3. No other tool adjusts retrieval strategy based on what you're actually trying to do.
Rationale per file. Every included file has a one-line explanation of why it's there. You can see what Claude will read before it reads it.
Hard token budget. The bundle never exceeds the limit. Partial file inclusion is not permitted.
Local-first. Embedded KuzuDB graph, no server, no port, no auth. Works offline.
Supported languages
| Language | Parsing | Docstrings |
|---|---|---|
| Python | tree-sitter-python | ✓ (first line of docstring) |
| TypeScript / TSX | tree-sitter-typescript | ✓ (JSDoc /** */) |
Tech stack
tree-sitter · KuzuDB · BM25 (rank-bm25) · rapidfuzz · FastMCP · fastembed (optional)
License
Apache 2.0
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file claude_context_compiler-0.5.3.tar.gz.
File metadata
- Download URL: claude_context_compiler-0.5.3.tar.gz
- Upload date:
- Size: 47.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.4
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e2c234dfbf4e7bc737b75875d107fc94043e1649f46a04dc41ff3c9f98a0347e
|
|
| MD5 |
b95aa7b3e929d11c8e0b48f58a3cd5e7
|
|
| BLAKE2b-256 |
f25a7f3579bd2309f6f5876f1a4ca6e3916c60e9357619f45435c7c8f7bb2546
|
File details
Details for the file claude_context_compiler-0.5.3-py3-none-any.whl.
File metadata
- Download URL: claude_context_compiler-0.5.3-py3-none-any.whl
- Upload date:
- Size: 30.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.4
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3d618b7b4b25febeb8704f34837d080cedee8821a2c88b058402c61f5d79df89
|
|
| MD5 |
ff314f83fb8066794290e930b3261721
|
|
| BLAKE2b-256 |
fffa5978539c3e6e8edd1c42a3c430b6df287f2edc68cc6e2f4e650b8d7b559b
|