| name | doc-fetcher |
| description | Fetches library documentation from Context7 and saves it to ai_docs/ in organized category-based folders. Supports version management, topic-specific documentation, and refreshing existing docs. Automatically invoked for requests to fetch or save library documentation. |
Doc Fetcher Skill
Expert skill for fetching library documentation from Context7 and organizing it in the ai_docs/ directory with proper categorization and metadata tracking.
When to Use This Skill
Use this skill when the user:
- Requests to fetch documentation for a library or framework
- Asks to save library docs for future reference
- Wants to update or refresh existing documentation
- Needs specific topic documentation (e.g., "fetch Next.js routing docs")
- Asks about downloading or storing API documentation
Trigger phrases:
- "Fetch the LangGraph documentation"
- "Get Next.js docs and save them to ai_docs"
- "Download Playwright documentation"
- "Refresh the React docs"
- "Fetch Next.js routing documentation"
- "Get the latest version of the Prisma docs"
- "/fetch-docs langgraph" (explicit slash command)
What This Skill Does
Fetches library documentation from Context7 and organizes it in ai_docs/ with:
- Category-based organization (frameworks/, ai-ml/, databases/, etc.)
- Metadata tracking (.meta.json) for version and fetch history
- Topic-specific documentation files
- Version management (latest vs specific versions)
- Automatic refresh and update capabilities
Output:
- Markdown documentation files in
ai_docs/{category}/{library}/ - Metadata tracking in
.meta.jsonfor each library - Support for multiple topics per library
- Version-specific subdirectories when needed
Core Workflow
Step 1: Resolve Library ID
Before fetching documentation, resolve the library name to a Context7-compatible library ID:
Tool: mcp__context7__resolve-library-id
Input: { "libraryName": "Next.js" }
Output: List of matching libraries with IDs like "/vercel/next.js"
Selection criteria:
- Prioritize exact name matches
- Check documentation coverage (Code Snippet count)
- Consider trust score (7-10 is authoritative)
- If ambiguous, ask user to clarify
Skip this step if:
- User provides explicit Context7 ID (e.g., "/vercel/next.js")
- Library was previously fetched (ID stored in
.meta.json)
Step 2: Determine Category
Categorize the library using references/categories.md:
Common categories:
frameworks/- Web and application frameworksai-ml/- AI, ML, and LLM librariesdatabases/- Database systems and ORMsfrontend/- Frontend libraries and toolsbackend/- Backend utilities and toolstesting/- Testing frameworksdevops/- DevOps and infrastructureutilities/- General-purpose utilities
If category unclear:
- Check
references/categories.mdfor common mappings - Use library description from Context7 to infer category
- Default to
utilities/for general-purpose libraries - Ask user if truly ambiguous
Step 3: Normalize Directory Name
Transform library name to valid directory name:
Rules:
- Lowercase everything:
Next.js->nextjs - Remove special characters:
shadcn/ui->shadcn-ui - Replace spaces with hyphens:
Material UI->material-ui - Keep hyphens from original:
date-fns->date-fns
Examples:
- "Next.js" ->
nextjs - "LangGraph" ->
langgraph - "shadcn/ui" ->
shadcn-ui - "@angular/core" ->
angular-core
Step 4: Fetch Documentation
Fetch documentation using Context7:
Tool: mcp__context7__get-library-docs
Input: {
"context7CompatibleLibraryID": "/vercel/next.js",
"tokens": 5000, // Default 5000, adjustable
"topic": "routing" // Optional, omit for general docs
}
Token guidelines:
- Default: 5000 tokens (good balance of detail and context usage)
- Large topics (e.g., "complete API reference"): 8000-10000 tokens
- Specific topics (e.g., "hooks"): 3000-5000 tokens
- Overview/getting started: 3000 tokens
Topic parameter:
- Omit for general/overview documentation
- Specify for focused documentation (e.g., "routing", "hooks", "API reference")
- Topic becomes the filename (routing.md, hooks.md, etc.)
Step 5: Create Directory Structure
Create the appropriate directory structure:
For latest version (default):
ai_docs/{category}/{library}/
For specific version:
ai_docs/{category}/{library}/{version}/
Example paths:
ai_docs/frameworks/nextjs/(latest)ai_docs/frameworks/nextjs/v14/(specific version)ai_docs/ai-ml/langgraph/(latest)
Step 6: Save Documentation
Save the fetched documentation to appropriate file:
File naming:
- General/overview:
README.md - Specific topic:
{topic-normalized}.md
Topic normalization:
- Lowercase all words
- Replace spaces with hyphens
- Remove special characters except hyphens
- Examples:
- "API Routes" ->
api-routes.md - "Server Components" ->
server-components.md - "State Graphs" ->
state-graphs.md
- "API Routes" ->
Full path examples:
ai_docs/frameworks/nextjs/README.md(general docs)ai_docs/frameworks/nextjs/routing.md(routing topic)ai_docs/ai-ml/langgraph/state-graphs.md(state graphs topic)
Step 7: Update Metadata
Create or update .meta.json in the library directory:
Structure:
{
"library_name": "Next.js",
"context7_id": "/vercel/next.js",
"category": "frameworks",
"last_updated": "2025-10-23T14:30:00Z",
"version": "latest",
"fetches": [
{
"topic": "general",
"file": "README.md",
"tokens": 5000,
"fetched_at": "2025-10-23T14:30:00Z"
}
]
}
Operations:
- New library: Create
.meta.jsonwith first fetch - Existing library, new topic: Append to
fetchesarray - Refresh existing topic: Update existing fetch entry with new timestamp
- Always update
last_updatedfield
Step 8: Report to User
Provide clear confirmation:
Success message template:
Fetched {library_name} documentation and saved to:
- Location: ai_docs/{category}/{library}/{file}
- Topic: {topic or "general overview"}
- Tokens: {token_count}
- Version: {version or "latest"}
You can now reference this documentation directly from ai_docs/.
Example:
Fetched Next.js documentation and saved to:
- Location: ai_docs/frameworks/nextjs/routing.md
- Topic: routing
- Tokens: 3500
- Version: latest
You can now reference this documentation directly from ai_docs/.
Advanced Features
Refresh Existing Documentation
When user requests refresh or update:
- Check for existing
.meta.json - Locate existing fetch entry for same topic
- Re-fetch using same Context7 ID and topic
- Overwrite existing file
- Update metadata with new timestamp
- Report what was refreshed
Example:
User: "Refresh the Next.js routing docs"
1. Load ai_docs/frameworks/nextjs/.meta.json
2. Find fetch entry with topic="routing"
3. Re-fetch from /vercel/next.js with topic="routing"
4. Overwrite ai_docs/frameworks/nextjs/routing.md
5. Update fetched_at timestamp in metadata
6. Confirm: "Refreshed Next.js routing documentation (was last updated 2 days ago)"
Version Management
When user specifies a version:
Pattern 1: User provides version explicitly
User: "Fetch Next.js v14 documentation"
1. Resolve to /vercel/next.js/v14.3.0-canary.87 (or closest match)
2. Create ai_docs/frameworks/nextjs/v14/ directory
3. Save to ai_docs/frameworks/nextjs/v14/README.md
4. Store version in .meta.json as "v14.3.0-canary.87"
Pattern 2: Latest version (default)
User: "Fetch Next.js documentation"
1. Resolve to /vercel/next.js (latest)
2. Save to ai_docs/frameworks/nextjs/README.md (no version subfolder)
3. Store version in .meta.json as "latest"
Pattern 3: Multiple versions
ai_docs/frameworks/nextjs/
README.md # Latest version
.meta.json # Latest version metadata
v14/
README.md
.meta.json # v14-specific metadata
v13/
README.md
.meta.json # v13-specific metadata
Multiple Topics
Fetch multiple topics in sequence:
User: "Fetch Next.js docs for routing, API routes, and server components"
Actions:
1. Fetch routing -> ai_docs/frameworks/nextjs/routing.md
2. Fetch API routes -> ai_docs/frameworks/nextjs/api-routes.md
3. Fetch server components -> ai_docs/frameworks/nextjs/server-components.md
4. Update .meta.json with all three fetches
5. Report all three files created
Metadata after multiple topics:
{
"library_name": "Next.js",
"context7_id": "/vercel/next.js",
"category": "frameworks",
"last_updated": "2025-10-23T15:45:00Z",
"version": "latest",
"fetches": [
{
"topic": "general",
"file": "README.md",
"tokens": 5000,
"fetched_at": "2025-10-23T14:00:00Z"
},
{
"topic": "routing",
"file": "routing.md",
"tokens": 3500,
"fetched_at": "2025-10-23T15:30:00Z"
},
{
"topic": "api routes",
"file": "api-routes.md",
"tokens": 2800,
"fetched_at": "2025-10-23T15:35:00Z"
},
{
"topic": "server components",
"file": "server-components.md",
"tokens": 4200,
"fetched_at": "2025-10-23T15:45:00Z"
}
]
}
Error Handling
Library Not Found
Symptom: Context7 resolve-library-id returns no matches
Response:
I couldn't find "{library_name}" in Context7's library database.
Possible solutions:
1. Try a different name (e.g., "React" instead of "ReactJS")
2. Check the official library name on GitHub or npm
3. The library may not be in Context7's database yet
4. Try fetching from official docs manually and I can help organize it
Would you like me to search for similar libraries?
Ambiguous Library Name
Symptom: Multiple strong matches from resolve-library-id
Response:
Found multiple matches for "{library_name}":
1. /vercel/next.js - Next.js web framework (Trust: 10, Coverage: High)
2. /another-org/next - Different library (Trust: 5, Coverage: Low)
Which one would you like to fetch? (I recommend #1 based on trust score)
Category Unclear
Symptom: Library doesn't match any category in references/categories.md
Response:
I need help categorizing "{library_name}".
Based on the description: "{library_description}"
Which category fits best?
1. frameworks/ - Web/app frameworks
2. utilities/ - General-purpose utilities
3. Other (please specify)
Fetch Failure
Symptom: get-library-docs returns error or empty content
Response:
Failed to fetch documentation for {library_name}.
Error: {error_message}
Possible causes:
1. Library ID may be incorrect
2. Context7 service may be temporarily unavailable
3. Documentation may not be available for this version
Would you like me to:
1. Try again with different parameters
2. Attempt to fetch from official docs URL instead
3. Search for alternative documentation sources
File Write Error
Symptom: Cannot create directory or write file
Response:
Error saving documentation to ai_docs/{path}
Error: {error_message}
Please check:
1. Write permissions for ai_docs/ directory
2. Available disk space
3. Path validity (Windows path length limits, special characters)
I can retry after you've checked these issues.
Usage Examples
Example 1: Simple Fetch
User: "Fetch the LangGraph documentation"
Actions:
- Resolve "LangGraph" ->
/langchain-ai/langgraph - Determine category: ai-ml (from references/categories.md)
- Normalize name:
langgraph - Fetch general docs (no topic specified, 5000 tokens)
- Create
ai_docs/ai-ml/langgraph/ - Save to
ai_docs/ai-ml/langgraph/README.md - Create
.meta.jsonwith fetch metadata
Response:
Fetched LangGraph documentation and saved to:
- Location: ai_docs/ai-ml/langgraph/README.md
- Topic: general overview
- Tokens: 5000
- Version: latest
You can now reference this documentation directly from ai_docs/.
Example 2: Topic-Specific Fetch
User: "Get Next.js routing documentation"
Actions:
- Resolve "Next.js" ->
/vercel/next.js - Category: frameworks
- Normalize:
nextjs - Fetch with topic="routing" (3500 tokens)
- Check if
ai_docs/frameworks/nextjs/exists:- If yes: Add to existing directory
- If no: Create directory
- Save to
ai_docs/frameworks/nextjs/routing.md - Update or create
.meta.json
Response:
Fetched Next.js routing documentation and saved to:
- Location: ai_docs/frameworks/nextjs/routing.md
- Topic: routing
- Tokens: 3500
- Version: latest
Added to existing Next.js documentation directory.
Example 3: Refresh Existing Docs
User: "Refresh the React documentation"
Actions:
- Check
ai_docs/frameworks/react/.meta.jsonexists - Load metadata to get Context7 ID:
/facebook/react - Re-fetch general docs (same parameters as original)
- Overwrite
ai_docs/frameworks/react/README.md - Update
last_updatedand fetch entry in metadata
Response:
Refreshed React documentation:
- Location: ai_docs/frameworks/react/README.md
- Previously updated: 5 days ago
- New fetch timestamp: 2025-10-23T16:20:00Z
- Tokens: 5000
Documentation is now up to date.
Example 4: Specific Version
User: "Fetch Next.js v14 documentation"
Actions:
- Resolve "Next.js v14" ->
/vercel/next.js/v14.3.0-canary.87 - Category: frameworks
- Normalize:
nextjs - Extract version:
v14 - Create
ai_docs/frameworks/nextjs/v14/ - Save to
ai_docs/frameworks/nextjs/v14/README.md - Create version-specific
.meta.json
Response:
Fetched Next.js v14 documentation and saved to:
- Location: ai_docs/frameworks/nextjs/v14/README.md
- Topic: general overview
- Tokens: 5000
- Version: v14.3.0-canary.87
Version-specific documentation saved to separate directory.
Example 5: Multiple Topics
User: "Fetch Playwright docs for testing, selectors, and debugging"
Actions:
- Resolve "Playwright" ->
/microsoft/playwright - Category: testing
- Normalize:
playwright - Fetch three topics in sequence:
- testing ->
testing.md - selectors ->
selectors.md - debugging ->
debugging.md
- testing ->
- Update
.meta.jsonwith all three fetches
Response:
Fetched Playwright documentation (3 topics) and saved to:
1. ai_docs/testing/playwright/testing.md
- Topic: testing
- Tokens: 4000
2. ai_docs/testing/playwright/selectors.md
- Topic: selectors
- Tokens: 3200
3. ai_docs/testing/playwright/debugging.md
- Topic: debugging
- Tokens: 3500
All topics saved. Total documentation: 3 files, 10,700 tokens.
Example 6: Slash Command
User: /fetch-docs langgraph
Actions: Same as Example 1 (simple fetch), but triggered via explicit slash command
Note: The /fetch-docs slash command provides a structured interface for this skill
Integration with Existing Documentation
Migration from Flat Structure
If ai_docs/ already exists with flat structure:
Existing structure:
ai_docs/
langgraph/
README.md
nextjs/
README.md
Migration approach:
- Detect existing libraries
- Determine categories for each
- Ask user: "I found existing docs. Should I reorganize into category structure?"
- If yes:
- Move
langgraph/->ai-ml/langgraph/ - Move
nextjs/->frameworks/nextjs/ - Create
.meta.jsonfor each with inferred metadata
- Move
- Report migration results
After migration:
ai_docs/
ai-ml/
langgraph/
README.md
.meta.json
frameworks/
nextjs/
README.md
.meta.json
Coexistence with Manual Documentation
If user has manually added documentation:
Scenario:
ai_docs/
custom-notes/
my-research.md
Approach:
- Don't modify directories that don't have
.meta.json - Create category-based structure alongside manual docs
- Inform user about mixed structure
Result:
ai_docs/
custom-notes/ # User's manual docs (untouched)
my-research.md
ai-ml/ # Skill-managed docs
langgraph/
README.md
.meta.json
Slash Command Integration
This skill can be invoked via /fetch-docs slash command (see .claude/commands/):
Usage:
/fetch-docs <library-name> [options]
Options:
--topic=<topic> # Fetch specific topic
--version=<version> # Fetch specific version
--tokens=<count> # Override default token count (5000)
--refresh # Refresh existing documentation
Examples:
/fetch-docs langgraph
/fetch-docs nextjs --topic=routing
/fetch-docs react --version=18
/fetch-docs playwright --topic=testing --tokens=8000
/fetch-docs nextjs --refresh
Slash command behavior:
- Parses arguments and invokes this skill
- Provides structured interface for common operations
- Supports batch operations (future enhancement)
Best Practices
Token Allocation
Recommended token counts by use case:
- Quick reference: 3000 tokens
- General overview: 5000 tokens (default)
- Comprehensive topic: 7000-8000 tokens
- Full API reference: 10,000+ tokens
Token efficiency:
- Fetch specific topics instead of everything
- Use topic parameter to focus documentation
- General README.md should be broad overview
- Deep-dive topics should be separate files
Category Selection
When in doubt:
- Primary use case determines category
- Libraries can belong to multiple categories in theory, but choose ONE
- Most specific category wins (e.g., Next.js is
frameworks/notfrontend/) - Consistency matters - check existing structure first
Metadata Hygiene
Always:
- Update
last_updatedtimestamp on any fetch - Append new fetches to array (don't replace)
- Preserve version information
- Include token count (helps estimate context usage)
Never:
- Delete existing fetch entries (keep history)
- Modify Context7 ID (breaking change)
- Skip metadata updates (causes sync issues)
File Organization
Do:
- Use README.md for general/overview documentation
- Create topic-specific files for focused content
- Keep version-specific docs in subdirectories
- Normalize all filenames consistently
Don't:
- Mix versions in same directory
- Create deeply nested subdirectories (max 2 levels: category/library or category/library/version)
- Use spaces or special characters in filenames
- Create generic filenames like "docs.md" or "info.md"
Performance
Target: <5 seconds for typical fetch operation
Factors affecting speed:
- Context7 API response time: 1-3 seconds
- File I/O operations: <1 second
- Metadata updates: <1 second
- Library resolution: 1-2 seconds
Optimization:
- Cache resolved library IDs in memory (avoid re-resolving)
- Batch multiple topics if possible
- Skip resolution if Context7 ID already known
Validation Checklist
Before confirming successful fetch:
- Library ID successfully resolved (or provided by user)
- Category determined (from mapping or user input)
- Directory created at correct path
- Documentation file saved with correct name
-
.meta.jsoncreated or updated - All timestamps in ISO 8601 format
- File paths use forward slashes (cross-platform compatibility)
- Success message displayed to user
Troubleshooting
Issue: Skill not auto-triggering
- Verify you're using trigger phrases like "fetch docs" or "get documentation"
- Try explicit slash command:
/fetch-docs <library> - Check
.claude/skills/doc-fetcher/SKILL.mdexists
Issue: Category not recognized
- Check
references/categories.mdfor mappings - Add custom mapping if needed
- Default to
utilities/category
Issue: Version directory already exists
- Check if refresh intended (overwrite existing)
- Confirm version number format matches
- May need to manually clean up old versions
Issue: Metadata file corrupted
- Delete
.meta.jsonand re-fetch - Skill will recreate metadata from scratch
- Original documentation files preserved
For detailed examples: See references/example-structure.md
For category mappings: See references/categories.md