iTranslated by AI
Building a Skill to Automatically Generate Library Skills from Documentation
Introduction
I'm 884js, a freelance engineer.
Suddenly, have you ever experienced something like this?
"I asked Claude Code to write code using a library, but it implemented it using an outdated API."
I try various things like feeding it the latest library documentation each time or pasting text, but it's a bit of a hassle. I wish it just knew all the development documentation.
To solve these kinds of problems, I created a skill called "lib-docs-generator" that crawls documentation URLs, automatically turns them into a skill, and ensures you can always reference the latest information.
What is a Claude Code Skill?
Skills are like plugins that extend the capabilities of Claude Code. By placing them in the .claude/skills/ directory within your project, Claude Code can automatically reference specialized knowledge in specific contexts. It's super convenient!
About lib-docs-generator
The directory structure of the skill itself looks like this:
.claude/skills/lib-docs-generator/
├── SKILL.md # The skill itself (execution flow definition)
├── references/
│ └── crawling-guide.md # Crawling technical details
└── templates/
├── llms.md # llms.md generation template
└── skill.md # SKILL.md generation template
3 Issues Resolved by lib-docs-generator
Issue 1: Outdated Knowledge
It lacks knowledge about the latest library versions or newly added APIs. In actively developed libraries, it is not uncommon for significant changes to occur within a few months.
Issue 2: Inefficiency of Manual WebFetch Every Time
You could instruct it to "look at the latest documentation" each time, but that's inefficient. Crawling multiple pages every time you ask a question takes time, and there is also the cost of determining which page to look at.
Issue 3: Inefficiency of Importing Documentation Manually
Conversely, you could "save all documentation locally," but this includes huge files in the context, consuming a massive amount of tokens. I often copy-paste parts of libraries, but that is inefficient.
Mechanism: Overview of the 4-Stage Flow
lib-docs-generator generates skills through the following 4-stage flow:
Phase 1: URL analysis → Check for llms.txt
↓
Phase 2: URL collection → Retrieve a list of URLs from sitemaps or navigation
↓
Phase 3: Lightweight crawl → Extract only "Title + Summary" from each URL
↓
Phase 4: Skill generation → Output SKILL.md and llms.md
1. llms.txt Priority Strategy
llms.txt is a documentation format formatted by site administrators for LLMs to read. Adoption is progressing on major documentation sites.
| Site | llms.txt URL |
|---|---|
| Expo | https://docs.expo.dev/llms.txt |
| Vercel | https://vercel.com/llms.txt |
| Tamagui | https://tamagui.dev/llms.txt |
lib-docs-generator first checks for the existence of this file and uses it directly if available. It is more accurate and faster than manual crawling.
2. Lightweight Crawling Method
Even if there is no llms.txt, instead of downloading the entire text, it extracts only the title and summary (the first 1-2 sentences) from each page.
# FlashList
> Fast & performant React Native list. Drop-in replacement for FlatList.
## Getting Started
- [Introduction](URL): Overview of FlashList features
- [Usage](URL): Props, hooks, and methods for implementing FlashList
## Core Concepts
- [Recycling](URL): How FlashList recycles components
- [Performance](URL): Profiling in release mode, memoization tips
By saving it in this format of "Table of Contents + Summary of each page," you can save both storage and tokens.
3. On-Demand WebFetch Method
The generated skill uses WebFetch to acquire the necessary documentation pages at runtime.
I decided to keep only the "Table of Contents" locally so that even if the documentation is updated, the system can go and reference the latest information using WebFetch.
When the skill is triggered:
1. Read references/llms.md (Table of Contents)
2. Identify URLs relevant to the question
3. Retrieve details of the corresponding page via WebFetch
4. Generate a response
Actual Use Case
Let's take a look at an example of generating a documentation skill for FlashList, which I often use when developing with React Native.
Command Execution
/lib-docs-generator https://shopify.github.io/flash-list flash-list
Generated File Structure
.claude/skills/shopify-flash-list/
├── SKILL.md # Skill definition
└── references/
└── llms.md # Documentation table of contents
Generated SKILL.md
---
name: shopify-flash-list
description: |
Provides documentation for FlashList, the fastest React Native list component by Shopify.
Use when working with code that imports "@shopify/flash-list", "FlashList", "useRecyclingState", "useBenchmark", "MasonryFlashList", or "useBlankAreaTracker".
Use when the user asks about fast lists, performant lists, FlatList alternatives, or shows code with FlashList imports.
Can also be invoked directly with "FlashList", "flash-list", "Shopify list".
---
By including import patterns and related keywords in the description, Claude Code will trigger the skill at the appropriate time.
Generated llms.md
# FlashList
> Fast & performant React Native list. Drop-in replacement for FlatList.
## Getting Started
- [Introduction](https://shopify.github.io/flash-list/docs/): Overview of FlashList features
- [Usage](https://shopify.github.io/flash-list/docs/usage): Props, hooks, and methods
## Core Concepts
- [Recycling](https://shopify.github.io/flash-list/docs/recycling): How FlashList recycles components
- [Performance](https://shopify.github.io/flash-list/docs/fundamentals/performance): Profiling and optimization tips
## Guides
- [Masonry Layout](https://shopify.github.io/flash-list/docs/guides/masonry): Creating grids with varying heights
- [Testing with Jest](https://shopify.github.io/flash-list/docs/testing): Mocking FlashList for tests
...
Behavior When Using the Skill
Once the skill is generated, it will automatically trigger when you ask questions or reference code related to FlashList.
User: I want to implement a Masonry layout with FlashList
Claude Code:
1. The shopify-flash-list skill is automatically triggered
2. Identify Masonry-related URLs from references/llms.md
3. Retrieve https://shopify.github.io/flash-list/docs/guides/masonry via WebFetch
4. Present code examples based on the latest v2 API
Summary
Thank you for reading this far!
I used to manually paste documentation sites, but I feel like this skill has significantly reduced that effort.
Enjoy your AI coding life!
Discussion