AgentSkillsCN

understanding-code-context

在了解外部库、框架或依赖项时使用——通过Context7而非网页搜索或源代码阅读,为您提供查找与阅读官方文档的工作流。

SKILL.md
--- frontmatter
name: understanding-code-context
description: Use when understanding external libraries, frameworks, or dependencies - provides workflows for finding and reading official documentation via Context7 instead of web search or source code reading

Understanding Code Context

Overview

Core principle: Use official documentation (Context7) to understand external libraries and frameworks instead of web search or reading source code.

This skill provides structured workflows for finding authoritative, version-specific documentation for external dependencies.

When to Use

Use this skill when:

  • Understanding how an external library/framework works
  • Learning library concepts, patterns, and APIs
  • Finding official documentation for dependencies
  • Understanding library configuration and usage patterns

Don't use for:

  • Exploring project code (use other tools)
  • Finding implementations in your codebase
  • Simple file content reading

Context7 Tool Usage

Primary tool: Context7 provides authoritative, version-specific documentation for external libraries.

Commands

bash
# Step 1: Find library ID
resolve-library-id "library-name"

# Step 2: Get documentation
get-library-docs context7CompatibleLibraryID="/org/project"

Search Strategy

When searching for library documentation, try multiple variations:

  1. Exact package name: "importmap-rails"
  2. Framework + concept: "rails import maps"
  3. Organization/repo: "rails/importmap"
  4. Base name: "importmap"

Important: Try 2+ variations before using WebSearch. Context7 has official, version-specific documentation. WebSearch gives you blog posts and outdated StackOverflow.

Core Workflow

Understanding External Library:

code
1. resolve-library-id "library-name"
   - If not found: try variations (framework + concept, org/repo, base name)
   - Try 2+ variations before giving up
2. get-library-docs context7CompatibleLibraryID="/org/project"
3. Read and understand official patterns, APIs, and concepts
4. Apply understanding to project usage

Example:

markdown
User: "Help me understand how importmap works and how to add a new library"

You:
1. resolve-library-id "importmap-rails"
   - If not found: try "rails/importmap", "rails import maps", "importmap"
2. get-library-docs context7CompatibleLibraryID="/rails/importmap"
3. Understand: import maps spec, pin vs pin_all_from, CDN vs vendor
4. Explain concepts and how to add a new library based on official docs

Red Flags - STOP Immediately

If you catch yourself doing ANY of these, STOP and start over:

  • ❌ "Context7 didn't work" after 1 try (try 2+ search term variations!)
  • ❌ "WebSearch is faster" (it's less accurate and often outdated!)
  • ❌ "I know how this lib works" (check official docs anyway!)
  • ❌ Reading source code before checking Context7 docs
  • ❌ Using WebSearch before trying Context7 variations

All of these mean: STOP. Try Context7 with multiple search variations first.

Anti-Patterns

Common mistakes:

MistakeFix
WebSearch firstUse Context7 with multiple search term variations
One search term onlyTry 2+ variations (exact name, framework+concept, org/repo, base name)
Reading source codeCheck Context7 official docs first
Assuming library behaviorOfficial docs explain intent, best practices, and gotchas

Why Context7 over WebSearch:

  • Official, version-specific documentation
  • Authoritative patterns and APIs
  • Up-to-date information
  • Explains intent and best practices

Quick Reference

Find library documentation:

bash
resolve-library-id "library-name"
get-library-docs context7CompatibleLibraryID="/org/project"

Search term variations to try:

  1. Exact package name: "package-name"
  2. Framework + concept: "framework concept"
  3. Organization/repo: "org/repo"
  4. Base name: "basename"

Troubleshooting

Context7 Connection Issues

"Context7 server not connected"

  • Verify MCP server is running in Settings > Extensions
  • Reconnect Context7 if status shows disconnected
  • Check API key is valid

"No results found"

  • Try multiple search term variations (see Quick Reference)
  • Check spelling of library name
  • Some libraries may not be indexed - fall back to WebSearch

Library Not Found

After trying multiple variations:

  1. Check if library exists on npm/PyPI/etc.
  2. Use WebSearch as fallback for unindexed libraries
  3. Check the library's official documentation URL directly

Stale Documentation

"Documentation seems outdated"

  • Context7 provides version-specific docs
  • Verify you're using the correct library ID
  • Check library's changelog for recent changes

See Also