CLI tool for AI agents to retrieve library documentation via the Context7 API. Written in Nim — single static binary, fast startup, disk caching.
git clone https://github.com/yourusername/context7-cli
cd context7-cli
make build-release
sudo make install # optional, installs to /usr/local/binDownload from the Releases page (Linux x86_64/arm64, macOS x86_64/arm64).
export CONTEXT7_API_KEY="your-api-key"
context7 search react
context7 doc react --query "useEffect cleanup"
context7 get /facebook/react --query "hooks best practices"| Command | Description |
|---|---|
context7 version |
Print CLI version |
context7 intro |
Show usage guide (for AI agents) |
context7 search <name> |
Search for libraries |
context7 get <id> --query <q> |
Get docs for a specific library ID |
context7 doc <name> --query <q> |
Search + fetch docs in one step |
| Flag | Env var | Description |
|---|---|---|
--api-key <key> |
CONTEXT7_API_KEY |
API key |
--cache-dir <dir> |
CONTEXT7_CACHE |
Custom cache directory |
--no-cache |
— | Skip cache |
--refresh-cache |
— | Ignore cached data, write fresh |
--verbose / -v |
— | Diagnostics to stderr |
--format <json|md|txt> |
— | Output format |
--api-keyflagCONTEXT7_API_KEYenv var~/.config/context7/config.json~/.authinfo(machine api.context7.com password <key>)~/.netrc(machine api.context7.com password <key>)
~/.config/context7/config.json (or $XDG_CONFIG_HOME/context7/config.json):
{
"api_key": "your-api-key-here",
"cache_dir": "/custom/cache/path",
"base_url": "https://custom-api.example.com",
"search_ttl": 21600,
"context_ttl": 86400
}Comments (// and /* */) are supported.
Responses are cached to disk ($CONTEXT7_CACHE > $XDG_CACHE_HOME/context7/ > ~/.cache/context7/). Search results expire after 6 hours, context results after 24 hours. Override via config file (search_ttl / context_ttl keys, in seconds) or env vars (CONTEXT7_SEARCH_TTL / CONTEXT7_CONTEXT_TTL). Env vars take priority over config file.
Requires Nim ≥ 2.0.0.
make build # debug build
make build-release # optimized + stripped
make test # run tests
make clean # remove build artifactsGNU General Public License v3.0 — see LICENSE.