
Prelude
io.github.adjective-robv1.11.0更新於 Oct 4, 2026
Committed, machine-readable codebase context and code map that tells agents where to look.
概覽
為助理提供可提交、機器可讀的專案脈絡與程式碼地圖,協助它找到任務相關的檔案、測試與決策。
- 功能
- Prelude 掃描一次程式庫,在 .context/ 下寫入 JSON 脈絡檔案:技術堆疊、架構、限制、決策,以及包含模組、匯出與內部匯入圖的程式碼地圖。它的 MCP 工具讓助理取得符合 token 預算的概觀,依任務描述定位檔案並附上理由、被匯入次數、涵蓋的測試與適用的決策,依主題、目錄或類型查詢脈絡,以及檢視樞紐檔案或單一模組。助理也能記錄決策與標註模組,供後續工作階段沿用。全部都是靜態檔案與本機 CLI,不使用嵌入向量,也不會發出網路請求。
- 適用情境
- 適合助理在程式庫中工作、需要比 grep 更多資訊時:程式碼為何這樣設計、某個檔案被誰依賴、哪些測試涵蓋它、先前的工作階段學到了什麼。也適合希望把脈絡提交進儲存庫、可在拉取請求中比對,並在多種工具與多個已註冊專案間共享的團隊。
- 執行需求
- 需要 Node.js >= 20.19。以 stdio 在本機執行,通常透過 npx prelude-context serve 並指定 --root 路徑,或使用全域安裝的 prelude 指令。專案中必須有以 prelude init 建立的 .context/ 目錄。不需要帳號、API 金鑰或網路存取。
安裝
在 SourceWeft 中
- 開啟 儀表板中的 Prelude,將其新增到工作區。
- 為需要使用其工具的對話啟用該服務。
Desktop only,透過 STDIO。 STDIO 服務會啟動本機處理程序,因此需要 SourceWeft 桌面主機。
其他 MCP 客戶端
參照 儲存庫 中的啟動說明。
README
Prelude
Project memory and a code map for AI agents: where to look, why the code is the way it is, and what a change will touch.
[npm version] [CI] [License: MIT] [Node >= 20.19]
An agent with grep can find where a word appears. It cannot find out why the code is shaped the way it is, which tests cover a file, how many other files depend on it, or what the last session learned. That knowledge isn't in the source.
Prelude keeps it in the repo. It scans the project once and writes a small set of JSON files to .context/: the stack, the architecture, the constraints, the decisions, and a code map of every module, its exports, and what imports what. You commit those files, and agents add to them as they work. Every later session starts from them, through an MCP server, a generated CLAUDE.md / AGENTS.md, or plain stdout.
No embeddings, no server to host, no network calls. Regex heuristics over TypeScript/JavaScript, Python, Go, and Rust.
[Terminal: prelude init, then prelude locate returning ranked files with reasons]
Quick start
Or install it, which gives you the prelude command used in the rest of this README:
Then give it a task phrase:
One call returns the files to read, why each was picked, what depends on them, the tests to run afterwards, and the recorded decision that constrains the change. That is real output from this repository, which keeps its own .context/ committed. Browse it to see what Prelude writes.
Requires Node.js >= 20.19.
What you get
Commit .context/. Gitignore .context/*.session.json.
prelude compact prints the whole thing as one dense line per section, sized for a system prompt (a few hundred tokens for this repo):
What grep can't tell an agent
prelude locate attaches the first four to every file it returns. On a freshly initialised project the decisions and notes are empty; the import graph and tests are there from the first run, and the rest accumulates as people and agents record it.
How well does locate find files?
bench/locate-bench.ts replays a repository's git history: each commit subject is a query, the files that commit changed are the answer, and the repo is checked out at the parent commit so nothing sees the change itself. The baseline is a grep for each query term over the same files, ranked by distinct terms matched. Share of queries with a correct file in the top 8:
The top result is correct 48% of the time, against 39% for grep. Up to 100 commits per repo. The scoring weights were chosen using these same six repositories, so treat the numbers as in-sample; run the script on your own repo to check (see CONTRIBUTING.md). File-finding is the baseline here, not the point: the table above is.
Why not just write a CLAUDE.md or AGENTS.md?
Keep them. Prelude generates both (prelude export --format claude-md, --format agents-md) and can bootstrap from one you already have (prelude init --from-claude-md). The difference is what sits underneath:
- It doesn't rot silently. A hand-written context file is correct on the day it is written.
prelude diff --checkexits 1 when the committed context no longer matches the code, so CI catches the drift. - It is structured. JSON with a published schema, so tools can query one section, one directory, or one module instead of loading a whole markdown file.
- It answers "where" and "what else".
prelude locateturns a task phrase into a short list of files with the reason each was picked, the tests that cover it, and the decisions that apply. A prose file can't do that. - Your edits survive. Prelude tracks which fields it inferred and which you wrote.
prelude updaterefreshes the first kind and never touches the second. - It spans projects. Register several repos once and a single MCP server answers for all of them, including how they relate.
- It isn't tied to one tool. The same files feed Claude Code, Cursor, Codex, Claude Desktop, or anything that reads JSON.
How it relates to other approaches
- In-session repo maps (Aider's, for example) are computed when the session starts and discarded when it ends. Prelude's map is a file: diffable in a pull request, correctable by hand, shared by the whole team.
- Hosted code search and indexing services are more powerful retrieval, and they are a service to run or pay for. Prelude is static files and a local CLI.
- Embedding-based retrieval finds semantic matches that Prelude's term matching will miss. Prelude's results are deterministic and explain themselves, and they cost nothing to produce.
Use it from an agent (MCP)
Prelude runs as an MCP server over stdio.
One project
From a project that has a .context/ directory, register the server with Claude Code:
For any other client, the server command is npx -y prelude-context serve --root /path/to/project:
prelude mcp-config --client claude-code | cursor | codex | claude-desktop prints the exact snippet for your machine and client. The read tools are annotated read-only, so clients that honour tool annotations can run them without asking.
Resources: prelude://context/full, prelude://context/compact, prelude://context/map, and prelude://context/{type} for a single file.
Every project on the machine
Register each codebase once, register Prelude once in your agent harness, and every session can see all of your projects: what each one is, how they relate, and where to look inside any of them.
In workspace mode every tool takes an optional project, and three more tools appear:
prelude workspace list | index | status | remove <name> manage the registry at ~/.prelude/ (override with PRELUDE_HOME).
Keep it honest in CI
The GitHub Action has two modes. Guard (check: "true") runs prelude diff --check and fails the job when the committed .context/ has drifted from the code. Update (the default) runs prelude update and opens a pull request when .context/ changed. Use both: guard pull requests, update on main.
See action.yml for the inputs (version, args, working-directory, check).
Commands
Run any command with --help for its flags.
prelude init
With --from-claude-md, Prelude extracts project info, stack, architecture, and constraints from the markdown and merges them with what it infers.
prelude update and prelude diff
prelude locate <query...>
Scores every file on two kinds of evidence: what the map knows (exports, paths, module purposes, architecture roles, decisions that mention the file) and a scan of file contents for the query terms, weighted so rare terms count for more. Each result lists the reasons it was picked, then an impact line (how many files import it, which tests cover it), the recorded decisions that mention it, and any module notes. --format json returns the same fields.
When nothing matches, Prelude prints the hub files as a place to start.
prelude query <topic> [options]
Output goes to stdout and the token estimate to stderr, so it pipes cleanly. At least one of topic, scope, or type is required.
prelude export
The claude-md and agents-md formats include a Read first list of hub files and a one-line-per-module map.
prelude annotate <module>
prelude decision <title>
prelude validate
Validates every .context/ file against its JSON Schema and exits 1 if any fails.
prelude workspace <action>
The format
Prelude is a CLI and a format. The format is specified in spec.md, with a JSON Schema for every file in schemas/. The schemas ship in the npm package and allow additional properties, so you can add your own fields.
The code map: map.json
Every module with a short purpose, each file's exports, the resolved internal import graph, and the hub files most of the codebase depends on. It is deterministic (sorted arrays, no timestamps), so it diffs cleanly in git.
Manual edits
The .context/ files are plain JSON. Edit them directly:
prelude update keeps what you wrote and refreshes only what it inferred.
External context directory
Set PRELUDE_ROOT to read and write context in a directory outside the project, for repos where you can't or don't want to commit .context/.
Language support
The format itself is language-agnostic. Adding a language to the scanner is a contained change; see CONTRIBUTING.md.
FAQ
Does it respect .gitignore? Yes, the root .gitignore. Ignored files and directories stay out of the map and the architecture. Nested .gitignore files are not read yet.
Should I commit .context/? Yes. It is project documentation that happens to be machine-readable. Gitignore only .context/*.session.json.
How often should I run prelude update? After adding dependencies or restructuring. The GitHub Action does it for you and the guard mode tells you when you forgot.
What if the inference is wrong? It will be sometimes; it is heuristics. Edit the JSON or use prelude annotate. Your correction is kept on every later update. If the mistake is one Prelude should not make, open an issue.
Does it send my code anywhere? No. Inference, locate, and the MCP server make no network requests.
Does it work with any LLM? Yes. The output is text and JSON.
Roadmap
- Graph-weighted ranking for
locate - An end-to-end benchmark: tokens and tool calls an agent needs to finish a task, with and without Prelude
- More languages in the code map
- Learned heuristics from agent usage
Shipped work is in the changelog. Open items are tracked in issues.
Contributing
Contributions are welcome, especially inference fixes for real project layouts, new framework detectors, and new languages for the code map. CONTRIBUTING.md has setup, conventions, and step-by-step recipes for each. Issues labelled good first issue are scoped to be approachable.
License
來源:README.md,提交 bdb8071
工具
0版本歷史
1- v1.11.0最新Oct 4, 2026

