
Onfly:一个可搜索的结构化代码库映射,供 AI 助手使用,通过 MCP 提供。
概览
用Claude Code在五个仓库中测量(每个任务三次;详情见docs/evaluation.md):- 最佳情况,在两个中等仓库中,涉及行为问题:约减少10%的回合和时间,输出标记减少12%至16%,发送给模型的上下文减少6%。- 其他三个仓库无收益:助理很少调用Onfly,且通过Grep或Read找到答案。- 成本节省未被可靠衡量(即时缓存占主导),且尚未被证明。 别再在整文件读取和噪声高的 Grep 上烧掉成千上万的令牌了。Onfly 是一个无 CGO 的 Go CLI 和 MCP 服务器,用 WebAssembly 解析器将你的代码解析成语言感知区块,然后为 Claude Code、Cursor 或任何 MCP 客户端提供两个工具:(文件骨架、谁调用它、调用什么、你的项目规则)和(最匹配代码加上它使用的代码),每个工具都是一次循环。
概述(AI 翻译)
实验性。六个代码库的检索和代理基准测试及其数量及其限制见评估,并总结如下。代理运行的节省取决于助理调用Onfly的频率,而非
Grep和Read;成本节省不予衡量。
Onfly 是一个没有 CGO 的单一 Go 二进制。它用 WebAssembly 解析器(wazero)将你的代码分成块,保存在 SQLite(或 Postgres),并为 Claude Code、Cursor 或任何 MCP 客户端提供两个工具,每个工具在一次往返中回答:onfly_xray 返回文件骨架、调用者、调用内容和项目规则,[onfly_focus 返回最匹配的代码及其使用内容。搜索是本地优先且混合的:包含名称、文本和路径,以及来自 Ollama 的向量([qwen3-embedding),用于描述代码未使用行为的问题。调用返回的规模小于它替换的文件;[onfly stats 显示估计值。
为什么不直接Read和Grep?
| 原生代理流程 | 使用 Onfly | |
|---|---|---|
| 理解一个文件 | Read 整个文件,每个方法主体 |
onfly_xray:保留签名、属性和文档块,长主体折叠为 '// … |
本页由 AI 翻译,技术细节请以原文为准。
README
以下为原文 README 节选,完整内容请查看原文。
Onfly: a context compressor for AI coding agents
Experimental. Retrieval and agent benchmarks on six code bases, with the numbers and their limits, are in Evaluation and summarized below. Savings in agent runs depend on how often the assistant calls Onfly instead of
GrepandRead; cost savings are not measured.
Onfly is a single Go binary with no CGO. It parses your code into chunks with WebAssembly parsers (wazero), keeps them in SQLite (or Postgres), and gives Claude Code, Cursor or any MCP client two tools, each answering in one round-trip: onfly_xray returns a file’s skeleton, who calls it, what it calls and your project rules, and onfly_focus returns the best-matching code and what it uses. Search is local-first and hybrid: names, text and paths, plus vectors from Ollama (qwen3-embedding) for questions that describe behavior in words the code does not use. A call comes back smaller than the files it replaces; onfly stats shows the estimate.
Why not just Read and Grep?
| Native agent flow | With Onfly | |
|---|---|---|
| Understand a file | Read the whole file, every method body |
onfly_xray: signatures, attributes and docblocks kept, long bodies collapsed to // ... [body omitted: original lines 12-58, ~47 lines, ~410 tokens; focus_symbol="Name" expands it] ..., every line numbered as in the file |
| Who calls this? | Several Greps, then Read each hit |
called_by and calls in the same answer, resolved through imports, parameter and property types, so strings.Split is not your Split; the entrypoint two hops up is on the same line |
| Find a flow | Grep for guessed words, read the false hits |
onfly_focus: ranked by name and meaning, full code of the best few plus signatures of what they use |
| Project conventions | Whatever the model remembered from CLAUDE.md |
The rules that match the returned paths ride along, once per session |
| Cost visibility | None | onfly stats totals the estimated tokens saved |
Quickstart
You need Go 1.27+ to build Onfly. An embedder is optional: without one, names, text and paths are searched and everything else works; Ollama (free, local) adds search by meaning.
git clone https://github.com/OnFlyApp/cli onfly && cd onfly && make build # bin/onfly; put it on your PATH
ollama pull qwen3-embedding:0.6b # the default embedder, once
cd ~/code/my-project
onfly init # .onfly/config.yaml, .onfly/ in .gitignore, parsers for the languages it finds, first index
onfly setup claude # register the MCP server in .mcp.json and write the guide into CLAUDE.md
Restart Claude Code and ask about your code.
安装
This server does not publish a one-line install command.
Open the repository installation guide 新手?先看 mcpskill.org 教程 →