Skip to content

ethan-huo/ctx

Repository files navigation

ctx

Context acquisition for AI agents: find curated library docs, search the open web, and read complete original sources.

ctx library docs react "useEffect cleanup"     # find doc sources via Context7 index
ctx web search "OpenAI latest model pricing" --type news
ctx read <url>                                  # read full document as clean markdown
ctx web crawl start <docs-site> --limit 20      # start a reusable crawl job

The Problem

AI coding agents need documentation, but current tools make trade-offs:

  • RAG-based tools (ctx7, etc.) return 60-200 token fragments — too small for real understanding
  • Full-doc tools (ref, etc.) return complete pages but search accuracy is inconsistent

ctx combines curated Context7 library discovery with open-web EXA search, then fetches the full originals via GitHub API, HTTP content negotiation, or headless browser rendering.

Install

curl -fsSL https://raw.githubusercontent.com/ethan-huo/ctx/main/install.sh | sh

The installer downloads the latest GitHub Release binary for your platform, verifies the checksum, and overwrites the existing ctx binary. Supported release targets:

  • macOS ARM64
  • Linux ARM64
  • Linux AMD64

Install a specific release:

curl -fsSL https://raw.githubusercontent.com/ethan-huo/ctx/main/install.sh | sh -s -- --version v0.1.0

Install somewhere other than ~/.local/bin:

curl -fsSL https://raw.githubusercontent.com/ethan-huo/ctx/main/install.sh | sh -s -- --dir /usr/local/bin
Build from source
make build    # compile to bin/ctx
make install  # build + symlink to ~/.local/bin/ctx

Requires Go 1.25+.

Workflow

1. Choose source → Read

ctx library search mlx-swift "GPU stream thread safety"  # optional: discover IDs
ctx library docs mlx-swift "GPU stream thread safety"    # curated docs source map
ctx web search "GPU stream thread safety mlx swift" --type code
ctx read <url>                                             # read as clean markdown

Long documents (>2000 lines) automatically produce a structural summary with numbered sections:

ctx read <url>             # returns summary with section numbers
ctx read <url> -s 2.1      # read specific section
ctx read <url> -s "1-3,5"  # combine sections
ctx read <url> --toc       # compact heading outline

2. Browser Superpowers

When plain HTTP isn't enough, ctx uses Cloudflare Browser Rendering for full JS-rendered pages:

Need Command
Read a JS-rendered SPA ctx read <url>
Extract specific DOM elements ctx web scrape <url> -s "table.api-params"
Pull multiple pages from a docs site ctx web crawl start <url> --limit 50 --depth 2 -> ctx web crawl export <job-id>
Screenshot a page ctx web screenshot <url> --full-page
Explore a site's link structure ctx web links <url> --internal-only
Extract structured data with AI ctx web json <url> --prompt "Extract pricing tiers"

All commands support -d for full API control (cookies, viewport, JS injection, etc.):

{
  url: "https://example.com",
  cookies: "session=abc",
  viewport: {width: 1920, height: 1080},
  addScriptTag: [{content: "document.querySelector('.nav')?.remove()"}]
}

3. Per-Domain Auth

Store headers that auto-inject into all requests for a domain:

ctx site set example.com Cookie "session=abc"
ctx site set example.com Authorization "Bearer token123"
ctx site ls

How read Resolves URLs

URL Pattern Strategy
/path, ./path, file:///path Direct file read
github://owner/repo@ref/path GitHub Contents API
https://github.com/.../blob/... Auto-converted to GitHub API
https://github.com/.../tree/<ref>/<path> GitHub directory listing via Contents API
https://github.com/owner/repo Auto-resolved to repository README
https://github.com/owner/repo/issues/123 Auto-resolved to issue title/body/comments
Any https:// (text/plain/markdown/JSON/XML) Direct fetch
Any https:// (HTML/SPA) Cloudflare Browser Rendering fallback

Issue reads auto-expand comments until a line budget is reached, then append a continuation hint like ctx read github://owner/repo/issues/123 --comments 9-20. Use --comments 1-3 or --comments all to override. GitHub directory reads return an ls-style listing headed by the canonical github://... path, so agents can immediately drill into a child path instead of trying to parse GitHub HTML. YouTube video URLs are rejected with a clear unsupported error. ctx does not provide transcript extraction because that path depends on unstable authenticated extraction and external downloader behavior.

Authentication

ctx auth login ctx7          # Context7 (device code login, opens browser)
ctx auth login exa --key ... # EXA open-web search
ctx auth login cloudflare    # Cloudflare Browser Rendering
ctx auth status              # check what's configured

GitHub reads use your gh auth token automatically.

Agent Integration

ctx ships with a skill definition for AI agents (Claude Code, Cursor, etc.) that teaches them the full search → read → navigate → scrape workflow. Install it with your agent's skill mechanism.

Environment Variables

Variable Purpose
GITHUB_TOKEN / GH_TOKEN GitHub API token (fallback: gh auth token)
CONTEXT7_BASE_URL Override Context7 API base URL
CONTEXT7_API_KEY Context7 API key (alternative to OAuth)
EXA_API_KEY EXA API key(s), comma-separated for rotation

About

Library documentation finder — ctx7 index + full document reads

Resources

Stars

Watchers

Forks

Packages

 
 
 

Contributors