reflens
Click on "Install Server".
Wait a few minutes for the server to deploy. Once ready, it will show a "Started" state.
In the chat, type
@followed by the MCP server name and your instructions, e.g., "@reflensLearn the dependency injection pattern from fastapi."
That's it! The server will respond to your query, and you can continue using it as needed.
Here is a step-by-step guide with screenshots.
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.
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), ordump 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.
Related MCP server: mcplens
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 — |
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 historyYou 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 |
| which reference repos are indexed |
| compact table-of-contents (modules + internal-dependency weight) |
| Tier-1 digest: architecture brief (default, ~4K tokens) → per-module outlines ( |
| hybrid lexical (FTS5) + semantic search → ranked |
| byte-exact source by file path or symbol name |
| dependency expansion (imports / imported-by / defines) |
| git history (repo-wide or per file) |
| 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 --semanticEmbeddings use fastembed (ONNX, no torch). It's opt-in because CPU embedding is slow (~25 chunks/s); the vector matrix is cached in-process so repeat queries are ~milliseconds.
Compared to
reflens | clone + agent | 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 | ✅ | 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/reflensThen (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 # confirmreflens 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 -qSee CONTRIBUTING.md and ARCHITECTURE.md.
License
This server cannot be installed
Maintenance
Resources
Unclaimed servers have limited discoverability.
Looking for Admin?
If you are the server author, to access and configure the admin panel.
Latest Blog Posts
MCP directory API
We provide all the information about MCP servers via our MCP API.
curl -X GET 'https://glama.ai/api/mcp/v1/servers/cybertronayush/reflens'
If you have feedback or need assistance with the MCP directory API, please join our Discord server