The ctx7 CLI is the command-line interface for Context7. It does two things:
- Fetch library documentation — resolve any library by name and query its up-to-date docs directly in your terminal, without opening a browser
- Configure your AI coding agent — set up the Context7 MCP server (or a CLI-based
docsskill) for Claude Code, Cursor, OpenCode, and more with a single command
The CLI is useful both as a standalone tool (fetching docs while you code) and as a setup utility (wiring up Context7 for your AI coding agent).
Installation#
Requires Node.js 18 or later.
Query Library Documentation#
Fetching docs is a two-step process: first resolve the library name to get its Context7 ID, then use that ID to query documentation.
Step 1 — ctx7 library#
Searches the Context7 index by name and returns matching libraries. Pass a query describing what you're trying to do — this ranks results by relevance and helps when a library name is ambiguous or shared across multiple packages.
Each result includes:
| Field | Description |
|---|---|
| Library ID | The identifier to pass to ctx7 docs (format: /org/project) |
| Code Snippets | Number of indexed code examples — higher means more documentation coverage |
| Source Reputation | Authority indicator: High, Medium, Low, or Unknown |
| Benchmark Score | Quality score from 0 to 100 |
| Versions | Version-specific IDs when available (format: /org/project/version) |
When multiple results come back, the best match is usually the one with the closest name, highest snippet count, and strongest reputation. If you need docs for a specific version, pick the matching version ID from the list.
Step 2 — ctx7 docs#
Takes a library ID and a natural-language question, and returns relevant code snippets and explanations from the indexed documentation.
Library IDs always start with /. Running ctx7 docs react "hooks" will fail — always use the
full ID returned by ctx7 library in Step 1.
Queries work best when they're specific. Describe what you're trying to accomplish rather than using single keywords — "How to set up authentication with JWT in Express.js" returns much better results than "auth".
The output contains two types of content: code snippets (titled, with language-tagged blocks) and info snippets (prose explanations with breadcrumb context). Both are formatted for readability in the terminal.
Setup#
Configure Context7 for your AI coding agent. On first run, prompts you to choose between two modes:
- MCP server — registers the Context7 MCP server in your agent's config so it can call
resolve-library-idandquery-docstools natively - CLI + Skills — installs a
docsskill that guides your agent to fetch up-to-date library docs usingctx7CLI commands (no MCP required)
ctx7 setup#
Authentication options:
Without --api-key or --oauth, setup runs the OAuth device flow: it shows a verification link and short code that you open on any device to sign in, so it works the same locally or on a remote, headless, or SSH host. MCP mode additionally generates a new API key after login. --oauth is MCP-only — use it when an IDE handles the auth flow on your behalf.
What gets written — MCP mode:
| File | Purpose |
|---|---|
.mcp.json / .cursor/mcp.json / .opencode.json | MCP server entry |
| Agent rules directory | Rule file — instructs the agent to use Context7 for library docs |
| Agent skills directory | context7-mcp skill |
What gets written — CLI + Skills mode:
| File | Purpose |
|---|---|
| Agent skills directory | docs skill — guides the agent to use ctx7 library and ctx7 docs commands |
ctx7 remove#
Remove the setup written by ctx7 setup. By default this removes both MCP setup and CLI setup for the selected agent.
If you installed the CLI itself with npm install -g ctx7, remove that separately with npm uninstall -g ctx7. If you run Context7 with npx ctx7, there is no permanent CLI install to remove.
Authentication#
Most commands work without authentication. Log in to unlock higher rate limits on documentation commands.
Commands#
API Key#
Set an API key via environment variable to skip interactive login entirely — useful for CI or scripting:
When is authentication required?#
| Feature | Required |
|---|---|
ctx7 library / ctx7 docs | No — login gives higher rate limits |
ctx7 setup | Yes — unless --api-key is passed (--oauth also skips login for MCP mode) |
Telemetry#
The CLI collects anonymous usage data to help improve the product. To disable: