Claude Code skill for up-to-date library documentation via Context7 API
Retrieve current, version-specific documentation for libraries and frameworks using the Context7 API.
The following environment variables are automatically provided by the agent sandbox:
CONTEXT7_API_KEY - Context7 API key (optional - unauthenticated access works but has lower rate limits)Get a free API key at: https://context7.com/dashboard
Use whenever you need library or framework documentation:
Priority: Use Context7 BEFORE web search for library documentation to ensure version-specific accuracy.
Search for available libraries by name. Use this to find the correct library ID before fetching documentation.
Endpoint: GET https://context7.com/api/v2/libs/search
Query Parameters:
query (required) - Your question or task (used for relevance ranking)libraryName (required) - Library name to search for (e.g., "react", "nextjs", "django")Example:
# Search for React library
curl "https://context7.com/api/v2/libs/search?libraryName=react&query=hooks" \
-H "Authorization: Bearer ${CONTEXT7_API_KEY}"
# Unauthenticated (lower rate limits)
curl "https://context7.com/api/v2/libs/search?libraryName=react&query=hooks"
Response:
{
"results": [
{
"id": "/facebook/react",
"title": "React",
"description": "A JavaScript library for building user interfaces",
"totalSnippets": 1250,
"trustScore": 95,
"benchmarkScore": 88,
"versions": ["v18.2.0", "v17.0.2"]
}
]
}
IMPORTANT: The response is an object with a results array, NOT a plain array. Always access .results first (e.g., data["results"][0] in Python, .results[0] in jq).
Tips:
id field from the response for the next stepversions array to see available versionsRetrieve documentation context for a specific library. Returns relevant documentation snippets based on your query.
Endpoint: GET https://context7.com/api/v2/context
Query Parameters:
query (required) - Your question or task (used for relevance ranking)libraryId (required) - Library identifier from search (e.g., /facebook/react)type (optional) - Response format: json (default) or txtExample:
# Get React useEffect documentation (JSON format)
curl "https://context7.com/api/v2/context?libraryId=/facebook/react&query=useEffect" \
-H "Authorization: Bearer ${CONTEXT7_API_KEY}"
# Get documentation in text format (better for LLM prompts)
curl "https://context7.com/api/v2/context?libraryId=/facebook/react&query=useEffect&type=txt" \
-H "Authorization: Bearer ${CONTEXT7_API_KEY}"
# Unauthenticated (lower rate limits)
curl "https://context7.com/api/v2/context?libraryId=/facebook/react&query=useEffect&type=txt"
Response (JSON format):
[
{
"title": "Using the Effect Hook",
"content": "The Effect Hook lets you perform side effects...",
"source": "react.dev/reference/react/useEffect"
}
]
Response (Text format): Returns plain text ready for LLM prompts.
Tips:
type=txt for cleaner output that's easier to parse/vercel/next.js/v15.1.8# Step 1: Search for the library
LIBRARY_SEARCH=$(curl -s "https://context7.com/api/v2/libs/search?libraryName=react&query=state%20management" \
-H "Authorization: Bearer ${CONTEXT7_API_KEY}")
# Extract library ID (first result - response has a "results" array wrapper)
LIBRARY_ID=$(echo "$LIBRARY_SEARCH" | jq -r '.results[0].id')
echo "Found library: $LIBRARY_ID"
# Step 2: Get documentation context
DOCS=$(curl -s "https://context7.com/api/v2/context?libraryId=$LIBRARY_ID&query=How%20do%20I%20use%20useState&type=txt" \
-H "Authorization: Bearer ${CONTEXT7_API_KEY}")
echo "$DOCS"
The Context7 API uses standard HTTP status codes:
| Code | Description | Action |
|---|---|---|
| 200 | Success | Process the response normally |
| 202 | Accepted - Library not finalized | Wait and retry later |
| 400 | Bad Request - Invalid parameters | Check query parameters |
| 401 | Unauthorized - Invalid API key | Check CONTEXT7_API_KEY format |
| 404 | Not Found - Library doesn't exist | Verify the library ID |
| 429 | Too Many Requests - Rate limit exceeded | Wait and retry with backoff |
| 500 | Internal Server Error | Retry with backoff |
Rate Limits:
&type=txt for cleaner output that's easier to parse/library-name/vX.Y.Z for consistent results# Research Django REST Framework authentication
LIBRARY_ID=$(curl -s "https://context7.com/api/v2/libs/search?libraryName=django-rest-framework&query=authentication" \
-H "Authorization: Bearer ${CONTEXT7_API_KEY}" | jq -r '.results[0].id')
curl -s "https://context7.com/api/v2/context?libraryId=$LIBRARY_ID&query=token%20authentication&type=txt" \
-H "Authorization: Bearer ${CONTEXT7_API_KEY}"
# Verify Next.js 15 App Router API
curl -s "https://context7.com/api/v2/context?libraryId=/vercel/next.js/v15.1.8&query=app%20router%20layout&type=txt" \
-H "Authorization: Bearer ${CONTEXT7_API_KEY}"
# Answer "How do I use React hooks?"
LIBRARY_ID="/facebook/react"
curl -s "https://context7.com/api/v2/context?libraryId=$LIBRARY_ID&query=hooks%20usage&type=txt" \
-H "Authorization: Bearer ${CONTEXT7_API_KEY}"