find-docs

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Documentation Lookup

文档查询

Retrieve current documentation and code examples for any library using the Context7 CLI.
Make sure the CLI is up to date before running commands:
bash
npm install -g ctx7@latest
Or run directly without installing:
bash
npx ctx7@latest <command>
使用Context7 CLI检索任意库的最新文档和代码示例。
运行命令前请确保CLI已更新至最新版本:
bash
npm install -g ctx7@latest
或者无需安装直接运行:
bash
npx ctx7@latest <command>

Workflow

工作流

Two-step process: resolve the library name to an ID, then query docs with that ID.
bash
undefined
分为两步:先将库名解析为ID,再使用该ID查询文档。
bash
undefined

Step 1: Resolve library ID

步骤1:解析库ID

ctx7 library <name> <query>
ctx7 library <name> <query>

Step 2: Query documentation

步骤2:查询文档

ctx7 docs <libraryId> <query>

You MUST call `ctx7 library` first to obtain a valid library ID UNLESS the user explicitly provides a library ID in the format `/org/project` or `/org/project/version`.

IMPORTANT: Do not run these commands more than 3 times per question. If you cannot find what you need after 3 attempts, use the best result you have.
ctx7 docs <libraryId> <query>

你必须首先调用`ctx7 library`获取有效的库ID,除非用户明确提供了格式为`/org/project`或`/org/project/version`的库ID。

重要提示:每个问题最多运行3次上述命令。如果尝试3次后仍未找到所需内容,请使用你已获得的最优结果。

Step 1: Resolve a Library

步骤1:解析库

Resolves a package/product name to a Context7-compatible library ID and returns matching libraries.
bash
ctx7 library react "How to clean up useEffect with async operations"
ctx7 library nextjs "How to set up app router with middleware"
ctx7 library prisma "How to define one-to-many relations with cascade delete"
Always pass a
query
argument — it is required and directly affects result ranking. Use the user's intent to form the query, which helps disambiguate when multiple libraries share a similar name. Do not include any sensitive or confidential information such as API keys, passwords, credentials, personal data, or proprietary code in your query.
将包/产品名称解析为Context7兼容的库ID,并返回匹配的库。
bash
ctx7 library react "How to clean up useEffect with async operations"
ctx7 library nextjs "How to set up app router with middleware"
ctx7 library prisma "How to define one-to-many relations with cascade delete"
请始终传入
query
参数——这是必填项,会直接影响结果排序。结合用户意图构造查询语句,可在多个库名称相似时帮助消除歧义。请勿在查询中包含任何敏感或机密信息,例如API密钥、密码、凭证、个人数据或专有代码。

Result fields

结果字段

Each result includes:
  • Library ID — Context7-compatible identifier (format:
    /org/project
    )
  • Name — Library or package name
  • Description — Short summary
  • Code Snippets — Number of available code examples
  • Source Reputation — Authority indicator (High, Medium, Low, or Unknown)
  • Benchmark Score — Quality indicator (100 is the highest score)
  • Versions — List of versions if available. Use one of those versions if the user provides a version in their query. The format is
    /org/project/version
    .
