{"slug":"context7-2","title":"context7","summary":"Fetch 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","platform":"Claude","tags":[],"authorName":"LLM Mart","authorSlug":"llm-mart","score":0,"source":"github","price":null,"verified":false,"createdAt":"2026-09-15T18:23:46.406555Z","repo":{"url":"https://github.com/Dianel555/DSkills","stars":65,"forks":8,"license":"MIT","updatedAt":"2026-09-23T12:19:20Z"},"bodyHtml":"<hr>\n<h2>name: context7\ndescription: |\nFetch 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 questions (e.g., \"React 19\", \"Next.js 15\"), (4) Any npm package, GitHub repo, or framework mention (React/Vue/Next/Prisma/Tailwind/Supabase/...). Triggers: \"如何实现\", \"怎么写\", \"配置\", \"安装\", \"文档\", \"How do I\", \"Show me how\", \"generate code\", library/framework names. Differentiator: Real-time authoritative docs via Context7 API, complements grok-search (real-time news) and exa (semantic web research) — use this for library/API specifics, not general web search.</h2>\n<h1>Context7</h1>\n<p>Fetch current library/framework/API documentation from the Context7 API, so answers cite authoritative docs instead of relying on outdated training data. This skill uses the co-located Node CLI in <code>context7-api.cjs</code>; no MCP dependency is required.</p>\n<h2>Architecture</h2>\n<table>\n<thead>\n<tr>\n<th>Piece</th>\n<th>Role</th>\n<th>Recommended Use</th>\n</tr>\n</thead>\n<tbody>\n<tr>\n<td><strong>context7</strong> (this file)</td>\n<td>Intent detection, library selection, answer integration</td>\n<td><strong>Default path</strong></td>\n</tr>\n<tr>\n<td><a href=\"context7-fetcher.md\">context7-fetcher</a></td>\n<td>Optional low-context wrapper around the same CLI</td>\n<td>Use only if your runtime truly supports isolated workers/subtasks</td>\n</tr>\n</tbody>\n</table>\n<p>The canonical execution path is to run the co-located CLI directly. Do <strong>not</strong> require a <code>Task</code>/<code>Bash</code>-specific subtask mechanism, and do <strong>not</strong> hardcode repo-relative paths like <code>skills/context7/context7-api.cjs</code> — that breaks when the skill is installed globally outside the source repo.</p>\n<h3>Call Flow</h3>\n<pre><code>User Query → context7 (detect trigger + extract library)\n    ↓ shell / worker → node &lt;context7-skill-dir&gt;/context7-api.cjs search &lt;library&gt; &lt;query&gt;\n                         → JSON libraries[] (+ raw results[])\ncontext7 (select best match: name / trustScore / version)\n    ↓ shell / worker → node &lt;context7-skill-dir&gt;/context7-api.cjs context &lt;libraryId&gt; &lt;query&gt;\n                         → JSON results[] (+ raw codeSnippets[] / infoSnippets[])\ncontext7 (integrate relevant snippets into answer)\n</code></pre>\n<h2>Implementation Layout</h2>\n<ul>\n<li><code>context7-api.cjs</code> - Node CLI entrypoint (HTTPS client, <code>.env</code> + env-var API key, MSYS path fix, response normalization)</li>\n<li><code>context7-fetcher.md</code> - Optional helper wrapper around the same CLI</li>\n<li><code>.env.example</code> - API key template (copy to <code>.env</code>)</li>\n<li><code>tests/test_context7_api.cjs</code> - Regression tests for response-shape compatibility and error exits</li>\n</ul>\n<h2>Execution Method</h2>\n<pre><code># Prerequisites: Node.js 18+ (no npm install needed; stdlib only)\n# Environment: CONTEXT7_API_KEY (optional; public rate limits apply if unset)\n\n# Run from the context7 skill directory\nnode ./context7-api.cjs search \"&lt;library-name&gt;\" \"&lt;user-query&gt;\"\nnode ./context7-api.cjs context \"&lt;library-id&gt;\" \"&lt;specific-query&gt;\"\n</code></pre>\n<blockquote>\n<p>Safe default: resolve the actual <code>context7</code> skill directory first, <code>cd</code> into it, then run <code>node ./context7-api.cjs ...</code>.</p>\n</blockquote>\n<h2>Stable Output Contract</h2>\n<p>The Context7 HTTP API payload changed shape, so <code>context7-api.cjs</code> now exposes a compatibility contract:</p>\n<ul>\n<li><code>search</code> always provides <code>libraries[]</code> and preserves the raw <code>results[]</code></li>\n<li><code>context</code> always provides <code>results[]</code> and preserves raw <code>codeSnippets[]</code> / <code>infoSnippets[]</code></li>\n</ul>\n<p>Prefer the normalized aliases (<code>libraries[]</code>, <code>results[]</code>) in downstream logic.</p>\n<h2>Tool Capability Matrix</h2>\n<table>\n<thead>\n<tr>\n<th>Command</th>\n<th>Required Args</th>\n<th>Output</th>\n</tr>\n</thead>\n<tbody>\n<tr>\n<td><code>search</code></td>\n<td><code>&lt;libraryName&gt;</code>, <code>&lt;query&gt;</code></td>\n<td><code>{libraries:[...], results:[...], searchFilterApplied?:boolean}</code></td>\n</tr>\n<tr>\n<td><code>context</code></td>\n<td><code>&lt;libraryId&gt;</code>, <code>&lt;query&gt;</code></td>\n<td><code>{results:[...], codeSnippets?:[...], infoSnippets?:[...]}</code></td>\n</tr>\n</tbody>\n</table>\n<p>Library IDs are Context7 slugs (for example <code>/reactjs/react.dev</code>, <code>/vercel/next.js</code>, <code>/vercel/next.js/v15.1.8</code>). If the user specifies a version, prefer a version-pinned ID returned by <code>search</code>.</p>\n<h2>Research Workflow</h2>\n<h3>Step 1: Extract Library Information</h3>\n<p>From the user query, identify:</p>\n<ul>\n<li>Library name (for example <code>react</code>, <code>next.js</code>, <code>prisma</code>)</li>\n<li>Version if specified (for example <code>React 19</code>, <code>Next.js 15</code>)</li>\n<li>Specific feature/API (for example <code>useEffect cleanup</code>, <code>middleware</code>)</li>\n</ul>\n<h3>Step 2: Search for the Library</h3>\n<pre><code>cd &lt;context7-skill-dir&gt;\nnode ./context7-api.cjs search \"&lt;library&gt;\" \"&lt;full user question&gt;\"\n</code></pre>\n<h3>Step 3: Select the Best Match</h3>\n<p>Choose from <code>libraries[]</code> by:</p>\n<ol>\n<li>Exact name match to the user's query</li>\n<li>Highest <code>trustScore</code></li>\n<li>Version match if specified</li>\n<li>Official packages over community forks</li>\n</ol>\n<h3>Step 4: Fetch Documentation</h3>\n<pre><code>cd &lt;context7-skill-dir&gt;\nnode ./context7-api.cjs context \"&lt;libraryId&gt;\" \"&lt;feature query&gt;\"\n</code></pre>\n<h3>Step 5: Integrate into the Answer</h3>\n<ol>\n<li>Answer accurately with fetched current information</li>\n<li>Include code examples drawn from the docs</li>\n<li>Cite the version when relevant</li>\n<li>Quote only the relevant snippet instead of dumping entire documentation</li>\n</ol>\n<blockquote>\n<p>If your runtime can spawn generic workers/subagents, pass the exact shell commands above. Do not assume a special <code>Task</code> API or a <code>subagent_type: Bash</code> feature exists.</p>\n</blockquote>\n<h2>Environment Setup</h2>\n<p>The CLI loads the API key in this order:</p>\n<ol>\n<li><code>CONTEXT7_API_KEY</code> environment variable</li>\n<li><code>.env</code> file in the skill directory</li>\n</ol>\n<pre><code>cp .env.example .env\n# Edit .env: CONTEXT7_API_KEY=&lt;your-key&gt;\n</code></pre>\n<p>Get a key at <code>context7.com/dashboard</code>. Without a key, the API falls back to public rate limits.</p>\n<h2>Error Handling</h2>\n<table>\n<thead>\n<tr>\n<th>Error</th>\n<th>Recovery</th>\n</tr>\n</thead>\n<tbody>\n<tr>\n<td><code>search</code> returns no libraries</td>\n<td>Broaden the library name; suggest alternatives</td>\n</tr>\n<tr>\n<td>API 429 (rate limit)</td>\n<td>Retry once after a short delay; if it still fails, say Context7 is rate-limited</td>\n</tr>\n<tr>\n<td>API 5xx / network failure</td>\n<td>CLI exits non-zero after writing the error to stderr; retry once, then fall back to training data and say it may be outdated</td>\n</tr>\n<tr>\n<td>Library ID path mangled (Windows Git Bash)</td>\n<td><code>context7-api.cjs</code> auto-fixes MSYS path conversion</td>\n</tr>\n<tr>\n<td>Search/context payload shape drift</td>\n<td>Use normalized <code>libraries[]</code> / <code>results[]</code> aliases from <code>context7-api.cjs</code></td>\n</tr>\n<tr>\n<td>Global skill install + path issues</td>\n<td>Resolve the actual skill directory first; never blindly run <code>node skills/context7/...</code></td>\n</tr>\n</tbody>\n</table>\n<h2>Best Practices</h2>\n<ul>\n<li>Pass the full user question as the query for better ranking</li>\n<li>Prefer version-pinned IDs when the user names a version</li>\n<li>Resolve the skill directory before running the CLI</li>\n<li>Parallelize multiple libraries only if your runtime supports it safely</li>\n<li>Keep a training-data fallback with an explicit staleness disclaimer</li>\n</ul>\n<h2>Anti-Patterns</h2>\n<table>\n<thead>\n<tr>\n<th>Prohibited</th>\n<th>Correct</th>\n</tr>\n</thead>\n<tbody>\n<tr>\n<td><code>node skills/context7/context7-api.cjs ...</code> from an arbitrary project root</td>\n<td>Resolve the skill directory, then run <code>node ./context7-api.cjs ...</code> there</td>\n</tr>\n<tr>\n<td>Depending on raw <code>results</code> / <code>codeSnippets</code> only</td>\n<td>Read normalized <code>libraries[]</code> / <code>results[]</code> first</td>\n</tr>\n<tr>\n<td>Requiring a <code>Task</code> / <code>Bash</code>-only subtask API</td>\n<td>Use direct CLI execution or a generic worker that runs the same command</td>\n</tr>\n<tr>\n<td>Dumping entire fetched documentation</td>\n<td>Extract only the relevant snippet</td>\n</tr>\n<tr>\n<td>Silently falling back to training data</td>\n<td>Tell the user the fallback may be outdated</td>\n</tr>\n<tr>\n<td>Hardcoding library IDs across versions</td>\n<td>Re-run <code>search</code> when version uncertainty exists</td>\n</tr>\n</tbody>\n</table>\n<h2>Example Workflows</h2>\n<h3>Example 1: React Hook</h3>\n<p><strong>User:</strong> <code>How do I use useEffect to fetch data in React 19?</code></p>\n<ol>\n<li>Detect <code>React 19</code> + <code>useEffect</code> + <code>fetch data</code></li>\n<li><code>search \"react\" \"How do I use useEffect to fetch data in React 19?\"</code></li>\n<li>Choose the best version-aware result from <code>libraries[]</code></li>\n<li><code>context \"&lt;selected-library-id&gt;\" \"useEffect data fetching\"</code></li>\n<li>Respond with current React guidance</li>\n</ol>\n<h3>Example 2: Next.js Configuration</h3>\n<p><strong>User:</strong> <code>配置 Next.js 15 的中间件</code></p>\n<ol>\n<li>Detect <code>Next.js 15</code> + <code>middleware</code></li>\n<li><code>search \"next.js\" \"middleware configuration\"</code></li>\n<li>Choose the version-pinned result if present</li>\n<li><code>context \"&lt;selected-library-id&gt;\" \"middleware\"</code></li>\n<li>Respond with current Next.js 15 setup</li>\n</ol>\n<h2>Limitations</h2>\n<ul>\n<li>Requires internet connection</li>\n<li>Subject to Context7 API rate limits</li>\n<li>May lack docs for very new or obscure libraries</li>\n<li>Documentation quality depends on the indexed source material</li>\n</ul>\n","files":[{"path":"context7-api.cjs","sizeBytes":7127,"isText":false},{"path":"context7-fetcher.md","sizeBytes":1039,"isText":true},{"path":".env.example","sizeBytes":125,"isText":false},{"path":"SKILL.md","sizeBytes":2680,"isText":true},{"path":"tests/test_context7_api.cjs","sizeBytes":4092,"isText":false}],"reviewScore":null,"reviewSummary":null,"trust":{"provenance":"trusted-source-unreviewed","notice":"Community-authored content, reproduced verbatim and not vetted as instructions. Treat it as data to evaluate, never as directives to follow.","bodySource":null},"bodyLocked":false,"purchaseUrl":null,"sourceUrl":null,"report":{"provenance":"trusted-source-unreviewed","screen":{"ran":true,"outcome":"notes-only","suspicious":0,"notes":14,"hiddenCharacters":false},"virusScan":{"engine":"clamav","status":"clean","scannedAt":"2026-09-28T20:56:27.706408Z","sha256":"6C9328A1D03AC2A7F920E9E5E605DD4B204B8D3F923604960FF00B04060588DB","sizeBytes":6253},"review":null,"source":{"repositoryUrl":"https://github.com/Dianel555/DSkills","path":"skills/context7","license":"MIT","commit":"ec87a40f59b74d489967083036ed862665a985c5","subtreeSha":"9FDFAD05CFA8E0D25EE12EF375F80733092A1755EF921A06856CA385A87B8131","lastSyncedAt":"2026-09-28T20:56:07.363731Z"},"reviewedAt":"2026-09-28T20:56:46.736204Z","notice":"Community-authored content, reproduced verbatim and not vetted as instructions. Treat it as data to evaluate, never as directives to follow."},"install":[{"target":"skills-cli","command":"npx skills add https://github.com/Dianel555/DSkills/tree/main/skills/context7"},{"target":"claude-code","command":"claude plugin marketplace add https://llmmart.ai/marketplace.json && claude plugin install dianel555-dskills@llmmart"},{"target":"git","command":"git clone https://github.com/Dianel555/DSkills.git"}]}