$npx -y skills add Dianel555/DSkills --skill context7Fetch up-to-date library/framework/API documentation from Context7, bypassing training-cutoff limits. Use when: (1) User asks how to use/configure/install a library, framework, or SDK, (2) Code examples or API reference needed for a specific package, (3) Version-specific behavior
| 1 | # Context7 |
| 2 | |
| 3 | Fetches current library/framework/API documentation from the Context7 API, so responses cite authoritative docs rather than potentially outdated training data. Standalone Node CLI only (no MCP dependency). |
| 4 | |
| 5 | ## Architecture: Two-Skill Split |
| 6 | |
| 7 | | Skill | Role | Context | Token Cost | |
| 8 | |-------|------|---------|------------| |
| 9 | | **context7** (this file) | Intent detection, library selection, response integration | Full conversation | Higher | |
| 10 | | [context7-fetcher](context7-fetcher.md) | Pure API calls (`search` / `context`) | `context: fork` (isolated) | Lower | |
| 11 | |
| 12 | The main skill never calls the API directly. It delegates each HTTP call to `context7-fetcher` via the Task tool so the forked subagent executes without carrying conversation history. The fetcher's contract is defined in [`context7-fetcher.md`](context7-fetcher.md). |
| 13 | |
| 14 | ### Call Flow |
| 15 | |
| 16 | ``` |
| 17 | User Query → context7 (detect trigger + extract library) |
| 18 | ↓ Task(context7-fetcher) → search <library> <query> → JSON libraries[] |
| 19 | context7 (select best match: name / trustScore / version) |
| 20 | ↓ Task(context7-fetcher) → context <libraryId> <query> → JSON results[] |
| 21 | context7 (integrate relevant snippets into answer) |
| 22 | ``` |
| 23 | |
| 24 | ## Implementation Layout |
| 25 | |
| 26 | - `context7-api.cjs` - Node CLI entrypoint (HTTPS client, .env + env-var API key, MSYS path fix) |
| 27 | - `context7-fetcher.md` - Sub-skill definition (forked context, API executor) |
| 28 | - `.env.example` - API key template (copy to `.env`) |
| 29 | |
| 30 | ## Execution Method |
| 31 | |
| 32 | ```bash |
| 33 | # Prerequisites: Node.js 18+ (no npm install needed; stdlib only) |
| 34 | # Environment: CONTEXT7_API_KEY (optional; public rate limits apply if unset) |
| 35 | |
| 36 | # All examples assume cwd == skills/context7/. Relative path also works from repo root. |
| 37 | node context7-api.cjs search "<library-name>" "<user-query>" |
| 38 | node context7-api.cjs context "<library-id>" "<specific-query>" |
| 39 | ``` |
| 40 | |
| 41 | > In practice, invoke these **through the Task tool pointing at `context7-fetcher`** (see Call Flow), not via direct Bash — that keeps API calls in a forked context and minimizes token use. |
| 42 | |
| 43 | ## Tool Capability Matrix |
| 44 | |
| 45 | | Command | Required Args | Optional Args | Output | |
| 46 | |---------|---------------|---------------|--------| |
| 47 | | `search` | `<libraryName>`, `<query>` | – | `{libraries:[{id,name,description,trustScore,versions[]}]}` | |
| 48 | | `context` | `<libraryId>`, `<query>` | – | `{results:[{title,content,source,relevance}]}` | |
| 49 | |
| 50 | Library IDs are Context7 slugs (e.g., `/facebook/react`, `/vercel/next.js`). For version-specific docs, append the version: `/vercel/next.js/v15.1.8`. |
| 51 | |
| 52 | ## Research Workflow |
| 53 | |
| 54 | ### Step 1: Extract Library Information |
| 55 | From the user query, identify: |
| 56 | - Library name (e.g., "react", "next.js", "prisma") |
| 57 | - Version if specified (e.g., "React 19", "Next.js 15") |
| 58 | - Specific feature/API (e.g., "useEffect cleanup", "middleware") |
| 59 | |
| 60 | ### Step 2: Search for Library → delegate to fetcher |
| 61 | ``` |
| 62 | Task: |
| 63 | - subagent_type: Bash |
| 64 | - description: "Search Context7 for <library>" |
| 65 | - prompt: node skills/context7/context7-api.cjs search "<library>" "<full user question>" |
| 66 | ``` |
| 67 | |
| 68 | ### Step 3: Select Best Match |
| 69 | From search results, choose by: |
| 70 | 1. Exact name match to the user's query |
| 71 | 2. Highest `trustScore` (quality/popularity signal) |
| 72 | 3. Version match if the user specified one |
| 73 | 4. Official packages over community forks |
| 74 | |
| 75 | ### Step 4: Fetch Documentation → delegate to fetcher |
| 76 | ``` |
| 77 | Task: |
| 78 | - subagent_type: Bash |
| 79 | - description: "Fetch Context7 docs for <library>" |
| 80 | - prompt: node skills/context7/context7-api.cjs context "<libraryId>" "<feature query>" |
| 81 | ``` |
| 82 | |
| 83 | ### Step 5: Integrate into Response |
| 84 | 1. Answer accurately with the fetched, current information |
| 85 | 2. Include code examples drawn from the docs |
| 86 | 3. Cite version when relevant |
| 87 | 4. Quote only the relevant snippet — do not dump entire documentation |
| 88 | |
| 89 | ## Environment Setup |
| 90 | |
| 91 | The `context7-api.cjs` script loads the API key in priority order: |
| 92 | |
| 93 | 1. `CONTEXT7_API_KEY` environment variable |
| 94 | 2. `.env` file in the skill directory (`.claude/skills/context7/.env` or `skills/context7/.env`) |
| 95 | |
| 96 | ```bash |
| 97 | cp .env.example .env |
| 98 | # Edit .env: CONTEXT7_API_KEY=<your-key> |
| 99 | ``` |
| 100 | |
| 101 | Get a key at [context7.com/dashboard](https://context7.com/dashboard). Without a key, the API falls back to public rate limits (lower quota). |
| 102 | |
| 103 | ## Error Handling |
| 104 | |
| 105 | | Error | Recovery | |
| 106 | |-------|--------- |