Anneal
Optimal context selection for AI coding assistants. Cooling random context down to exactly what your AI needs.
Anneal reads your codebase's structural graph, formulates "which chunks are optimal?" as a QUBO problem, solves with simulated annealing, and returns the minimum context set for your task.
Quick Start
pip install anneal-context
cd your-project
anneal init # builds graph from source, writes config
That's it. anneal init parses your codebase using tree-sitter, extracts functions, classes, and import relationships, and writes the graph to .anneal/graph.db. Then point your MCP client at anneal-server and you're ready to go.
How It Works
- Build graph —
anneal initwalks your source tree and extracts structural relationships via tree-sitter, supporting 20+ languages (Python, JavaScript, TypeScript, Go, Rust, Java, Ruby, C/C++, and more) - Generate candidates — keyword matching + graph topology identify relevant chunks
- Formulate QUBO — minimize token cost, maximize relevance, reward dependency coverage
- Solve via simulated annealing — SpinChain engine finds optimal selection
- Return results — stability-ranked, dependency-ordered chunks within your token budget
Requirements
- Python 3.11+
Installation
pip install anneal-context
Or with uv:
uv tool install anneal-context
Setup
Primary: anneal init
cd your-project
anneal init # builds graph from source, writes config
anneal init uses tree-sitter to parse your codebase directly — no external tools required. It supports 20+ languages including Python, JavaScript, TypeScript, Go, Rust, Java, Ruby, C/C++, C#, Kotlin, Swift, Scala, PHP, and more.
The command:
- Walks your source files
- Extracts functions, classes, and import relationships
- Builds
.anneal/graph.db - Writes a default
.anneal/config.toml
Add .anneal/ to your .gitignore.
Optional: Advanced Graph Sources
If you have code-review-graph or Graphify installed, Anneal merges their graph data alongside the built-in tree-sitter graph. This can provide additional structural signals (e.g., review history from code-review-graph, or Claude-generated summaries from Graphify).
# code-review-graph
npx code-review-graph install
# Graphify (Claude Code)
/plugin marketplace add safishamsi/graphify && /graphify
Configuration
Default config is written by anneal init. You can customize .anneal/config.toml:
[budget]
default_tokens = 5000
strategy = "balanced" # "minimal" | "balanced" | "thorough"
[solver]
backend = "simulated-annealing"
num_reads = 100
num_sweeps = 1000
MCP Server Setup
Claude Code
Add to .claude/settings.json:
{
"mcpServers": {
"anneal": {
"command": "anneal-server"
}
}
}
Gemini CLI
Add to ~/.gemini/settings.json:
{
"mcpServers": {
"anneal": {
"command": "anneal-server"
}
}
}
OpenAI Codex CLI
Add to ~/.codex/config.toml:
[[mcp_servers]]
name = "anneal"
command = "anneal-server"
Cursor / VS Code + Copilot / Aider
Any MCP-compatible client: run anneal-server via stdio transport.
Tools
get_optimal_context
Parameters:
task_description: str -- what you want to do
token_budget: int | None -- max tokens (default: 5000)
include_files: list[str] -- always include these paths
exclude_files: list[str] -- never include these paths
strategy: str -- "balanced" | "minimal" | "thorough"
Returns:
selected_chunks: list[{path, content, relevance_score, tokens}]
total_tokens: int
budget_utilization: float
stability_score: float
dependency_graph: dict
get_status
Returns graph source availability, node counts, solver config.
Development
git clone https://github.com/ameyakhot/anneal
cd anneal
uv venv && source .venv/bin/activate
uv pip install -e /path/to/spinchain
uv pip install -e ".[dev]"
python -m pytest tests/ -v
License
MIT
Metadata
Release files for anneal-context 0.2.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| anneal_context-0.2.0.tar.gz | 143.1 kB | With provenance | Details for anneal_context-0.2.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| anneal_context-0.2.0-py3-none-any.whl | Python 3 | none | any | Details for anneal_context-0.2.0-py3-none-any.whl |
Total release size: 168.5 kB
Release files / anneal_context-0.2.0.tar.gz
| Download URL | anneal_context-0.2.0.tar.gz |
|---|---|
| Size | 143.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
85ce6a2afa6a63afee6ea3eb9e3822d75a3bed95f293522a29ffc52634284ccf
|
|
BLAKE2b-256 checksum How to use checksums |
ad3a1aedbc34db5623db5eb34a22279fbabec48eb7340146195e8c0d412c84d5
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.12
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Apr 13, 2026.
Transparency logRelease files / anneal_context-0.2.0-py3-none-any.whl
| Download URL | anneal_context-0.2.0-py3-none-any.whl |
|---|---|
| Size | 25.4 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
d59f35dda3bdcb61e4b6e9ba16b74c6d28447d025ee38c24be1fa90f94b329a4
|
|
BLAKE2b-256 checksum How to use checksums |
0c6c32162f0dfd023d6eff6540ff1d5bc3b2bb8d652a06630d023822d735acfb
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.12
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Apr 13, 2026.
Transparency logSecurity for anneal-context 0.2.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
Full provenance
Both files in this release have been uploaded with provenance metadata.
Attestation for anneal_context-0.2.0.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Apr 13, 2026.
Transparency logA note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.