Skip to main content
The ctx7 CLI is the command-line interface for Context7. It does two things:
  • Fetch library documentation — search all libraries with one question, or 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 find-docs skill) 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 22.13 or later.
Run ctx7 directly without installing anything. Useful for one-off commands or trying it out.

Search Documentation

Takes a natural-language question and returns relevant code snippets and explanations in one step. Context7 picks the libraries for you, so no library ID is needed.
If you know the library, version, or language, add them to narrow the results:

Query Library Documentation

To query one library directly, 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: 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, pass the version your project uses with --tag, as written in your package file (15.4.3, ^15.4.3, 14). Context7 serves that version or the closest one it has.

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.

On-premise deployments

ctx7 library and ctx7 docs also query an on-premise deployment. Set the deployment’s root URL in CONTEXT7_BASE_URL once, or pass --base-url on each command. When MCP authentication is enabled on the deployment, set CONTEXT7_API_KEY to a personal API key from the dashboard:
--base-url wins when both are set. A custom deployment authenticates with CONTEXT7_API_KEY only: the CLI does not send your ctx7 login session to it. ctx7 search, ctx7 code and ctx7 get-upgrade-guide are available only on hosted Context7.
CONTEXT7_BASE_URL is the deployment’s root URL, without /api. The MCP server reads a different variable, CONTEXT7_API_URL, which ends in /api.

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-id and query-docs tools natively
  • CLI + Skills — installs a find-docs skill that guides your agent to fetch up-to-date library docs using ctx7 CLI 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. The device flow returns an API key that setup uses for authentication. --oauth is MCP-only — use it when an IDE handles the auth flow on your behalf. If your teamspace’s API key policy refuses you a key (OAuth only, or keys for owners and admins only), MCP setup continues with OAuth instead, as with --oauth. This includes a key saved by an earlier login: setup checks it first, and signs you in again when the key is no longer valid. With --stdio it stops with an error, because the stdio server needs an API key.

On-premise setup

Pass the root URL of your on-premise deployment with --base-url, or set it once in CONTEXT7_BASE_URL. Do not include /mcp or /api:
The CLI checks /api/auth/mcp before writing configuration. It configures anonymous access, writes Authorization: Bearer <personal-key>, or, when the deployment uses OAuth sign-in, writes no key so the client signs in through the browser. When the deployment needs a personal key and no key was provided, interactive setup requests the key with masked input. Use --api-key or CONTEXT7_API_KEY for non-interactive automation. On-premise setup uses Streamable HTTP and bundled rule/skill content. When --base-url targets a custom deployment, setup skips the npm update check and telemetry and does not fetch rules or skills from GitHub or Context7 Cloud. After the CLI package is installed, the only network request made by setup is to the configured deployment. In a restricted environment, mirror ctx7 and its dependencies in an internal npm registry and run the installed ctx7 binary instead of npx ctx7@latest. For a custom deployment, ctx7 setup supports MCP setup only. It cannot be combined with --stdio or --cli. --oauth works when the deployment offers OAuth sign-in. What gets written — MCP mode: The rule file is the contents of rules/context7-mcp.md and the skill is skills/context7-mcp/SKILL.md. For Claude Code, ctx7 setup --claude writes the files below. With --project, the rule and skill go to .claude/rules/ and .claude/skills/ in the project instead; CLAUDE_CONFIG_DIR replaces ~/.claude when it is set. What gets written — CLI + Skills mode: The rule file is the contents of rules/context7-cli.md and the skill is skills/find-docs/SKILL.md. For Claude Code, ctx7 setup --cli --claude writes ~/.claude/skills/find-docs/SKILL.md and ~/.claude/rules/context7.md (.claude/ in the project with --project).

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

Session expiry

If your saved login can no longer be refreshed, the CLI clears it and asks whether to sign in again. Answering yes runs ctx7 login and continues the command with the new login. Answering no continues without an account. No prompt is shown when output is piped or --json is passed — the CLI prints a notice to stderr and continues without an account, so parsed output stays clean. ctx7 login, ctx7 whoami, and ctx7 setup also skip the prompt. Network, rate-limit, and server errors keep your saved login, so the next command retries.

API Key

Set an API key via environment variable to skip interactive login entirely — useful for CI or scripting:

When is authentication required?


Telemetry

The CLI collects anonymous usage data to help improve the product. To disable:
Against hosted Context7, the CLI sends anonymous usage events to context7.com and checks the npm registry (registry.npmjs.org) for a newer ctx7 version. The update check is cached for 24 hours, so it runs at most once a day, and is skipped for --json, -v/--version and --base-url. CTX7_TELEMETRY_DISABLED stops the events, not the update check. A custom --base-url deployment turns off both.

Next Steps

Claude Code

Set up Context7 in Claude Code

All Clients

Installation for every supported editor