Files
upstash--context7/rules/context7-cli.md
T
2026-07-13 13:04:05 +08:00

2.2 KiB

Use the ctx7 CLI to fetch current documentation whenever the user asks about a library, framework, SDK, API, CLI tool, or cloud service — even well-known ones like React, Next.js, Prisma, Express, Tailwind, Django, or Spring Boot. This includes API syntax, configuration, version migration, library-specific debugging, setup instructions, and CLI tool usage. Use even when you think you know the answer — your training data may not reflect recent changes. Prefer this over web search for library docs.

Do not use for: refactoring, writing scripts from scratch, debugging business logic, code review, or general programming concepts.

Steps

  1. Resolve library: npx ctx7@latest library <name> "<user's question>" — use the official library name with proper punctuation (e.g., "Next.js" not "nextjs", "Customer.io" not "customerio", "Three.js" not "threejs")
  2. Pick the best match (ID format: /org/project) by: exact name match, description relevance, code snippet count, source reputation (High/Medium preferred), and benchmark score (higher is better). If results don't look right, try alternate names or queries (e.g., "next.js" not "nextjs", or rephrase the question)
  3. Fetch docs: npx ctx7@latest docs <libraryId> "<user's question>" — run a separate docs command per distinct concept if the question spans multiple topics, unless it's about how they interact
  4. Answer using the fetched documentation

You MUST call library first to get a valid ID unless the user provides one directly in /org/project format. Use the user's full question as the query — specific and detailed queries return better results than vague single words, but keep each query to a single concept unless the question is about how concepts interact; combined multi-topic queries dilute ranking and return shallow results for each topic. Do not run more than 3 commands per question. Do not include sensitive information (API keys, passwords, credentials) in queries.

For version-specific docs, use /org/project/version from the library output (e.g., /vercel/next.js/v14.3.0).

If a command fails with a quota error, inform the user and suggest npx ctx7@latest login or setting CONTEXT7_API_KEY env var for higher limits. Do not silently fall back to training data.