
Context7 CLI (ctx7)
CLIUpstash 官方的 Context7 命令行(ctx7):在终端检索库并拉取最新版本的文档,也能一键为 Claude Code、Cursor 等 agent 配置 Context7 MCP 与规则。查询文档无需登录,登录后调用额度更高。
ctx7
CLI for Context7 - query up-to-date library documentation and configure Context7 for AI coding agents.
Installation
# Run directly with npx (no install needed)
npx ctx7
# Or install globally
npm install -g ctx7
Quick Start
# Set up Context7 MCP for your coding agents
ctx7 setup
# Remove Context7 setup later
ctx7 remove
# Target a specific agent
ctx7 setup --cursor
ctx7 setup --claude
ctx7 setup --opencode
ctx7 setup --vscode
ctx7 setup --devin
ctx7 setup --copilot
Library Documentation
# Find a library
ctx7 library react
ctx7 library nextjs "app router"
# Get documentation
ctx7 docs /facebook/react "useEffect cleanup"
ctx7 docs /vercel/next.js "proxy"
Usage
Find a library
Resolve a library name to a Context7 library ID.
ctx7 library react
ctx7 library nextjs "app router setup"
ctx7 library prisma "database relations"
# Output as JSON
ctx7 library react --json
Query documentation
Fetch documentation for a specific library using its Context7 ID.
ctx7 docs /facebook/react "useEffect cleanup"
ctx7 docs /vercel/next.js "proxy authentication"
ctx7 docs /prisma/prisma "one-to-many relations"
# Output as JSON
ctx7 docs /facebook/react "hooks" --json
Setup
Configure Context7 MCP and a rule for your AI coding agents. Authenticates via OAuth, generates an API key, and writes the config.
# Interactive (prompts for agent selection)
ctx7 setup
# Target specific agents
ctx7 setup --cursor
ctx7 setup --claude
ctx7 setup --opencode
ctx7 setup --vscode
ctx7 setup --devin
ctx7 setup --copilot
# Use an existing API key instead of OAuth
ctx7 setup --api-key YOUR_API_KEY
# Use OAuth endpoint (IDE handles auth flow)
ctx7 setup --oauth
# Configure an on-premise deployment (pass the deployment root)
ctx7 setup --mcp --base-url https://context7.internal.example --codex
# When on-premise MCP auth is enabled, the CLI prompts for the key with hidden input
ctx7 setup --mcp \
--base-url https://context7.internal.example \
--codex
# For non-interactive automation, provide the key through the environment
CONTEXT7_API_KEY=ctx7op-... ctx7 setup --mcp --yes \
--base-url https://context7.internal.example \
--codex
# Configure for current project only (default is global)
ctx7 setup --project
# Skip prompts
ctx7 setup --yes
For a custom --base-url, setup discovers whether MCP authentication is enabled and writes either an anonymous HTTP entry or an Authorization: Bearer header. Interactive setup requests the personal key with masked input, keeping it out of shell history; --api-key and CONTEXT7_API_KEY remain available for automation. Setup uses bundled rule and skill content and skips the npm update check and telemetry, so after ctx7 is installed it contacts only the configured deployment. Enterprise environments can mirror ctx7 and its dependencies in an internal npm registry. Custom deployments support MCP HTTP setup; hosted OAuth, stdio, and CLI-query mode are not supported for on-premise targets.
Uninstall setup
Remove the Context7 setup written by ctx7 setup. By default this removes both MCP setup and CLI setup for the selected agent.
# Interactive
ctx7 remove
# Target specific agents
ctx7 remove --cursor
ctx7 remove --claude --project
ctx7 remove --vscode --project
ctx7 remove --devin --project
ctx7 remove --copilot --project
# Remove both setup modes explicitly
ctx7 remove --cursor --all
# Remove only one setup mode
ctx7 remove --cursor --cli
ctx7 remove --claude --mcp
If you installed the CLI itself globally with npm install -g ctx7, remove that separately with npm uninstall -g ctx7. If you use npx ctx7, there is no permanent CLI install to remove.
Authentication
Log in to access authenticated setup and higher documentation rate limits.
# Log in (opens browser for OAuth)
ctx7 login
# Check login status
ctx7 whoami
# Log out
ctx7 logout
Supported Clients
The CLI automatically detects which AI coding agents you have installed and configures Context7 for them:
| Client | Skills Directory |
|---|---|
| Universal (Amp, Codex, Gemini CLI, GitHub Copilot, OpenCode + more) | .agents/skills/ |
| Claude Code | .claude/skills/ |
| Cursor | .cursor/skills/ |
| VS Code | .agents/skills/ |
| Devin | .devin/skills/ |
| GitHub Copilot CLI | .agents/skills/ |
| Antigravity | .agent/skills/ |
Disabling Telemetry
The CLI collects anonymous usage data to help improve the product. To disable telemetry, set the CTX7_TELEMETRY_DISABLED environment variable:
# For a single command
CTX7_TELEMETRY_DISABLED=1 ctx7 docs /facebook/react "useEffect examples"
# Or export in your shell profile (~/.bashrc, ~/.zshrc, etc.)
export CTX7_TELEMETRY_DISABLED=1
Learn More
Visit context7.com for documentation lookup and setup guides.
相关资源

Context7
Plugin接入 Upstash 托管的 Context7 远程 MCP,按需拉取各类库指定版本的最新文档与代码示例,减少过时与臆造的 API;无需本地 Node,匿名即可使用,配置 API Key 可提高限额。Upstash 维护。
anthropics/claude-plugins-official40.4k
Context7
MCP把各类库与框架的最新版本文档和代码示例注入 agent 上下文,减少使用过时或臆造的 API。Upstash 出品,匿名可用,免费申请 API Key 可提高限额。
upstash/context763.1k
Serena
MCP借助语言服务器(LSP)为编码 agent 提供类 IDE 的符号级代码检索、编辑与重构工具,支持 40 多种语言,并带跨会话记忆;可选付费的 JetBrains 插件作后端(额外支持断点调试)。需先用 uv 安装。
oraios/serena30.3k
RTK (Rust Token Killer)
CLI在命令输出进入 agent 上下文之前做过滤和压缩的 Rust 命令行代理,覆盖 git、测试、grep、ls 等上百种命令,最多可减少约 90% 的 bash 输出;通过钩子自动改写 Claude Code、Codex 等 agent 执行的命令。
rtk-ai/rtk83.6k
Repomix
CLI把整个代码仓库打包成单个 AI 友好的文件(XML、Markdown、JSON 或纯文本),附每个文件的 token 统计,自动排除含密钥的文件,可用 Tree-sitter 压缩代码或直接打包远程 GitHub 仓库。
yamadashy/repomix28.9k
Crush
CLICharm 出品的终端编码 Agent,可在会话中途切换模型并保留上下文,按项目管理多个会话,借助 LSP 获取代码上下文,支持 MCP 扩展与兼容 OpenAI / Anthropic 协议的 API。
charmbracelet/crush28.7k