Serving Agents
Expose ktx context to Claude Code, Codex, Cursor, OpenCode, and custom agents.
ktx serves agents through the CLI and project-local instruction files. Agents read generated rules, call ktx commands, inspect context files, and use JSON for structured results.
Recommended setup
Run the agent install step from a ktx project:
ktx setup --agents
Or install a specific target:
ktx setup --agents --target codex
Supported targets:
| Target | Generated project file |
|---|---|
| Claude Code | .claude/skills/ktx/SKILL.md |
| Codex | .agents/skills/ktx/SKILL.md |
| Cursor | .cursor/rules/ktx.mdc |
| OpenCode | .opencode/commands/ktx.md |
Universal .agents | .agents/skills/ktx/SKILL.md |
Claude Code and Codex also support global installs:
ktx setup --agents --target claude-code --global ktx setup --agents --target codex --global
Installed files are recorded in .ktx/agents/install-manifest.json. Rerun
ktx setup --agents after moving a checkout or reinstalling the CLI.
Agent command set
All supported clients use the same command surface. Use --project-dir outside
the ktx project directory.
Readiness
ktx status --json
Run this before relying on context. It reports project, provider, connection, context-build, and agent-integration readiness.
Semantic layer discovery
ktx sl --json ktx sl --connection-id warehouse --json ktx sl "revenue" --json --limit 10
Use these commands to find source names, connection ids, measures, dimensions, and files to inspect.
Semantic-layer validation and queries
ktx sl validate orders --connection-id warehouse
Compile SQL before executing:
ktx sl query \ --connection-id warehouse \ --measure orders.total_revenue \ --dimension orders.created_date \ --format sql
Execute only when the task calls for live data:
ktx sl query \ --connection-id warehouse \ --measure orders.total_revenue \ --dimension orders.status \ --execute \ --max-rows 100
For complex calls, agents can write a JSON query object and pass it with
--query-file.
Wiki context
ktx wiki --json ktx wiki "revenue recognition" --json --limit 10
Search the wiki for business definitions, metric caveats, process rules, and non-obvious terms.
Context refresh
Agents can refresh context when the user asks them to:
ktx ingest warehouse --fast ktx ingest ktx ingest --file docs/revenue-notes.md --connection-id warehouse
Use --deep only when LLM and embedding setup is ready.
Good agent behavior
Agents should:
- Run
ktx status --jsonbefore using ktx context. - Use
ktx sl <query>andktx wiki <query>before writing SQL from memory. - Inspect the relevant YAML or Markdown files after search returns candidates.
- Compile SQL with
ktx sl query --format sqlbefore executing. - Use
--max-rowswhenever executing a live query. - Validate edited semantic sources with
ktx sl validate. - Keep generated context changes reviewable in git.
ktx is a local context layer with a CLI and plain project files. Do not assume a background server, ORPC route, frontend app, or external migration system.
Manual setup
Use manual setup for custom agents that can read project-local instructions.
-
Install the universal target:
ktx setup --agents --target universal
-
Configure the agent to read
.agents/skills/ktx/SKILL.md. -
Open the agent in the ktx project directory.
-
Ask it to run
ktx status --jsonand summarize readiness.
For per-client notes, see Agent Clients.
Troubleshooting
| Symptom | Likely cause | Recovery |
|---|---|---|
| Agent says ktx is unavailable | Agent did not load the generated instruction file | Rerun ktx setup --agents --target <target> and restart the agent session |
| Agent command cannot find the project | Agent is running outside the ktx directory | Add --project-dir <path> or open the agent in the project root |
| Generated rules point at a missing CLI path | CLI was moved, rebuilt, or reinstalled | Rerun ktx setup --agents |
| Agent cannot find a metric | Context is missing or stale | Run ktx sl <query>, inspect source YAML, then refresh with ktx ingest if needed |
| Agent query returns too many rows | The command executed without a result cap | Require --max-rows for executed queries |