reflens
An MCP server that indexes reference repositories and provides tools for AI coding agents to retrieve lossless code context, enabling reasoning over codebases larger than the agent's context window.
README
<div align="center">
reflens
Give your AI coding agent the full, lossless context of any reference repository — and let it reason over a codebase far larger than its context window.
Point it at a local folder, a GitHub URL, or a Repomix dump. reflens indexes it once and serves it to OpenCode / Claude Code (or any MCP host) as tools your agent calls on its own.
</div>
The problem
You want your coding agent to learn from a flagship repo and apply its patterns to your project. But the repo is 100k–1M+ tokens — it does not fit in the context window. Today you either:
- paste fragments and hope they're the right ones, or
- clone it into your workspace and let the agent blind-
grepit every session (slow, token-hungry, no orientation), or - dump it with Repomix and watch it overflow the window.
All three silently lose context. Silent truncation is the bug — the agent confidently reasons about code it never actually saw.
The approach: two tiers (the honest part)
You cannot fit a 25M-token repo into a 200K window losslessly — that's physics, not engineering. Any tool that claims otherwise is truncating behind your back. reflens refuses to, and gives you two tiers plus a way to prove nothing was lost:
| Tier | What it is | Loss |
|---|---|---|
| 1 — Intelligence Digest | A budgeted, in-context overview: architecture (modules + most-depended-on files), entry points, mined conventions & decisions, and the full public symbol surface (every signature + docstring + line anchor) | Lossy on bodies, complete on structure & meaning |
| 2 — Lossless Store | Every byte of every file, content-addressed (gzip + SHA-256) | Zero — reflens verify reconstructs every file and checks SHA-256 |
The agent reasons from Tier 1 and expands into Tier 2 (exact source) only when a task needs the gnarly detail. Retrieval is the safety net, not the primary mechanism. Where the digest hits a budget, it prints the exact tool call to reach the rest — so nothing becomes unreachable.
→ Full design in ARCHITECTURE.md.
Quickstart (60 seconds)
# 1. Install (isolated; pipx recommended)
pipx install "git+https://github.com/cybertronayush/reflens"
# 2. Wire it into your agent (edits OpenCode + Claude Code configs, adds usage guidance)
reflens install both
# 3. Stock the library — any local dir, GitHub URL, or repomix .md
reflens add https://github.com/tiangolo/fastapi --name fastapi
reflens add /path/to/your/reference-repo --name myref
reflens add ./repomix-output.md --name dump
# 4. Prove nothing was lost (directory ingests are byte-exact)
reflens verify myref
# 5. Restart OpenCode / Claude Code, then just ask:
# "Use reflens to learn fastapi's dependency-injection pattern and apply it to my app."
That's it. The agent calls the tools automatically — no slash-commands, no per-repo setup.
How your agent uses it
Once installed, every model in every project gets the reflens_* tools (global MCP server) plus a usage note in your global AGENTS.md / CLAUDE.md. A typical agent flow:
reflens_modules(repo) → the module map (table of contents)
→ reflens_map(repo) → architecture brief (hubs, conventions, decisions)
→ reflens_map(repo, path_glob) → zoom into a module at signature detail
→ reflens_search(repo, query) → find the relevant code (hybrid lexical+semantic)
→ reflens_read(repo, target) → byte-exact source of a file or symbol
→ reflens_neighbors / _history → dependencies / git history
You never write commands for the agent. For 100% reliability on a given task, just name the repo ("learn from the fastapi repo…").
MCP tools
| Tool | Purpose |
|---|---|
reflens_list |
which reference repos are indexed |
reflens_modules(repo) |
compact table-of-contents (modules + internal-dependency weight) |
reflens_map(repo, level?, path_glob?, budget_tokens?) |
Tier-1 digest: architecture brief (default, ~4K tokens) → per-module outlines (path_glob + level=2) |
reflens_search(repo, query, k?, mode?) |
hybrid lexical (FTS5) + semantic search → ranked file:line hits |
reflens_read(repo, target, start?, end?) |
byte-exact source by file path or symbol name |
reflens_neighbors(repo, target, limit?) |
dependency expansion (imports / imported-by / defines) |
reflens_history(repo, target?, limit?) |
git history (repo-wide or per file) |
reflens_verify(repo) |
prove losslessness + completeness + extraction coverage |
CLI reference
reflens add <source> --name <n> [--semantic] [--max-file-bytes N] [--include-binary]
reflens list
reflens modules <name> # table of contents
reflens map <name> [--level 0|1|2] [--glob 'src/**'] [--budget N]
reflens search <name> "<query>" [-k N] [--mode auto|lexical|semantic|hybrid]
reflens read <name> <path|symbol> [--start N --end N]
reflens neighbors <name> <path|symbol>
reflens history <name> [path]
reflens verify <name> # SHA-256 round-trip + completeness + coverage
reflens enrich <name> [--model ...] # optional LLM per-module summaries
reflens remove <name> -y
reflens install [opencode|claude|both] # wire the MCP server + agent guidance
reflens serve # the MCP stdio server (hosts launch this)
What gets extracted
- Python → exact, via the stdlib
ast(classes, methods, functions, constants, module docstrings, imports). - TypeScript / JavaScript / Go / Rust / Java / Kotlin / C / C++ / C# / Ruby / PHP / Swift / Scala / Shell → signature outlines via a tuned regex extractor (optionally
tree-sitterwithpip install 'reflens[code]'). - Markdown → heading outline (docs/specs/ADRs become navigable).
- Everything else → stored losslessly + full-text searchable.
Losslessness — and proof
$ reflens verify myref
{ "ok": true,
"files": 1750, "verified": 1750, "failed": [],
"completeness": { "declared_files": 1750, "indexed_files": 1750, "drift_detected": false },
"extraction": { "code_files": 1287, "with_symbols": 1235, "coverage_pct": 96.0 } }
Every stored file is content-addressed and re-hashed on read; verify reconstructs all of them and compares SHA-256. Directory/git ingests are byte-identical to source. Repomix --compress dumps are lossless with respect to the dump (their bodies were already stripped) — reflens detects and warns about this; ingest the directory for true source fidelity.
Semantic search (opt-in)
Lexical FTS5 is the instant default and is excellent for code (symbol names, error strings). For concept queries ("how do they handle retries?"), build embeddings:
pipx install "reflens[semantic] @ git+https://github.com/cybertronayush/reflens"
reflens add /path/to/repo --name myref --semantic
Embeddings use fastembed (ONNX, no torch) and index the symbol surface (signature + docstring), not raw code bodies — so a concept query like "detect content type and pick a compressor" returns the actual function, not a doc page. It's opt-in (a one-time ~4 min build for a large repo); the vector matrix is cached in-process so repeat queries are ~3 ms. Lexical FTS still covers full file content, and byte-exact retrieval is unchanged.
Compared to
| reflens | clone + agent grep |
Repomix / gitingest | editor codebase index | |
|---|---|---|---|---|
| External reference repos as a persistent library | ✅ | ✗ (in your tree) | ✗ (one file) | ✗ (your repo) |
| Architecture-first orientation | ✅ | ✗ | ✗ | partial |
| Bigger-than-window handling | ✅ navigable | ✗ overflows / re-explores | ✗ overflows | ✅ |
| Lossless + provable | ✅ verify |
n/a | partial | n/a |
| One install across hosts (MCP) | ✅ | n/a | n/a | per-editor |
reflens is for "I want my agent to learn from N flagship repos I don't want cluttering my workspace." For a single repo you're actively editing, your editor's built-in tools are fine.
Honest limitations
- It's navigable, not omniscient. The agent must query well; the architecture-first design + AGENTS.md guidance steer it, but a lazy agent still gets shallow context. Name the repo for reliability.
- Semantic ingest is slow (CPU embeddings). Lexical-only is instant and the default.
reflens_historyneeds a live git source dir — unavailable for URL-cloned or repomix repos (the digest still shows recent commit subjects).- Not yet benchmarked against the "just clone it" baseline. The design is sound; measured task-success deltas are future work.
Install & setup
reflens has zero required runtime dependencies — it runs on the standard
library alone (sqlite3 with FTS5, ast, and a hand-rolled MCP stdio server).
The core works on Python 3.10+. The optional extras (semantic, code)
pull fastembed/tree-sitter, whose wheels can lag the newest Python, so for
those use Python 3.12 (recommended).
Pick one install path, then do the same three post-install steps.
Path A — pipx (isolated, simplest)
pipx install "reflens[semantic] @ git+https://github.com/cybertronayush/reflens"
# core only: pipx install "git+https://github.com/cybertronayush/reflens"
Path B — from source (this is exactly how the reference setup runs)
git clone https://github.com/cybertronayush/reflens && cd reflens
python3.12 -m venv .venv
.venv/bin/pip install -e ".[semantic,code,tokens]"
# make the `reflens` command available globally (PATH must include ~/.local/bin)
mkdir -p ~/.local/bin
ln -sf "$PWD/.venv/bin/reflens" ~/.local/bin/reflens
Then (any path) — wire it in, restart, stock the library
reflens install both # registers the MCP server in OpenCode + Claude Code
# and writes a usage block into their global AGENTS.md / CLAUDE.md
# → restart OpenCode / Claude Code so they launch the server
reflens add <dir|git-url|repomix.md> --name myref # populate the library (repeat per repo)
reflens list # confirm
reflens install wires each host to launch the server via the interpreter that
has reflens installed, e.g.:
// ~/.config/opencode/opencode.json → mcp.reflens
{ "type": "local",
"command": ["/abs/path/.venv/bin/python", "-m", "reflens", "serve"],
"enabled": true }
// ~/.claude.json → mcpServers.reflens (command/args form, same interpreter)
Local state lives in ~/.reflens (override with REFLENS_HOME). Nothing leaves
your machine. To update reflens itself, git pull (source) or re-run the pipx
install, then restart your agent.
Contributing
git clone https://github.com/cybertronayush/reflens && cd reflens
python3 -m venv .venv && .venv/bin/pip install -e ".[dev]"
.venv/bin/python -m pytest -q
See CONTRIBUTING.md and ARCHITECTURE.md.
License
推荐服务器
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 模型以安全和受控的方式获取实时的网络信息。