Skip to main content

Overview

Follow these best practices to maximize the value of Context7 in your AI-powered development workflow.

Use Rules for Automatic Invocation

Instead of typing use context7 in every prompt, set up a rule to automatically invoke Context7 for code-related questions.
This is the single most impactful change you can make to improve your Context7 experience.
Add a rule to your AI coding assistant:
  • Cursor: Cursor Settings > Rules
  • Claude Code: Create a CLAUDE.md file
  • Other clients: Check your client’s documentation for rule configuration
Example rule:
Always use Context7 MCP when I need library/API documentation, code generation, setup or configuration steps without me having to explicitly ask.
See the Using Rules guide for detailed setup instructions.

Specify Library IDs for Faster Results

If you know exactly which library you want to use, include its Context7 ID in your prompt. This allows Context7 to skip the library-matching step and directly retrieve documentation.
Implement basic authentication with Supabase. use context7
Benefits:
  • Faster response times
  • More accurate documentation retrieval
  • No ambiguity when multiple libraries have similar names

Finding Library IDs

Library IDs follow the format /owner/repository. You can find them by:
  1. Searching on context7.com
  2. Using the resolve-library-id MCP tool
  3. Checking the library’s GitHub repository URL
Library IDs are case-sensitive and must include the leading slash.

Request Specific Versions

For version-specific documentation, mention the version in your prompt:
How do I set up Next.js 14 middleware? use context7
Context7 will automatically match the appropriate version documentation.
See the Specifying Versions guide for more details on version syntax.

Write Clear, Specific Prompts

The quality of Context7’s responses depends on your prompt clarity.

Good Prompts

Create a Next.js middleware that checks for a valid JWT in cookies
and redirects unauthenticated users to `/login`. use context7
Why it’s good: Clearly states the technology (Next.js), the specific task (middleware with JWT validation), and the desired behavior.
Configure a Cloudflare Worker script to cache JSON API
responses for five minutes. use context7
Why it’s good: Identifies the platform (Cloudflare Workers), the action (caching), and specific requirements (JSON, 5 minutes).
How do I implement real-time subscriptions with Supabase v2? use context7
Why it’s good: Specifies the library, feature, and version.

Prompts to Avoid

How do I use React? use context7
Problem: Too broad. Specify what you want to do with React (hooks, components, routing, etc.).
Fix this authentication bug. use context7
Problem: No indication of which library or framework you’re using.
How do I set up MongoDB and also create a React app and deploy to Vercel? use context7
Problem: Too many topics at once. Break into separate prompts for better results.

Use the Right API Key

While Context7 works without an API key, you’ll get significantly better performance with one.

Without API Key

  • Lower rate limits
  • Slower responses
  • No usage analytics

With API Key

  • Higher rate limits
  • Faster responses
  • Usage tracking
  • Priority support
Get a free API key at context7.com/dashboard

SDK Best Practices

If you’re building with the Context7 SDK:

Use Environment Variables

Store your API key in environment variables:
.env
CONTEXT7_API_KEY=ctx7sk-...
import { Context7 } from "@upstash/context7-sdk";

const client = new Context7();
// API key is automatically loaded from CONTEXT7_API_KEY env var

Choose the Right Response Type

// For structured processing (default)
const docs = await client.getContext(
  "How do I use hooks?",
  "/facebook/react"
);
// Returns: Array of { title, content, url }

// For direct LLM consumption
const context = await client.getContext(
  "How do I use hooks?",
  "/facebook/react",
  { type: "txt" }
);
// Returns: Plain text string ready for prompt injection

Search Before Querying

Always search for the library first to get the correct ID:
// 1. Search for the library
const libraries = await client.searchLibrary(
  "I need to build a UI with components",
  "react"
);

// 2. Use the library ID to get documentation
const docs = await client.getContext(
  "How do I use hooks?",
  libraries[0].id
);

Performance Tips

Cache Results When Possible

If you’re building an application with the SDK, cache documentation results to reduce API calls:
const cache = new Map();

async function getCachedContext(query: string, libraryId: string) {
  const key = `${libraryId}:${query}`;
  
  if (cache.has(key)) {
    return cache.get(key);
  }
  
  const result = await client.getContext(query, libraryId);
  cache.set(key, result);
  return result;
}
If you need documentation for multiple related topics, make separate focused queries rather than one broad query:
// Good: Focused queries
const authDocs = await client.getContext(
  "How do I implement authentication?",
  "/supabase/supabase"
);

const storageDocs = await client.getContext(
  "How do I upload files to storage?",
  "/supabase/supabase"
);

// Less ideal: One broad query
const docs = await client.getContext(
  "How do I use authentication and storage?",
  "/supabase/supabase"
);

Stay Updated

Context7 regularly adds new libraries and improves existing documentation.
If you don’t see your library on Context7, you can submit it to the registry.

Build docs developers (and LLMs) love