context7-auto-research

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Context7 Auto Research Skill

Context7 Auto Research 技能

This skill automatically fetches current documentation from Context7 API when detecting library/framework-related queries, ensuring responses use up-to-date information instead of potentially outdated training data.
当检测到与库/框架相关的查询时,该Skill会自动从Context7 API获取最新文档,确保回复使用当前信息而非可能过时的训练数据。

Automatic Activation Triggers

自动激活触发条件

This skill should activate proactively when the user's message contains:
当用户消息包含以下内容时,该Skill应主动激活

Implementation Queries (实现相关)

实现相关查询

  • "如何实现" / "怎么写" / "怎么做"
  • "How do I..." / "How to..." / "How can I..."
  • "Show me how to..." / "Write code for..."
  • "如何实现" / "怎么写" / "怎么做"
  • "How do I..." / "How to..." / "How can I..."
  • "Show me how to..." / "Write code for..."

Configuration & Setup (配置相关)

配置与设置相关

  • "配置" / "设置" / "安装"
  • "configure" / "setup" / "install"
  • "初始化" / "initialize"
  • "配置" / "设置" / "安装"
  • "configure" / "setup" / "install"
  • "初始化" / "initialize"

Documentation Requests (文档相关)

文档相关请求

  • "文档" / "参考" / "API"
  • "documentation" / "docs" / "reference"
  • "查看" / "look up"
  • "文档" / "参考" / "API"
  • "documentation" / "docs" / "reference"
  • "查看" / "look up"

Library/Framework Mentions (库/框架提及)

库/框架提及

  • React, Vue, Angular, Svelte, Solid
  • Next.js, Nuxt, Remix, Astro
  • Express, Fastify, Koa, Hono
  • Prisma, Drizzle, TypeORM
  • Supabase, Firebase, Clerk
  • Tailwind, shadcn/ui, Radix
  • Any npm package or GitHub repository
  • React, Vue, Angular, Svelte, Solid
  • Next.js, Nuxt, Remix, Astro
  • Express, Fastify, Koa, Hono
  • Prisma, Drizzle, TypeORM
  • Supabase, Firebase, Clerk
  • Tailwind, shadcn/ui, Radix
  • 任何npm包或GitHub仓库

Code Generation Requests (代码生成)

代码生成请求

  • "生成代码" / "写一个" / "创建"
  • "generate" / "create" / "build"
  • "implement" / "add feature"
  • "生成代码" / "写一个" / "创建"
  • "generate" / "create" / "build"
  • "implement" / "add feature"

Research Process

研究流程

When triggered, follow this workflow:
触发后,遵循以下工作流:

Step 1: Extract Library Information

步骤1:提取库信息

Identify the library/framework from the user's query:
  • Library name (e.g., "react", "next.js", "prisma")
  • Version if specified (e.g., "React 19", "Next.js 15")
  • Specific feature/API mentioned (e.g., "useEffect", "middleware", "relations")
从用户查询中识别出库/框架:
  • 库名称(例如:"react", "next.js", "prisma")
  • 若指定版本(例如:"React 19", "Next.js 15")
  • 提及的特定功能/API(例如:"useEffect", "middleware", "relations")

Step 2: Search for Library

步骤2:搜索库

Use Task tool to call context7-fetcher sub-skill:
Task parameters:
- subagent_type: Bash
- description: "Search Context7 for library"
- prompt: node .claude/skills/context7-auto-research/context7-api.js search "<library-name>" "<user-query>"
Example:
Task: Search for Next.js
Prompt: node .claude/skills/context7-auto-research/context7-api.js search "next.js" "How to configure middleware in Next.js 15"
Response format:
json
{
  "libraries": [
    {
      "id": "/vercel/next.js",
      "name": "Next.js",
      "description": "The React Framework",
      "trustScore": 95,
      "versions": ["v15.1.8", "v14.2.0", "v13.5.0"]
    }
  ]
}
Why use Task tool?
  • Uses
    context: fork
    from context7-fetcher sub-skill
  • Avoids carrying conversation history to API calls
  • Reduces Token consumption
