Context7 CLI
The Context7 CLI does three things: fetches up-to-date library documentation, manages AI coding skills, and sets up Context7 MCP for your editor.
Make sure the CLI is up to date before running commands:
npm install -g ctx7@latest
Or run directly without installing:
npx ctx7@latest <command>
What this skill covers
- Documentation — Fetch current docs for any library. Use when writing code, verifying API signatures, or when training data may be outdated.
- Skills management — Install, search, suggest, list, remove, and generate AI coding skills.
- Setup — Configure Context7 MCP for Claude Code / Cursor / OpenCode.
Documentation Lookup — Two-Step Workflow
You MUST call 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.
Step 1: Resolve Library Name
npx ctx7@latest library <name> "<query>"
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.
Use the official library name with proper punctuation (e.g., "Next.js" not "nextjs", "Customer.io" not "customerio", "Three.js" not "threejs"). If results look wrong, try alternate spellings such as next.js before changing the query.
Result fields to use for selection:
- 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
Selection process:
- Analyze the query to understand what library/package the user is looking for
- Select the most relevant match based on name similarity, description relevance, documentation coverage, source reputation, and benchmark score
- If multiple good matches exist, acknowledge this but proceed with the most relevant one
- If no good matches exist, clearly state this and suggest query refinements
- For ambiguous queries, request clarification before proceeding with a best-guess match
Version-specific IDs: If the user mentions a specific version, use a version-specific library ID:
# General (latest indexed)
npx ctx7@latest docs /vercel/next.js "How to set up app router"
# Version-specific
npx ctx7@latest docs /vercel/next.js/v14.3.0-canary.87 "How to set up app router"
Step 2: Query Documentation
npx ctx7@latest docs <libraryId> "<query>"
Writing good queries:
- Be specific and include relevant details
- Keep each query to one topic — if the question spans multiple distinct concepts, run a separate
docscommand per concept instead of combining them, unless the question is about how the concepts interact - Do not include any sensitive or confidential information such as API keys, passwords, credentials, personal data, or proprietary code in your query
| Quality | Example |
|---|---|
| Good | "How to set up authentication with JWT in Express.js" |
| Good | "React useEffect cleanup function with async operations" |
| Bad (too vague) | "auth" |
| Bad (too vague) | "hooks" |
| Bad (too broad) | "routing and auth and caching in Next.js" |
Describe what to look up in the library's documentation, rather than the task to complete — vague one-word queries return generic results, and multi-topic queries dilute ranking and return shallow results for each topic.
The output contains two types of content: code snippets (titled, with language-tagged blocks) and info snippets (prose explanations with breadcrumb context).
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.
Sandbox note: Run Context7 CLI requests outside the default sandbox. If a Context7 CLI command fails with DNS or network errors such as ENOTFOUND, host resolution failures, or fetch failed, rerun it outside the sandbox instead of retrying inside the sandbox.
Authentication
Works without authentication. For higher rate limits:
# Option A: environment variable
export CONTEXT7_API_KEY=your_key
# Option B: OAuth login
npx ctx7@latest login
Quick Reference
# Documentation
ctx7 library <name> <query> # Step 1: resolve library ID
ctx7 docs <libraryId> <query> # Step 2: fetch docs
# Skills
ctx7 skills install /owner/repo # Install from a repo (interactive)
ctx7 skills install /owner/repo name # Install a specific skill
ctx7 skills search <keywords> # Search the registry
ctx7 skills suggest # Auto-suggest based on project deps
ctx7 skills list # List installed skills
ctx7 skills remove <name> # Uninstall a skill
ctx7 skills generate # Generate a custom skill with AI (requires login)
# Setup
ctx7 setup # Configure Context7 MCP (interactive)
ctx7 login # Log in for higher rate limits + skill generation
ctx7 whoami # Check current login status
Error Handling
If a command fails with a quota error ("Monthly quota reached" or "quota exceeded"):
- Inform the user their Context7 quota is exhausted
- Suggest they authenticate for higher limits:
npx ctx7@latest login - 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.
Common Mistakes
- Library IDs require a
/prefix —/facebook/reactnotfacebook/react - Always run
npx ctx7@latest libraryfirst —npx ctx7@latest docs react "hooks"will fail without a valid ID - Use descriptive queries, not single words —
"React useEffect cleanup function"not"hooks" - One topic per query — split
"routing and auth and caching"into a separatedocscommand per concept, unless the question is about how they interact - Do not include sensitive information (API keys, passwords, credentials) in queries
