Skip to main content

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 keycloak token expiry"
         ↓
  Classify → BUG_FIX
         ↓
  Find entry nodes → keycloak.py (BM25 + docstring matching)
         ↓
  Traverse graph → keycloak.py + secured_view.py + test_keycloak_steps.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:

  1. Indexes your codebase into a local dependency graph
  2. Registers the MCP server with Claude Code
  3. 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 "fix the retry logic"

All commands default to the current directory. Pass --repo <path> to target a different path.

Optional: semantic fallback

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": ["admin/keycloak.py", "admin/views/secured_view.py"],
  "rationale": [
    "Included Keycloak as primary task location (matched 'keycloak')",
    "Included SecuredView._has_role because it is called by Keycloak (depth 1)"
  ],
  "token_estimate": 870,
  "tokens_saved": 0,
  "task_type": "BUG_FIX",
  "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 /** */)

Environment variables

Variable Default Description
CC_REPO_PATH required Path to indexed repository
CC_TOKEN_BUDGET 8000 Default token budget for get_context

Tech stack

tree-sitter · KuzuDB · BM25 (rank-bm25) · rapidfuzz · FastMCP · fastembed (optional)


License

Apache 2.0

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

claude_context_compiler-0.3.0.tar.gz (53.1 kB view details)

Uploaded Source

Built Distribution

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

claude_context_compiler-0.3.0-py3-none-any.whl (28.3 kB view details)

Uploaded Python 3

File details

Details for the file claude_context_compiler-0.3.0.tar.gz.

File metadata

  • Download URL: claude_context_compiler-0.3.0.tar.gz
  • Upload date:
  • Size: 53.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.4

File hashes

Hashes for claude_context_compiler-0.3.0.tar.gz
Algorithm Hash digest
SHA256 2520d5ec0de68849a0f3ecc2f1c654bf53d603f2224829149ee658559251c334
MD5 ad6089bb62026bb6200cf8c5701a09a5
BLAKE2b-256 a87c323bf9907f9f8a5b9de30d54f7238a586701e48a7600f45ee7d787073268

See more details on using hashes here.

File details

Details for the file claude_context_compiler-0.3.0-py3-none-any.whl.

File metadata

File hashes

Hashes for claude_context_compiler-0.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 71a42d4f7a4683a0c2753b4f1f3c92f190c2cb89a2392164241f0ce94e2dedbc
MD5 84b82412d76842409784a94cef7e1879
BLAKE2b-256 c5774a75624c080b5c1afe2798e7e24b4a23f139374e99c96997c7455a4058b7

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