Claude Code Plugin Implementation
Relevant source files
The following files were used as context for generating this wiki page:
The claude-code-docs repository serves as an unofficial mirror of the official Claude Code documentation, designed to enhance the capabilities of AI coding agents. It provides a structured environment where documentation is synced every 6 hours from code.claude.com/docs, allowing agents to access local, version-pinned markdown files rather than processing raw HTML.
The implementation functions as both a data mirror and a Claude Code plugin. As a plugin, it utilizes PreToolUse hooks to intercept WebFetch calls, ensuring that when an agent attempts to access a documentation URL, it receives clean markdown content. Additionally, it provides a specialized "Skill" for semantic searching and question answering based on the mirrored documentation.
Sources: README.md:1-12, skills/claude-code-docs/SKILL.md:1-5
Core Architecture and Data Synchronization
The system architecture revolves around maintaining a local file-based mirror of the documentation. The synchronization process treats the remote llms.txt file as the source of truth for the manifest of available pages.
Synchronization Logic
The sync.ts script performs the following steps:
- Fetches the remote
llms.txtmanifest. - Identifies all
.mdURLs listed within the manifest. - Downloads each page (with a concurrency of 10 and 3 retries).
- Rewrites internal site-absolute links to relative markdown links so that the documentation remains navigable when viewed locally or on platforms like GitHub.
Sources: sync.ts:1-10, sync.ts:60-90, README.md:14-19
The diagram above illustrates the data flow from the canonical documentation source to the local mirror directory.
Sources: sync.ts:12-40, sync.ts:60-95
Claude Code Plugin Hooks
The plugin implementation utilizes a PreToolUse hook specifically for the WebFetch tool. This mechanism intercepts requests to code.claude.com/docs and redirects them to the .md source variant.
Hook Configuration
The hook is registered via hooks/hooks.json. It targets the WebFetch tool and executes a bash script to handle the URL transformation logic.
| Configuration Field | Value | Description |
|---|---|---|
matcher | WebFetch | Targets the tool used for fetching web content. |
type | command | Specifies the hook executes an external command. |
command | bash ${CLAUDE_PLUGIN_ROOT}/hooks/rewrite-docs-url.sh | The script performing the URL rewrite. |
timeout | 5 | Execution timeout in seconds. |
Sources: hooks/hooks.json:4-16
URL Rewriting Logic
The rewrite-docs-url.sh script filters URLs to ensure only specific documentation pages are rewritten. It strips URL fragments and query parameters, then appends .md to the path if it is a valid page under a locale segment (e.g., /docs/en/).
Plugin Skill Implementation
The plugin exposes a skill named claude-code-docs which provides a structured method for agents to answer questions about Claude Code.
Skill Workflow
The skill follows a multi-step resolution process:
- Resolve Mirror: Locates the cached checkout of the docs mirror using the
askCLI ornpx -y @pleaseai/ask. - Search: Performs semantic search using
csp(Code Search Please) or falls back togrepover the local markdown files. - Read and Answer: Reads the top matches and generates an answer, citing canonical URLs (e.g., mapping
docs/hooks.mdback tohttps://code.claude.com/docs/en/hooks). - Fallback: If local tools are unavailable, it fetches the online
llms.txtand usesWebFetchon individual page URLs.
Sources: skills/claude-code-docs/SKILL.md:11-53, README.md:59-69
Semantic Search Integration
The skill leverages the csp tool for token-efficient searching. This allows the agent to find relevant information without loading the entire 5MB documentation bundle into the context window.
Conclusion
The Claude Code Plugin Implementation provides a robust bridge between the official documentation and AI coding agents. By combining a frequently synced local mirror with a URL-rewriting hook and a semantic search skill, it ensures that agents can access high-quality, clean markdown documentation efficiently. This architecture reduces context window bloat while maintaining high accuracy through grounded search and canonical citations.
Sources: README.md:70-74, skills/claude-code-docs/SKILL.md:41-48