Documentation Lookup
Fetch current library docs and code examples via the Context7 CLI — at plan or implementation time, whenever doc accuracy matters or model knowledge may be stale.
Two steps: resolve the name to a /org/project ID, then fetch docs. Always pass a
specific query (the user's full question, not a single word) — it drives result ranking.
Never put secrets (API keys, credentials) in a query.
# 1. Resolve the library ID (skip only if the user gave an explicit /org/project[/version] ID)
npx -y ctx7 library react "How to clean up useEffect with async operations"
# 2. Fetch docs with that ID
npx -y ctx7 docs /facebook/react "How to clean up useEffect with async operations"
# version-specific ID (versions are listed in the library output):
npx -y ctx7 docs /vercel/next.js/v14.3.0-canary.87 "How to set up app router"
Pick the best match from step 1 by name/description relevance, code-snippet count, and source reputation. Max 3 attempts per question, then use the best result you have.
Critical gotchas: library IDs need the / prefix (/facebook/react, not facebook/react);
docs needs a real ID from step 1 (docs react "hooks" fails).
Rate limits: works unauthenticated; for higher limits set CONTEXT7_API_KEY (or
npx -y ctx7 login). On a quota error, tell the user why Context7 was skipped, suggest
authenticating, and if they decline, answer from training knowledge noting it may be
outdated — never fall back silently.