ContextFlux
Task-adaptive repository context for coding agents, enabling budgeted evidence retrieval without API keys or network calls.
README
<div align="center"> <h1>ContextFlux</h1> <p><strong>Task-adaptive repository context for coding agents.</strong></p> <p> Give an agent the evidence it needs, not the whole repository. </p>
ContextFlux is a local context engine and MCP server for coding agents. It classifies the current workflow, fuses lexical, path/symbol, dependency/test-graph, and workflow-specific rankings, then returns source-cited code ranges under a measured token ceiling.
It needs no API key, embedding model, daemon, or hosted index. It never executes repository code and never sends source, queries, or telemetry over the network.
Status: v0.1 is an experimental developer preview. The public API and index schema may change before v1. See limitations before production use.
Why ContextFlux?
A coding agent rarely needs every file. It needs different evidence for different jobs:
- a test when implementing a change;
- the source frame and dependencies when debugging a trace;
- downstream importers and tests before a risky edit;
- nearby code and configuration when addressing review feedback.
Recent repository-retrieval research supports this task-specific approach. The Agent Retrieval Bench reports that no single retrieval family wins across all coding-agent workflows, while repo maps are especially effective under tight context budgets. SWE-Explore evaluates ranked code regions under fixed line budgets, and context compression experiments show that smaller, more precise contexts can sometimes improve both quality and latency.
ContextFlux turns those ideas into a small, offline tool:
task / trace / review comment
|
workflow classifier
|
+----------+----------+-----------+-----------+
| lexical | path | code graph| task prior|
+----------+----------+-----------+-----------+
|
reciprocal-rank fusion
|
cited ranges + exact budget
Quick start
Node.js 20 or newer is required.
git clone https://github.com/divyanshu-iitian/ContextFlux.git
cd ContextFlux
npm ci
npm run build
node dist/cli.js index .
node dist/cli.js context "Fix the login timeout and update its tests" --budget 3000
Run directly from GitHub without a global install:
npx --yes --package=github:divyanshu-iitian/ContextFlux \
contextflux context "Trace the invalid credentials error" --root . --budget 3000
Useful CLI commands:
contextflux search "createSession" --limit 8
contextflux context "Add regression tests for login" --intent code2test --budget 2500
contextflux context "Show the blast radius of changing src/auth.ts" --intent edit2ripple
contextflux map --budget 1200
contextflux stats
contextflux benchmark benchmarks/self.json
The incremental cache lives at .contextflux/index.json, which should remain gitignored.
Connect an agent over MCP
Add this to an MCP client's configuration, replacing the root with an absolute path to the repository the agent will work on:
{
"mcpServers": {
"contextflux": {
"command": "npx",
"args": [
"--yes",
"--package=github:divyanshu-iitian/ContextFlux",
"contextflux-mcp"
],
"env": {
"CONTEXTFLUX_ROOT": "/absolute/path/to/repository"
}
}
}
}
On Windows, use npx.cmd if the client does not resolve npx. Restart the client after saving
the configuration.
The server exposes four read-only tools:
| Tool | Use it for |
|---|---|
get_task_context |
A bounded, source-cited evidence packet for a concrete coding task |
search_repository |
An exact symbol, path, error string, or focused concept |
repository_map |
One-time architecture orientation without file bodies |
index_status |
Index age, file/chunk/relation counts, baseline tokens, and cache size |
An agent skill and drop-in instruction files are included under
skills/context-efficient-coding and
integrations.
Retrieval modes
Leave the mode on auto in normal use, or choose one explicitly:
| Mode | Ranking emphasis |
|---|---|
explore |
Central files, symbols, concepts, and repository structure |
code2test |
Matching test files and test relations |
comment2context |
Mentioned paths, nearby dependencies, and configuration |
trace2code |
Stack-trace paths, source files, and dependencies |
edit2ripple |
Importers, tests, and likely downstream change surface |
Every search result includes a path, line range, symbols, preview, score, and human-readable evidence signals. Scores rank candidates; they are not calibrated probabilities.
Library API
import { ContextFlux } from "contextflux";
const flux = new ContextFlux({ root: process.cwd() });
const packet = await flux.context(
"Show the blast radius of changing src/auth.ts",
{ intent: "edit2ripple", budgetTokens: 3_000 },
);
console.log(packet.context);
console.log(packet.reductionPercent);
budgetTokens is enforced against the rendered packet with the GPT-4o tokenizer. For a model
with a different tokenizer, leave headroom.
Evaluation
The benchmark runner accepts gold-file cases and reports:
- mean reciprocal rank;
- Recall@5 and Recall@10;
- budgeted context yield (gold files present in the final packet);
- average packet tokens;
- the same retrieval metrics for a plain lexical baseline;
- measured lift over that baseline.
[
{
"id": "code-to-test",
"task": "Add regression tests for token-budget enforcement in src/engine.ts",
"intent": "code2test",
"goldFiles": ["test/engine.test.ts"],
"budgetTokens": 3000
}
]
Run the checked-in smoke set:
npm run build
node dist/cli.js benchmark benchmarks/self.json --root . --json
The smoke set checks wiring and regressions; it is not evidence of state-of-the-art quality. For externally valid comparisons, evaluate on Agent Retrieval Bench or another independent dataset and publish the full configuration.
How it compares
These projects solve adjacent problems and can be complementary:
| Project | Primary job | ContextFlux difference |
|---|---|---|
| Repomix | Pack a repository into an AI-friendly artifact | Selects task-specific ranges instead of packing the repository |
| Serena | LSP-powered semantic navigation and editing | Zero-daemon, language-agnostic retrieval with a strict packet budget |
| Aider | Full coding assistant with repository maps | Agent-agnostic context layer exposed as a library, CLI, and MCP server |
| codebase-memory-mcp | Persistent code knowledge graph | Lightweight ephemeral index with no external database |
ContextFlux does not claim to replace language servers, embeddings, or full coding agents. Its narrow job is budgeted evidence retrieval.
Research basis
The implementation is informed by, but is not an official implementation of, these papers:
- Yuan et al., Agent Retrieval Bench (27 July 2026): task-dependent retrieval families, natural no-gold cases, and budgeted context yield (paper, benchmark).
- SWE-Explore (June 2026): code-region retrieval under fixed exploration budgets (paper).
- CORE-Bench (June 2026): repository-level code retrieval evaluation (paper).
- RANGER (2025): graph-enhanced repository retrieval (paper).
- Context compression for coding agents (April 2026): empirical quality/latency trade-offs (paper).
Privacy and security
- Indexing, ranking, tokenization, and context assembly run locally.
- Symlinks and paths escaping the configured root are rejected.
- Binary, generated, dependency, lock, and oversized files are skipped by default.
- Repository text is returned as untrusted evidence, never executed as instructions.
- The cache contains source-derived terms and previews; protect it like source code.
Please report vulnerabilities according to SECURITY.md.
Limitations
- Import extraction is intentionally lightweight and currently recognizes common JavaScript, TypeScript, Python, Rust, Go, Java, Kotlin, Ruby, and PHP forms. It is not a compiler.
- Dynamic imports, aliases, generated sources, and runtime wiring may not form graph edges.
- Retrieval is lexical/structural; semantic paraphrases can be missed without shared terms.
- Confidence is deliberately not presented as calibrated. Closely ranked candidates produce a verification warning.
- The index is single-process and intended for local developer repositories, not a shared multi-tenant service.
Contributing
Issues, benchmark cases, language resolvers, and reproducible retrieval improvements are welcome. Read CONTRIBUTING.md before opening a pull request.
MIT licensed. Built by Divyanshu.
推荐服务器
Baidu Map
百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。
Playwright MCP Server
一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。
Magic Component Platform (MCP)
一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。
Audiense Insights MCP Server
通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。
VeyraX
一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。
graphlit-mcp-server
模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。
Kagi MCP Server
一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。
e2b-mcp-server
使用 MCP 通过 e2b 运行代码。
Neon MCP Server
用于与 Neon 管理 API 和数据库交互的 MCP 服务器
Exa MCP Server
模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。