Command Reference
Command-Line Usage
The contextmd CLI is designed to be simple yet powerful. It follows a standard command structure:
contextmd <url> [options]
Arguments
| Argument | Description |
| :--- | :--- |
| <url> | Required. The base URL of the documentation site you wish to crawl. The crawler will stay within this domain and protocol. |
Options
--key, -k <key>
The OpenAI API key used to refine and optimize the documentation for AI agents.
- Type:
string - Default: Uses the
OPENAI_API_KEYenvironment variable if not provided.
--output, -o <path>
Specifies the filename and location of the generated context file.
- Type:
string(path) - Default:
context.md
--limit, -l <number>
The maximum number of pages the crawler should visit before stopping. This is useful for large documentation sites to prevent excessive API usage or extremely large output files.
- Type:
number - Default:
100
--help, -h
Displays the help information and a list of all available commands and options.
Environment Variables
To avoid passing your API key in every command, you can use an environment variable. contextmd supports loading these from a .env file in your current working directory.
| Variable | Description |
| :--- | :--- |
| OPENAI_API_KEY | Your OpenAI API key. Required for the AI-powered refinement stage. |
Examples
Basic Extraction
Crawl a site using default settings and an environment variable for the API key.
contextmd https://docs.example.com
Custom Output and Limits
Crawl a specific documentation path, limiting the process to the first 20 pages and saving to a custom directory.
contextmd https://react.dev/reference/react -l 20 -o ./ai-context/react-hooks.md
Providing API Key Inline
If you haven't set an environment variable, you can provide your key directly via the flag.
contextmd https://docs.nestjs.com --key sk-proj-your-api-key-here
How it Works
When you run a command, contextmd performs the following sequence:
- Crawl: It traverses the provided URL, identifying all internal links within the same domain.
- Clean: It strips away non-essential HTML elements like navigation bars, footers, scripts, and sidebars to isolate the core documentation.
- Convert: It transforms the cleaned HTML into standard Markdown.
- Refine: It sends the Markdown to OpenAI's
gpt-4o-minimodel to remove conversational fluff and optimize the structure for LLM comprehension. - Consolidate: All processed pages are appended into a single file with source attribution headers.