| name | king-context |
| description | Search indexed documentation and research corpora efficiently via the `.king-context/bin/kctx` CLI (list, search, read, topics, grep). Trigger when the user wants to query content that is already indexed locally — "search the docs / our research", "how to use library X", "what's the API for Y", "what do we have on topic Z", "find in indexed content". Do NOT trigger when the user asks to scrape a new doc site (use scraper-workflow) or to run a new open-web research pipeline (use king-research). Prefer this skill over raw web search whenever a local corpus may contain the answer. |
King Context — Documentation Search Skill
Search indexed documentation and research corpora efficiently using .king-context/bin/kctx. Find the right section in ≤3 calls.
Two Stores, One CLI
King Context keeps two separate stores:
| Store | Populated by | What's in it |
|---|
docs | .king-context/bin/king-scrape <url> | Scraped product/API documentation |
research | .king-context/bin/king-research <topic> | Topic-driven research corpora from the open web |
Every kctx command is source-aware:
- Default: searches both stores, merged by score.
--source docs|research scopes to one store.
--doc <name> scopes to a single doc (works across stores — most precise filter).
Every search/grep hit is prefixed [docs] or [research] so you can tell the source at a glance.
Scraping/research LLM stages can use local Ollama by setting env vars such as ENRICH_PROVIDER=ollama, ENRICH_MODEL=<model>, OLLAMA_API_MODE=openai, and OLLAMA_BASE_URL=http://localhost:11434/v1. For Ollama Cloud/direct native API, use OLLAMA_API_MODE=native, OLLAMA_BASE_URL=https://ollama.com, and OLLAMA_API_KEY. OpenRouter fallback is opt-in with ENABLE_FALLBACK=true plus OPENROUTER_API_KEY.
Search Strategy
1. Check _learned/ → known shortcut? → .king-context/bin/kctx read <doc> <path> → DONE
2. .king-context/bin/kctx list → which doc + which store?
3. .king-context/bin/kctx search "query" → find section → got it?
4. .king-context/bin/kctx read --preview → assess relevance → right section?
5. .king-context/bin/kctx read → full content → DONE
6. Save discovery to _learned/
Rules:
- ALWAYS check
_learned/ FIRST — costs ~100 tokens, saves thousands.
- ALWAYS verify learned paths still exist before using them (
.king-context/bin/kctx read errors if stale).
- Prefer
.king-context/bin/kctx search over .king-context/bin/kctx grep — metadata search is faster and cheaper.
- Use
--preview before full read — assess relevance before paying full token cost.
- Use
.king-context/bin/kctx grep only for exact code patterns, API names, or error strings.
- Scope aggressively:
--doc <name> > --source <store> > unfiltered.
- NEVER read all sections — search narrows, preview confirms, then read only what's needed.
Picking a Filter (decision tree)
User asks about a specific library/product/SDK? → --doc <name>
User asks about a research topic you scraped? → --doc <research-slug>
User asks something generic, unsure which doc? → --source docs or --source research
User asks "is it anywhere in our indexed stuff?" → no filter (search both)
--doc is the sharpest tool. Run .king-context/bin/kctx list once if you don't know the name.
Query Decomposition
Transform user intent into efficient CLI queries:
| User asks | CLI query |
|---|
| "How to stream audio with ElevenLabs" | .king-context/bin/kctx search "streaming" --doc elevenlabs-api |
| "Authentication for the Exa API" | .king-context/bin/kctx search "auth api-key" --doc exa |
| "What does our research say on Chain of Thought" | .king-context/bin/kctx search "chain of thought" --source research |
| "Compare ToT vs CoT — anything indexed?" | .king-context/bin/kctx search "tree of thoughts" --source research --top 5 |
| "Is rate limiting documented anywhere?" | .king-context/bin/kctx search "rate limit" (both stores) |
"Find where Client( is used in httpx" | .king-context/bin/kctx grep "Client\\(" --doc httpx |
| "What topics does the docs cover" | .king-context/bin/kctx topics elevenlabs-api |
| "Show only our research corpora" | .king-context/bin/kctx list research |
Tips:
- Use 1–2 specific keywords, not full sentences.
- Scope to
--doc when you know which doc.
- Use
--top 3 to reduce output tokens.
- Keywords match exact terms; use_cases match substrings — "stream" matches "How to stream audio".
CLI Command Reference
List indexed content
.king-context/bin/kctx list
.king-context/bin/kctx list docs
.king-context/bin/kctx list research
.king-context/bin/kctx list --json
Search by metadata (keywords, use_cases, tags)
.king-context/bin/kctx search "query"
.king-context/bin/kctx search "streaming" --doc elevenlabs-api
.king-context/bin/kctx search "reasoning" --source research
.king-context/bin/kctx search "livecrawl" --source docs
.king-context/bin/kctx search "auth" --top 3
.king-context/bin/kctx search "query" --json
Output tags every hit with [docs] or [research]. Returns title, path, score, first use_case. No content — metadata only.
Read a section
.king-context/bin/kctx read <doc> <section-path>
.king-context/bin/kctx read <doc> <section-path> --preview
.king-context/bin/kctx read <doc> <section-path> --source research
.king-context/bin/kctx read <doc> <section-path> --json
If the doc name isn't unique, pass --source. If section not found, suggests similar paths.
Browse by topic
.king-context/bin/kctx topics <doc>
.king-context/bin/kctx topics <doc> --tag api-reference
.king-context/bin/kctx topics <doc> --source research
.king-context/bin/kctx topics <doc> --json
Grep content
.king-context/bin/kctx grep "pattern"
.king-context/bin/kctx grep "Client\\(" --doc httpx
.king-context/bin/kctx grep "livecrawl" --source docs
.king-context/bin/kctx grep "pattern" --context 3
.king-context/bin/kctx grep "pattern" --json
Index / re-index
.king-context/bin/kctx index .king-context/data/example.json
.king-context/bin/kctx index .king-context/data/research/topic.json
.king-context/bin/kctx index <path> --source research
.king-context/bin/kctx index --all
Generating New Content
Two producers feed the stores:
.king-context/bin/king-scrape https://docs.example.com
.king-context/bin/king-research "prompt engineering techniques" --basic
.king-context/bin/king-research "retrieval augmented generation" --medium
.king-context/bin/king-research "mixture of experts" --high
.king-context/bin/king-research "<topic>" --extrahigh
Both auto-index on completion — the new doc is immediately searchable via kctx. king-research outputs are tagged source_type: "research" in every section so --source research and the [research] prefix work automatically.
Self-Learning
After finding a useful section, save a shortcut for future sessions.
When to save
- You found the right section after searching.
- You discovered a gotcha or non-obvious behavior.
- You found a pattern that would help answer similar questions.
How to save
Write to .king-context/_learned/<doc-name>.md:
# <Doc Name> - Learned Shortcuts
## <Topic>
- **<What>** → `<section-path>` section
- Store: docs | research
- Gotcha: <non-obvious behavior>
- Related: `<other-section>` for <reason>
---
Last updated: <date>
Tracking the store lets you skip kctx list on the next lookup.
Reading learned shortcuts
Before any search:
- Read
.king-context/_learned/<doc-name>.md.
- If a shortcut matches the current query, use it directly:
.king-context/bin/kctx read <doc> <path>.
- If the path no longer exists (stale), fall back to normal search and update the learned file.
Good vs Bad Search Strategies
Good (3 calls, ~400 tokens)
.king-context/bin/kctx search "streaming" --doc elevenlabs-api --top 3
→ 1. [docs] WebSocket Streaming (elevenlabs-api/websocket-streaming) score=8.50
.king-context/bin/kctx read elevenlabs-api websocket-streaming --preview
→ "# WebSocket Streaming\n\nConnect to ws://..." Tokens: 450
.king-context/bin/kctx read elevenlabs-api websocket-streaming
→ Full content
Good (research-scoped, 2 calls)
.king-context/bin/kctx search "zero shot cot" --source research --top 3
→ 1. [research] Zero-Shot CoT (prompt-engineering-techniques/ai-prompt-engineering-...) score=12.50
.king-context/bin/kctx read prompt-engineering-techniques ai-prompt-engineering-patterns-cot-react-tot-zero-shot-cot
→ Full content
Bad (wasteful, ~3000+ tokens)
.king-context/bin/kctx list
.king-context/bin/kctx topics elevenlabs-api
.king-context/bin/kctx read elevenlabs-api getting-started # wrong section
.king-context/bin/kctx read elevenlabs-api text-to-speech # still wrong
.king-context/bin/kctx search "websocket streaming audio real-time" # too many terms
.king-context/bin/kctx read elevenlabs-api websocket-streaming # finally found it