使用Task工具调用context7-fetcher子Skill:
Task parameters:
- subagent_type: Bash
- description: "Search Context7 for library"
- prompt: node .claude/skills/context7-auto-research/context7-api.js search "<library-name>" "<user-query>"
示例:
Task: Search for Next.js
Prompt: node .claude/skills/context7-auto-research/context7-api.js search "next.js" "How to configure middleware in Next.js 15"
响应格式:
json
{
  "libraries": [
    {
      "id": "/vercel/next.js",
      "name": "Next.js",
      "description": "The React Framework",
      "trustScore": 95,
      "versions": ["v15.1.8", "v14.2.0", "v13.5.0"]
    }
  ]
}
为何使用Task工具?
  • 使用context7-fetcher子Skill的
    context: fork
  • 避免将对话历史带入API调用
  • 减少Token消耗

Step 3: Select Best Match

步骤3:选择最佳匹配

From search results, choose the library based on:
  1. Exact name match to user's query
  2. Highest trust score (indicates quality/popularity)
  3. Version match if user specified (e.g., "Next.js 15" → prefer v15.x)
  4. Official packages over community forks
从搜索结果中,根据以下条件选择库:
  1. 名称精确匹配用户查询
  2. 信任分数最高(代表质量/流行度)
  3. 若用户指定版本则版本匹配(例如:"Next.js 15" → 优先选择v15.x)
  4. 官方包优先于社区分支

Step 4: Fetch Documentation

步骤4:获取文档

Use Task tool to call context7-fetcher sub-skill:
Task parameters:
- subagent_type: Bash
- description: "Fetch documentation from Context7"
- prompt: node .claude/skills/context7-auto-research/context7-api.js context "<library-id>" "<specific-query>"
Example:
Task: Fetch Next.js middleware docs
Prompt: node .claude/skills/context7-auto-research/context7-api.js context "/vercel/next.js" "middleware configuration"
Response format:
json
{
  "results": [
    {
      "title": "Middleware",
      "content": "Middleware allows you to run code before a request is completed...",
      "source": "docs/app/building-your-application/routing/middleware.md",
      "relevance": 0.95
    }
  ]
}
Why use Task tool?
  • Independent context for API calls
  • No conversation history overhead
  • Faster execution
使用Task工具调用context7-fetcher子Skill:
Task parameters:
- subagent_type: Bash
- description: "Fetch documentation from Context7"
- prompt: node .claude/skills/context7-auto-research/context7-api.js context "<library-id>" "<specific-query>"
示例:
Task: Fetch Next.js middleware docs
Prompt: node .claude/skills/context7-auto-research/context7-api.js context "/vercel/next.js" "middleware configuration"
响应格式:
json
{
  "results": [
    {
      "title": "Middleware",
      "content": "Middleware allows you to run code before a request is completed...",
      "source": "docs/app/building-your-application/routing/middleware.md",
      "relevance": 0.95
    }
  ]
}
为何使用Task工具?
  • API调用使用独立上下文
  • 无对话历史开销
  • 执行速度更快

Step 5: Integrate into Response

步骤5:整合到回复中

Use the fetched documentation to:
  1. Answer accurately with current information
  2. Include code examples from the docs
  3. Cite version when relevant
  4. Provide context about the feature/API
使用获取到的文档:
  1. 准确回答,使用当前信息
  2. 包含代码示例,来自文档
  3. 相关时注明版本
  4. 提供功能/API的上下文说明

Helper Script Usage

辅助脚本使用

The
context7-api.js
script provides two commands:
context7-api.js
脚本提供两个命令:

Search Library

搜索库

bash
node context7-api.js search <libraryName> <query>
  • Returns matching libraries with metadata
  • Use for initial library resolution
bash
node context7-api.js search <libraryName> <query>
  • 返回匹配的库及元数据
  • 用于初始库识别

Get Context

获取上下文

bash
node context7-api.js context <libraryId> <query>
  • Returns relevant documentation snippets
  • Use after selecting a library
bash
node context7-api.js context <libraryId> <query>
  • 返回相关文档片段
  • 选择库后使用

Environment Setup

环境设置

The script supports two ways to configure the API key:
脚本支持两种配置API密钥的方式:

Option 1: .env File (Recommended)

选项1:.env文件(推荐)

Create a
.env
file in the skill directory:
bash
undefined
在技能目录中创建
.env
文件:
bash
undefined

In .claude/skills/context7-auto-research/.env

In .claude/skills/context7-auto-research/.env

CONTEXT7_API_KEY=your_api_key_here

