CLI Reference¶
The context-router CLI lets you validate configs, inspect routers, run queries, and manage the cache from the terminal.
Commands¶
context-router version¶
Show the installed version.
context-router validate¶
Check a configuration file for errors without running the engine. Validates structure, types, field values, and cross-references (e.g., routes referencing undefined sources).
context-router validate --config context-router.yaml
# Config is valid: 5 sources, 3 routes, 2 permissions
| Option | Short | Default | Description |
|---|---|---|---|
--config |
-c |
context-router.yaml |
Config file path |
Exit codes:
| Code | Meaning |
|---|---|
| 0 | Config is valid |
| 1 | Config has errors |
Error output example:
context-router validate --config broken.yaml
# Validation failed:
# - sources.api: http_api source requires 'url'
# - routes[2] (engineering): source 'api_docs' is not defined
# - budget.ranking: invalid value 'custom', expected one of ['manual', 'recency', 'relevance']
The validator checks:
- Version is
"1.0" - Every source has a valid
typeand its required fields (contentfor inline,pathfor directory/git_repo,urlfor http_api) - Every route has a unique
nameand references defined sources - Every route has at least one source
- Permission
allow_sourcesanddeny_sourcesreference defined sources - Permission
defaultis"allow"or"deny" budget.max_tokens>= 1budget.rankingis one ofrelevance,recency,manualbudget.truncationis one ofdrop,truncate_end,truncate_middlebudget.estimatoris one ofchars_div4,words,whitespacebudget.reserve_tokens>= 0cache.ttl>= 0cache.max_entries>= 1
context-router inspect¶
Display a formatted summary of the router configuration: sources, routes, permissions, and budget settings.
| Option | Short | Default | Description |
|---|---|---|---|
--config |
-c |
context-router.yaml |
Config file path |
--tag |
-- | Filter sources by tag |
Filter by tag:
This shows only sources tagged with engineering, along with all routes and permissions.
Exit codes:
| Code | Meaning |
|---|---|
| 0 | Success |
| 1 | Config file not found or invalid |
context-router query¶
Execute a context query against the router. This runs the full pipeline: route matching, permission filtering, parallel fetch, relevance scoring, ranking, and budget trimming.
# Console output (default)
context-router query --config context-router.yaml --text "What is the remote work policy?"
# JSON output
context-router query --config context-router.yaml --text "expenses" --output json
# Agent-specific query
context-router query --config context-router.yaml --text "deploy the API" --agent eng-assistant
# Export to file
context-router query --config context-router.yaml --text "PTO policy" --output json --output-file result.json
| Option | Short | Default | Description |
|---|---|---|---|
--config |
-c |
context-router.yaml |
Config file path |
--text |
-t |
(required) | Query text |
--agent |
-a |
"default" |
Agent identifier |
--output |
-o |
console |
Output format: console or json |
--output-file |
-- | Write JSON output to file (implies JSON format) |
Console output shows a human-readable summary: matched routes, chunk titles and sources, token counts, and timing.
JSON output includes the full response structure: all chunks with content, source, title, path, relevance score, token count, and metadata. Also includes total_tokens, was_truncated, matched_routes, denied_sources, and evaluation_time_ms.
Exit codes:
| Code | Meaning |
|---|---|
| 0 | Query executed successfully (even if no results) |
| 1 | Config file not found or invalid |
context-router cache stats¶
Show cache statistics: entry count, total size, TTL, and max entries.
context-router cache stats --config context-router.yaml
# Cache: enabled
# Directory: .context-router-cache
# Entries: 42
# Total Size: 156832 bytes
# TTL: 300s
# Max Entries: 1000
| Option | Short | Default | Description |
|---|---|---|---|
--config |
-c |
context-router.yaml |
Config file path |
If the cache is disabled in the config, the output shows Cache: disabled with zero entries.
Exit codes:
| Code | Meaning |
|---|---|
| 0 | Success |
| 1 | Config file not found or invalid |
context-router cache clear¶
Clear cache entries. Optionally clear only entries for a specific source.
# Clear all cache entries
context-router cache clear --config context-router.yaml
# Cleared 42 cache entries
# Clear entries for a specific source
context-router cache clear --config context-router.yaml --source docs
# Cleared 7 cache entries
| Option | Short | Default | Description |
|---|---|---|---|
--config |
-c |
context-router.yaml |
Config file path |
--source |
-s |
-- | Only clear entries for this source name |
Exit codes:
| Code | Meaning |
|---|---|
| 0 | Success |
| 1 | Config file not found or invalid |
Command Tree¶
context-router
|-- version Show version
|-- validate Validate a config file
|-- inspect Display router summary
|-- query Execute a context query
|-- cache
|-- stats Show cache statistics
|-- clear Clear cache entries
Common Workflows¶
Validate before deploying¶
Test a query as a specific agent¶
context-router query \
--config context-router.yaml \
--text "Show me salary data" \
--agent "intern-bot" \
--output json | python -m json.tool
Check the denied_sources field to see if permissions blocked any sources.
Debug routing¶
# See which routes match
context-router query --config context-router.yaml --text "How do deployments work?"
# Look at "matched_routes" in the output
# Compare two queries
context-router query -c context-router.yaml -t "deployment guide" -o json > query1.json
context-router query -c context-router.yaml -t "PTO policy" -o json > query2.json
Cache management¶
# Check cache state
context-router cache stats -c context-router.yaml
# Clear stale data for a specific source after updating its content
context-router cache clear -c context-router.yaml --source knowledge_base
# Full cache reset
context-router cache clear -c context-router.yaml
Global Behavior¶
- All commands read the config file using
load_config(), which performs full validation including environment variable interpolation (${ENV_VAR}) - If the config file is not found, commands print an error to stderr and exit with code 1
- If the config file has validation errors, all errors are listed to stderr and the command exits with code 1