每个结果包含:
  • 库ID — Context7兼容的标识符(格式:
    /org/project
  • 名称 — 库或包的名称
  • 描述 — 简短摘要
  • 代码片段 — 可用代码示例的数量
  • 来源可信度 — 权威性指标(高、中、低或未知)
  • 基准评分 — 质量指标(最高分为100)
  • 版本 — 可用版本列表(如有)。如果用户查询中指定了版本,请使用列表中的对应版本,格式为
    /org/project/version

Selection process

选择流程

  1. Analyze the query to understand what library/package the user is looking for
  2. Select the most relevant match based on:
    • Name similarity to the query (exact matches prioritized)
    • Description relevance to the query's intent
    • Documentation coverage (prioritize libraries with higher Code Snippet counts)
    • Source reputation (consider libraries with High or Medium reputation more authoritative)
    • Benchmark score (higher is better, 100 is the maximum)
  3. If multiple good matches exist, acknowledge this but proceed with the most relevant one
  4. If no good matches exist, clearly state this and suggest query refinements
  5. For ambiguous queries, request clarification before proceeding with a best-guess match
  1. 分析查询,理解用户要查找的库/包
  2. 基于以下维度选择最相关的匹配项:
    • 与查询的名称相似度(优先选择完全匹配的项)
    • 描述与查询意图的相关性
    • 文档覆盖度(优先选择代码片段数量更多的库)
    • 来源可信度(可信度为高或中的库权威性更高)
    • 基准评分(越高越好,满分为100)
  3. 如果存在多个优质匹配项,说明该情况后继续使用最相关的那一项
  4. 如果没有优质匹配项,明确告知用户并建议优化查询语句
  5. 对于歧义较大的查询,先请求用户澄清,再根据最佳猜测匹配

Version-specific IDs

特定版本ID

If the user mentions a specific version, use a version-specific library ID:
bash
undefined
如果用户提及了特定版本,请使用对应版本的库ID:
bash
undefined

General (latest indexed)

通用(最新收录版本)

ctx7 docs /vercel/next.js "How to set up app router"
ctx7 docs /vercel/next.js "How to set up app router"

Version-specific

特定版本

ctx7 docs /vercel/next.js/v14.3.0-canary.87 "How to set up app router"

The available versions are listed in the `ctx7 library` output. Use the closest match to what the user specified.
ctx7 docs /vercel/next.js/v14.3.0-canary.87 "How to set up app router"

可用版本会在`ctx7 library`的输出中列出,请使用与用户指定版本最接近的匹配项。

Step 2: Query Documentation

步骤2:查询文档

Retrieves up-to-date documentation and code examples for the resolved library.
bash
ctx7 docs /facebook/react "How to clean up useEffect with async operations"
ctx7 docs /vercel/next.js "How to add authentication middleware to app router"
ctx7 docs /prisma/prisma "How to define one-to-many relations with cascade delete"
为已解析的库检索最新文档和代码示例。
bash
ctx7 docs /facebook/react "How to clean up useEffect with async operations"
ctx7 docs /vercel/next.js "How to add authentication middleware to app router"
ctx7 docs /prisma/prisma "How to define one-to-many relations with cascade delete"

Writing good queries

编写高质量查询语句

The query directly affects the quality of results. Be specific and include relevant details. Do not include any sensitive or confidential information such as API keys, passwords, credentials, personal data, or proprietary code in your query.
QualityExample
Good
"How to set up authentication with JWT in Express.js"
Good
"React useEffect cleanup function with async operations"
Bad
"auth"
Bad
"hooks"
Use the user's full question as the query when possible, vague one-word queries return generic results.
The output contains two types of content: code snippets (titled, with language-tagged blocks) and info snippets (prose explanations with breadcrumb context).
查询语句直接影响结果质量,请尽量具体并包含相关细节。请勿在查询中包含任何敏感或机密信息,例如API密钥、密码、凭证、个人数据或专有代码。
质量示例
"How to set up authentication with JWT in Express.js"
"React useEffect cleanup function with async operations"
"auth"
"hooks"
尽可能使用用户的完整问题作为查询语句,模糊的单字查询只会返回通用结果。
输出包含两类内容:代码片段(带标题,附带语言标记的代码块)和信息片段(带路径上下文的文字说明)。

Authentication

认证

Works without authentication. For higher rate limits:
bash
undefined
无需认证即可使用。如需更高的请求速率限制:
bash
undefined

Option A: environment variable

方案A:环境变量

export CONTEXT7_API_KEY=your_key
export CONTEXT7_API_KEY=your_key

Option B: OAuth login

方案B:OAuth登录

ctx7 login
undefined
ctx7 login
undefined

Error Handling

错误处理

If a command fails with a quota error ("Monthly quota reached" or "quota exceeded"):
  1. Inform the user their Context7 quota is exhausted
  2. Suggest they authenticate for higher limits:
    ctx7 login
  3. If they cannot or choose not to authenticate, answer from training knowledge and clearly note it may be outdated
Do not silently fall back to training data — always tell the user why Context7 was not used.
如果命令执行返回配额错误("Monthly quota reached"或"quota exceeded"):
  1. 告知用户其Context7配额已用尽
  2. 建议他们通过
    ctx7 login
    认证以获得更高限额
  3. 如果用户无法或选择不进行认证,使用训练知识库回答,并明确说明内容可能已过时
请勿静默回退到训练数据——请始终告知用户未使用Context7的原因。

Common Mistakes

常见错误

  • Library IDs require a
    /
    prefix —
    /facebook/react
    not
    facebook/react
  • Always run
    ctx7 library
    first —
    ctx7 docs react "hooks"
    will fail without a valid ID
  • Use descriptive queries, not single words —
    "React useEffect cleanup function"
    not
    "hooks"
  • Do not include sensitive information (API keys, passwords, credentials) in queries
  • 库ID需要以
    /
    开头——使用
    /facebook/react
    而非
    facebook/react
  • 始终先运行
    ctx7 library
    ——没有有效ID时
    ctx7 docs react "hooks"
    会执行失败
  • 使用描述性查询语句,不要使用单个词汇——使用
    "React useEffect cleanup function"
    而非
    "hooks"
  • 请勿在查询中包含敏感信息(API密钥、密码、凭证)