You can copy from the example:

```bash
cp .env.example .env
CONTEXT7_API_KEY=your_api_key_here

你可以从示例文件复制:

```bash
cp .env.example .env

Then edit .env with your actual API key

然后编辑.env文件填入实际API密钥

undefined
undefined

Option 2: Environment Variable

选项2:环境变量

bash
export CONTEXT7_API_KEY="your-api-key"
Priority: Environment variable > .env file
Get API Key: Visit context7.com/dashboard to register and obtain your API key.
If not set, the API will use public rate limits (lower quota).
bash
export CONTEXT7_API_KEY="your-api-key"
优先级: 环境变量 > .env文件
获取API密钥: 访问context7.com/dashboard注册并获取API密钥。
若未设置,API将使用公共速率限制(配额较低)。

Best Practices

最佳实践

Query Specificity

查询特异性

  • Pass the full user question as the query parameter for better relevance
  • Include specific feature names (e.g., "useEffect cleanup" vs just "useEffect")
  • 完整用户问题作为查询参数,以获得更好的相关性
  • 包含特定功能名称(例如:"useEffect cleanup" 而非仅 "useEffect")

Version Awareness

版本意识

  • When users mention versions, use version-specific library IDs
  • Example:
    /vercel/next.js/v15.1.8
    instead of
    /vercel/next.js
  • 当用户提及版本时,使用特定版本的库ID
  • 示例:
    /vercel/next.js/v15.1.8
    而非
    /vercel/next.js

Error Handling

错误处理

  • If library search returns no results, inform user and suggest alternatives
  • If API fails, fall back to training data but mention it may be outdated
  • Handle rate limits gracefully (429 errors)
  • 若库搜索无结果,告知用户并建议替代方案
  • 若API调用失败,回退到训练数据但注明可能过时
  • 优雅处理速率限制(429错误)

Response Quality

回复质量

  • Don't dump entire documentation - extract relevant parts
  • Combine multiple doc snippets if needed for complete answer
  • Always include practical code examples
  • 不要直接输出整个文档 - 提取相关部分
  • 若需要完整回答,可组合多个文档片段
  • 始终包含实用代码示例

Example Workflows

示例工作流

Example 1: React Hook Question

示例1:React Hook问题

User: "How do I use useEffect to fetch data in React 19?"
Skill Actions:
  1. Detect trigger: "How do I use" + "useEffect" + "React 19"
  2. Search:
    node context7-api.js search "react" "useEffect fetch data"
  3. Select:
    /facebook/react/v19.0.0
    (version match)
  4. Fetch:
    node context7-api.js context "/facebook/react/v19.0.0" "useEffect data fetching"
  5. Respond with current React 19 patterns (e.g., using
    use()
    hook if applicable)
用户: "How do I use useEffect to fetch data in React 19?"
Skill操作:
  1. 检测触发条件:"How do I use" + "useEffect" + "React 19"
  2. 搜索:
    node context7-api.js search "react" "useEffect fetch data"
  3. 选择:
    /facebook/react/v19.0.0
    (版本匹配)
  4. 获取:
    node context7-api.js context "/facebook/react/v19.0.0" "useEffect data fetching"
  5. 使用当前React 19模式回复(例如:若适用则使用
    use()
    hook)

Example 2: Next.js Configuration

示例2:Next.js配置

User: "配置 Next.js 15 的中间件"
Skill Actions:
  1. Detect trigger: "配置" + "Next.js 15" + "中间件"
  2. Search:
    node context7-api.js search "next.js" "middleware configuration"
  3. Select:
    /vercel/next.js/v15.1.8
  4. Fetch:
    node context7-api.js context "/vercel/next.js/v15.1.8" "middleware"
  5. Respond with Next.js 15 middleware setup
用户: "配置 Next.js 15 的中间件"
Skill操作:
  1. 检测触发条件:"配置" + "Next.js 15" + "中间件"
  2. 搜索:
    node context7-api.js search "next.js" "middleware configuration"
  3. 选择:
    /vercel/next.js/v15.1.8
  4. 获取:
    node context7-api.js context "/vercel/next.js/v15.1.8" "middleware"
  5. 回复Next.js 15中间件设置方法

Example 3: Prisma Relations

示例3:Prisma关联

