local-ref
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseLocal Reference
本地参考
Cache library documentation locally so every session reads from disk instead of re-fetching from external sources. Local docs load via tool (free, instant) instead of API calls (tokens + latency).
Read将库文档本地缓存,这样每次会话都从磁盘读取,而非重新从外部源获取。本地文档通过工具加载(免费、即时),无需调用API(消耗令牌且有延迟)。
ReadSources
来源
Fetch documentation from any of these, in order of preference:
- Context7 API — curated library docs with code examples. See .
references/context7-api.md - WebFetch — official documentation sites (e.g., developer.wordpress.org, getbootstrap.com)
- Manual — user-provided docs, internal wikis, or CLI output
--help
可从以下任一来源获取文档,优先级如下:
- Context7 API —— 带有代码示例的精选库文档。详见。
references/context7-api.md - WebFetch —— 官方文档站点(例如developer.wordpress.org、getbootstrap.com)
- Manual —— 用户提供的文档、内部维基或CLI 输出
--help
Commands
命令
Init — local-ref init
local-ref init初始化 — local-ref init
local-ref initSet up local documentation cache for a project.
-
Detect project technologies from these sources:
- (JS/Node dependencies)
package.json - (PHP dependencies)
composer.json - /
AGENTS.md(mentioned frameworks)CLAUDE.md - /
requirements.txt(Python)pyproject.toml - (Ruby)
Gemfile - (Go)
go.mod
-
Confirm with user which technologies to cache. Suggest the top 3-5 most relevant. Skip generic/obvious ones (e.g., don't cache "JavaScript" docs for a JS project).
-
For each technology: a. Scan project code to identify which APIs/patterns are actually used b. Fetch documentation from best available source (see Sources above) c. Filter fetched content to patterns relevant to this project
-
Write project-specific docs to:
docs/reference/<topic>.md- Start each file with the standard header (see File Header Format below)
- Include only patterns relevant to this project's actual code
- Cross-reference actual project files when possible (e.g., "Used in ")
lib/acf.php - Target 100-200 lines per file — enough to be useful, small enough to read quickly
-
Update AGENTS.md — add asection with verbal references (NOT
## Local Reference Documentation-references) to the docs:@markdown## Local Reference Documentation The `docs/reference/` directory contains project-specific API references. Check these files before using external documentation tools: - `docs/reference/<file>.md` — <brief description>
为项目设置本地文档缓存。
-
从以下来源检测项目技术栈:
- (JS/Node依赖)
package.json - (PHP依赖)
composer.json - /
AGENTS.md(提及的框架)CLAUDE.md - /
requirements.txt(Python)pyproject.toml - (Ruby)
Gemfile - (Go)
go.mod
-
与用户确认要缓存的技术栈。建议选择最相关的3-5项。跳过通用/显而易见的内容(例如,JS项目无需缓存“JavaScript”文档)。
-
针对每项技术栈: a. 扫描项目代码,识别实际使用的API/模式 b. 从最佳可用来源获取文档(见上方“来源”部分) c. 过滤获取的内容,仅保留与本项目相关的模式
-
将项目专属文档写入:
docs/reference/<topic>.md- 每个文件以标准页眉开头(见下方“文件页眉格式”)
- 仅包含与本项目实际代码相关的模式
- 尽可能关联实际项目文件(例如:“在中使用”)
lib/acf.php - 每个文件目标长度为100-200行——足够实用,且便于快速阅读
-
更新AGENTS.md —— 添加部分,使用文字描述引用文档(不要使用
## Local Reference Documentation引用):@markdown## Local Reference Documentation The `docs/reference/` directory contains project-specific API references. Check these files before using external documentation tools: - `docs/reference/<file>.md` — <brief description>
Update — local-ref update
local-ref update更新 — local-ref update
local-ref updateRefresh existing local docs.
- Read to find existing doc files
docs/reference/ - For each file, parse the header to determine source type and parameters (
<!-- source="..." -->/libraryIdfor context7,queryfor webfetch)url - Re-fetch based on source type:
- — re-fetch using
context7andlibraryIdquery - — re-fetch from
webfetchurl - — skip (flag for user review if stale)
manual
- Merge new content while preserving project-specific annotations and cross-references
- Update the date
<!-- cached="..." --> - Report what changed (updated, skipped manual, failed)
刷新现有本地文档。
- 读取目录,找到现有文档文件
docs/reference/ - 针对每个文件,解析页眉以确定源类型和参数(Context7的
<!-- source="..." -->/libraryId,WebFetch的query)url - 根据源类型重新获取内容:
- —— 使用
context7和libraryId重新获取query - —— 从
webfetch重新获取url - —— 跳过(若内容过时则标记供用户审核)
manual
- 合并新内容,同时保留项目专属注释和关联引用
- 更新日期
<!-- cached="..." --> - 报告变更内容(已更新、跳过手动文档、获取失败)
Lookup — local-ref lookup <topic>
local-ref lookup <topic>查找 — local-ref lookup <topic>
local-ref lookup <topic>Find documentation, local-first.
- Check for a matching file (grep for topic keywords)
docs/reference/ - If found, read the local file and quote/apply the relevant sections to the current task
- If not found, fetch from external source, then ask user if the result should be saved locally
查找文档,优先使用本地缓存。
- 在目录中查找匹配文件(通过关键词 grep 搜索)
docs/reference/ - 若找到,读取本地文件并引用/应用与当前任务相关的章节
- 若未找到,从外部源获取,然后询问用户是否要将结果保存到本地
Save — local-ref save
(opportunistic, mid-project)
local-ref save保存 — local-ref save
(项目进行中按需使用)
local-ref saveWhen working on a project and you fetch documentation from an external source (Context7, WebFetch, etc.) that would be useful across sessions:
- After using the fetched docs to complete the current task, offer: "This documentation could be useful in future sessions. Save to ?"
docs/reference/ - If user agrees, write a project-specific version (not raw dump) to with the standard header (see File Header Format)
docs/reference/<topic>.md - Add the new file to the AGENTS.md bullet list so future sessions discover it
## Local Reference Documentation - Continue with the original task
This keeps docs growing organically as the project evolves, without requiring explicit or runs.
initupdate在项目开发过程中,当你从外部源(Context7、WebFetch等)获取了对后续会话有用的文档时:
- 使用获取的文档完成当前任务后,询问用户:“此文档对后续会话可能有用,是否保存到?”
docs/reference/ - 若用户同意,将项目专属版本(非原始转储)写入,并添加标准页眉(见“文件页眉格式”)
docs/reference/<topic>.md - 将新文件添加到AGENTS.md的项目符号列表中,以便后续会话能够发现
## Local Reference Documentation - 继续执行原任务
这样可随着项目演进自然扩充文档,无需显式运行或命令。
initupdatePassive Behavior (via AGENTS.md)
被动行为(通过AGENTS.md)
The command adds a section to AGENTS.md. This section loads every session (~80 tokens) and tells Claude to check before external lookups. This passive guidance works without loading the skill itself.
init## Local Reference Documentationdocs/reference/init## Local Reference Documentationdocs/reference/File Header Format
文件页眉格式
Every cached doc file MUST start with this machine-readable header. The command depends on it.
updatemarkdown
undefined每个缓存文档文件必须以以下机器可读页眉开头。命令依赖此页眉。
updatemarkdown
undefinedVite Asset Pipeline — Project Reference
Vite Asset Pipeline — Project Reference
<!-- source="context7" libraryId="/vitejs/vite" query="build manifest plugin configuration" -->
<!-- cached="2026-02-16" -->
Content here...
Header fields:
| Field | Required | Values |
|-------|----------|--------|
| `source` | yes | `context7`, `webfetch`, `manual` |
| `libraryId` | if context7 | Context7 library ID |
| `url` | if webfetch | Source URL |
| `query` | if applicable | Query used to fetch content |
| `cached` | yes | ISO date (`YYYY-MM-DD`) of last fetch |
For manually created docs, use `source="manual"`:
```markdown<!-- source="context7" libraryId="/vitejs/vite" query="build manifest plugin configuration" -->
<!-- cached="2026-02-16" -->
Content here...
页眉字段:
| 字段 | 是否必填 | 取值 |
|-------|----------|--------|
| `source` | 是 | `context7`, `webfetch`, `manual` |
| `libraryId` | 当source为context7时必填 | Context7库ID |
| `url` | 当source为webfetch时必填 | 源URL |
| `query` | 适用时必填 | 获取内容时使用的查询词 |
| `cached` | 是 | 最后获取日期(ISO格式 `YYYY-MM-DD`) |
对于手动创建的文档,使用`source="manual"`:
```markdownInternal Auth API — Project Reference
Internal Auth API — Project Reference
<!-- source="manual" cached="2026-02-16" -->
undefined<!-- source="manual" cached="2026-02-16" -->
undefinedWhen NOT to Cache
无需缓存的场景
Skip local caching when:
- Rapidly evolving APIs — bleeding-edge or pre-1.0 libraries where docs change weekly
- One-off lookups — if you only need one fact, fetching is cheaper than maintaining a file
- Already in AGENTS.md — if the project's agent instructions already cover the topic
When in doubt, cache. Stale docs are better than no docs — can refresh context7 and webfetch sources automatically (manual sources are flagged for review).
update以下情况跳过本地缓存:
- 快速演进的API —— 前沿或1.0版本前的库,其文档每周更新
- 一次性查找 —— 若仅需单个信息点,获取文档比维护文件更划算
- 已包含在AGENTS.md中 —— 若项目的Agent指令已涵盖该主题
若有疑问,优先缓存。过时文档总比没有好——命令可自动刷新Context7和WebFetch来源的内容(手动来源会标记供审核)。
updateKey Design Rules
核心设计规则
- Verbal references only — never add to AGENTS.md (would bloat system prompt). Use plain text descriptions so Claude reads files on-demand.
@docs/reference/... - Project-specific over generic — don't dump raw API output. Tailor examples to the project's actual code, file structure, and patterns.
- Cross-reference project files — mention where patterns are used (e.g., "see for implementation").
lib/assets.php - One file per topic — keep docs modular. Don't create one giant reference file.
- 100-200 lines per file — see target in command above.
init
- 仅使用文字描述引用 —— 切勿在AGENTS.md中添加(会膨胀系统提示词)。使用纯文本描述,让Claude按需读取文件。
@docs/reference/... - 优先项目专属内容,而非通用内容 —— 不要直接转储原始API输出。根据项目的实际代码、文件结构和模式调整示例。
- 关联项目文件 —— 提及模式的使用位置(例如:“详见中的实现”)。
lib/assets.php - 每个主题一个文件 —— 保持文档模块化。不要创建单一的巨型参考文件。
- 每个文件100-200行 —— 见命令中的目标要求。
init
File Naming Convention
文件命名规范
Use descriptive kebab-case names:
docs/reference/
├── acf-patterns.md
├── vite-asset-pipeline.md
├── wordpress-cpt-taxonomy.md
├── bootstrap-grid-components.md
└── react-hooks-patterns.md使用描述性的短横线分隔命名(kebab-case):
docs/reference/
├── acf-patterns.md
├── vite-asset-pipeline.md
├── wordpress-cpt-taxonomy.md
├── bootstrap-grid-components.md
└── react-hooks-patterns.mdExternal Source References
外部来源参考
See for Context7 API endpoints and common library IDs.
references/context7-api.mdContext7 API端点和常用库ID详见。
references/context7-api.md