User: "Show me how to define one-to-many relations in Prisma"
Skill Actions:
  1. Detect trigger: "Show me how" + "Prisma"
  2. Search:
    node context7-api.js search "prisma" "one-to-many relations"
  3. Select:
    /prisma/prisma
    (highest trust score)
  4. Fetch:
    node context7-api.js context "/prisma/prisma" "one-to-many relations"
  5. Respond with Prisma schema examples
用户: "Show me how to define one-to-many relations in Prisma"
Skill操作:
  1. 检测触发条件:"Show me how" + "Prisma"
  2. 搜索:
    node context7-api.js search "prisma" "one-to-many relations"
  3. 选择:
    /prisma/prisma
    (信任分数最高)
  4. 获取:
    node context7-api.js context "/prisma/prisma" "one-to-many relations"
  5. 回复Prisma schema示例

Architecture: Context Separation

架构:上下文分离

Why Split into Two Skills?

为何拆分为两个Skill?

This skill adopts a two-phase architecture:
  1. Main Skill (context7-auto-research) - Needs conversation context:
    • Detect trigger keywords in user message
    • Extract user query intent
    • Select best matching library (version, name, trust score)
    • Integrate documentation into response
  2. Sub-Skill (context7-fetcher) - Independent context (
    context: fork
    ):
    • Execute API calls to Context7
    • Pure HTTP requests, no conversation history needed
    • Reduce Token consumption
该Skill采用两阶段架构
  1. 主Skill(context7-auto-research) - 需要对话上下文:
    • 检测用户消息中的触发关键词
    • 提取用户查询意图
    • 选择最佳匹配库(版本、名称、信任分数)
    • 将文档整合到回复中
  2. 子Skill(context7-fetcher) - 独立上下文(
    context: fork
    ):
    • 执行Context7 API调用
    • 纯HTTP请求,无需对话历史
    • 减少Token消耗

Benefits

优势

AspectMain SkillSub-Skill
ContextFull conversationFork (independent)
PurposeIntent analysisAPI execution
Token usageHigherLower
ExecutionSequentialCan be parallel
维度Main SkillSub-Skill
上下文完整对话上下文Fork(独立上下文)
用途意图分析API执行
Token消耗较高较低
执行方式顺序执行可并行执行

Call Flow

调用流程

User Query → Main Skill (detect + analyze)
           Task Tool → Sub-Skill (API search)
           Main Skill (select best match)
           Task Tool → Sub-Skill (API fetch docs)
           Main Skill (integrate + respond)
用户查询 → 主Skill(检测+分析)
           Task工具 → 子Skill(API搜索)
           主Skill(选择最佳匹配)
           Task工具 → 子Skill(API获取文档)
           主Skill(整合+回复)

Integration with Existing Skills

与现有Skill的集成

This skill complements the existing
documentation-lookup
skill:
  • auto-research: Proactive, automatic activation
  • documentation-lookup: Manual, user-invoked via
    /context7:docs
Both can coexist - use auto-research for seamless UX, documentation-lookup for explicit queries.
该Skill补充现有
documentation-lookup
Skill:
  • auto-research:主动、自动激活
  • documentation-lookup:手动、用户通过
    /context7:docs
    调用
两者可共存 - auto-research用于无缝用户体验,documentation-lookup用于明确查询。

Performance Considerations

性能注意事项

  • Cache responses: Documentation changes infrequently
  • Parallel requests: If user asks about multiple libraries, fetch in parallel using multiple Task calls
  • Timeout handling: Set reasonable timeouts (5-10s) for API calls
  • Fallback strategy: If API unavailable, use training data with disclaimer
  • Context efficiency: Sub-skill uses fork context to minimize Token consumption
  • 缓存响应:文档变更频率低
  • 并行请求:若用户询问多个库,使用多个Task调用并行获取
  • 超时处理:为API调用设置合理超时(5-10秒)
  • 回退策略:若API不可用,使用训练数据并附带免责声明
  • 上下文效率:子Skill使用fork上下文以最小化Token消耗

Limitations

局限性

  • Requires internet connection for API access
  • Subject to Context7 API rate limits
  • May not have documentation for very new or obscure libraries
  • Documentation quality depends on source repository structure
  • 需要互联网连接以访问API
  • 受Context7 API速率限制约束
  • 可能没有极新或小众库的文档
  • 文档质量取决于源仓库结构 ",