ktx
Install and configure ktx, the open-source context layer for data agents.
Use this skill when a user wants an agent to add ktx to a project, connect
data sources, build initial context, install agent integration, or troubleshoot
a local ktx setup.
Operating rules
- Act autonomously when the user asks you to install or configure ktx.
The non-interactive scripted flow below is the canonical path — bare
ktx setup is interactive (clack prompts) and an agent cannot drive it.
- Setup's non-interactive flags are intentionally hidden from
--help. Use the
flags listed below; verify uncommon flags against the docs at
https://docs.kaelio.com/ktx/ or this skill — not against --help output.
- Ask only for values you cannot infer: project directory, connection targets,
credentials, account identifiers, and source selections.
- Never ask the user to paste secrets when an
env:VAR_NAME or file:/path
reference would work. Pasting a literal URL is also safe — ktx setup
auto-externalizes URLs into .ktx/secrets/<id>-url (see workflow step 2).
- Do not commit
.ktx/secrets/*.
- Print each command you run and its result.
- If a command fails, identify the cause and change something before retrying.
Gather inputs once
Before invoking ktx setup, collect in one round:
- Project directory (default: current working directory).
- LLM backend and key strategy. In
--no-input mode the CLI defaults to
anthropic and requires an API key. When the user is inside Claude
Code, pass --llm-backend claude-code explicitly; otherwise pass
--llm-backend anthropic --anthropic-api-key-env ANTHROPIC_API_KEY.
- Embedding backend (
sentence-transformers is the local default and needs
no key; use openai only if the user already has a key, then pass
--embedding-api-key-env OPENAI_API_KEY).
- Database: driver, connection id, URL (or
env: / file: ref), and one or
more schemas.
- Optional context sources (dbt, Metabase, Looker, LookML, MetricFlow,
Notion). Add each one with a follow-up
ktx setup --source … run (see
Add context sources); use --skip-sources only
when the user has none.
Do not discover these inputs across multiple setup runs.
Install workflow
Detect the install path. If the working directory contains
packages/cli/dist/bin.js or pnpm-workspace.yaml referencing
@kaelio/ktx you are inside the ktx monorepo — build and link the
local CLI with pnpm and do not run npm install -g. Otherwise:
node --version # require >= 22; stop and ask the user if older
ktx --version || npm install -g @kaelio/ktx
Run scripted setup (canonical path):
ktx setup --no-input --yes \
--project-dir <path> \
--llm-backend claude-code \
--embedding-backend sentence-transformers \
--database <driver> --database-connection-id <id> \
--database-url '<raw-url | env:NAME | file:/abs/path>' \
--database-schema <schema> \
--skip-sources
- Configure one new database connection per setup invocation. For multiple
connections, rerun setup once per connection.
- Pasting a literal
--database-url is safe: the CLI relocates the URL
into .ktx/secrets/<connection-id>-url and rewrites ktx.yaml to a
file: ref automatically.
Resumability and --skip-*. Re-running ktx setup against an existing
project resumes its config. Use --skip-llm, --skip-databases,
--skip-sources, or --skip-embeddings to leave a slice unconfigured but
let the rest complete instead of aborting on the first failure. When
resuming an existing project to change one slice (e.g. only LLM), still
pass the database flags from the previous run — setup validates current
flags, not persisted ktx.yaml state.
Build context if setup did not already complete one:
ktx ingest <connection-id> --no-input
ktx ingest always builds enriched context and requires a configured model
and embeddings (set during setup); a database connection without them fails
with an enrichment-readiness error. Note: ktx ingest rejects --yes
together with --no-input (Choose only one runtime install mode);
ktx setup accepts both. Use --no-input only for ingest.
Install agent integration:
ktx setup --agents --target <claude-code|claude-desktop|codex|cursor|opencode|universal>
ktx mcp start --project-dir <path>
Agent integration is not usable until ktx mcp start is running. The
--agents step prints this requirement as Required before using agents.
Fall back to bare ktx setup only when a human is at the keyboard —
it uses interactive prompts an agent cannot answer.
Add context sources
Context sources (dbt, Metabase, Looker, LookML, MetricFlow, Notion) are added
one at a time — --source is not repeatable, so run ktx setup once per
source. Source setup is resumable against an existing project: pass
--skip-databases --skip-llm --skip-embeddings so only the source is
configured. Map warehouse-backed sources (dbt, Metabase, Looker) to an existing
database connection with --source-warehouse-connection-id <db-connection-id>.
Prefer env:VAR / file:/abs/path refs for keys and tokens over literals.
# dbt — pick exactly one of --source-path (local) or --source-git-url (remote)
ktx setup --no-input --yes --skip-databases --skip-llm --skip-embeddings \
--source dbt --source-connection-id <id> \
--source-git-url <url> --source-branch <branch> \
--source-warehouse-connection-id <db-connection-id>
# Metabase
ktx setup --no-input --yes --skip-databases --skip-llm --skip-embeddings \
--source metabase --source-connection-id <id> \
--source-url <url> --source-api-key-ref env:METABASE_API_KEY \
--source-warehouse-connection-id <db-connection-id> \
--metabase-database-id <metabase-db-id>
# Notion
ktx setup --no-input --yes --skip-databases --skip-llm --skip-embeddings \
--source notion --source-connection-id <id> \
--source-auth-token-ref env:NOTION_TOKEN \
--notion-crawl-mode selected_roots --notion-root-page-id <page-id>
Notes:
--metabase-database-id is the numeric id of the warehouse inside
Metabase (not the ktx connection id). Discover it from the Metabase API
(GET /api/database) or UI if the user doesn't know it.
--notion-crawl-mode selected_roots requires at least one
--notion-root-page-id (repeatable); use all_accessible to crawl
everything the token can see.
- After adding sources, ingest each new connection so its context is queryable:
ktx ingest <source-connection-id> --no-input.
Files to inspect
ktx.yaml: project configuration.
.ktx/secrets/*: local secret files. Never commit them.
semantic-layer/<connection-id>/*.yaml: semantic sources for SQL
compilation.
wiki/**/*.md: project context pages for agents.
.claude/skills/ktx/, .agents/skills/ktx/, .cursor/rules/ktx.mdc, and
.opencode/commands/ktx.md: generated agent integration files.
Verification
After setup, run:
ktx connection test <connection-id>
ktx status --json --no-input
Judge readiness from ktx status --json fields, not the exit code.
ktx status exits 1 whenever the LLM is none, even when embeddings and
every database connection are healthy. Treat success as:
verdict: "ready" at the top of the JSON, and
- every
connections[].status === "ok", and
- every
ktx connection test <id> exited 0.
A non-zero exit with only the LLM unconfigured is still a usable context
layer — report it as "ready, LLM optional" rather than retrying setup.
Troubleshooting
For known failure signatures (invalid ELF header,
Native CLI binary for <plat> not found, Missing Anthropic API key,
claude-code probe failure, KTX cannot work without a database on resume),
see troubleshooting.md.
Final report
End setup work with a concise report:
ktx SETUP COMPLETE
Project: <path>
LLM: <backend> / <model>
Embeddings: <backend> / <model>
Connections: <name> (<driver>) status=<ok|warn|fail>
Sources: <list or none>
Verdict: <ready|needs action>
Next:
1. <copy-pasteable command or action>
2. <copy-pasteable command or action>
RESULT: PASS
1---2name: ktx3description: Installs and configures ktx, the open-source context layer for data agents — runs ktx setup non-interactively with hidden CLI flags, configures database connections and embeddings, installs agent integration, and verifies readiness. Use when the user asks an agent to add ktx to a project, connect data sources, install agent rules, ingest schema, or troubleshoot a local ktx install.4metadata:5 source: https://skillmd.com/skills/majiayu000/ktx6---78# ktx910Install and configure **ktx**, the open-source context layer for data agents.11Use this skill when a user wants an agent to add **ktx** to a project, connect12data sources, build initial context, install agent integration, or troubleshoot13a local **ktx** setup.1415## Operating rules1617- Act autonomously when the user asks you to install or configure **ktx**.18 The non-interactive scripted flow below is the canonical path — bare19 `ktx setup` is interactive (clack prompts) and an agent cannot drive it.20- Setup's non-interactive flags are intentionally hidden from `--help`. Use the21 flags listed below; verify uncommon flags against the docs at22 `https://docs.kaelio.com/ktx/` or this skill — not against `--help` output.23- Ask only for values you cannot infer: project directory, connection targets,24 credentials, account identifiers, and source selections.25- Never ask the user to paste secrets when an `env:VAR_NAME` or `file:/path`26 reference would work. Pasting a literal URL is also safe — `ktx setup`27 auto-externalizes URLs into `.ktx/secrets/<id>-url` (see workflow step 2).28- Do not commit `.ktx/secrets/*`.29- Print each command you run and its result.30- If a command fails, identify the cause and change something before retrying.3132## Gather inputs once3334Before invoking `ktx setup`, collect in one round:35361. Project directory (default: current working directory).372. LLM backend and key strategy. In `--no-input` mode the CLI defaults to38 `anthropic` and **requires an API key**. When the user is inside Claude39 Code, pass `--llm-backend claude-code` explicitly; otherwise pass40 `--llm-backend anthropic --anthropic-api-key-env ANTHROPIC_API_KEY`.413. Embedding backend (`sentence-transformers` is the local default and needs42 no key; use `openai` only if the user already has a key, then pass43 `--embedding-api-key-env OPENAI_API_KEY`).444. Database: driver, connection id, URL (or `env:` / `file:` ref), and one or45 more schemas.465. Optional context sources (dbt, Metabase, Looker, LookML, MetricFlow,47 Notion). Add each one with a follow-up `ktx setup --source …` run (see48 [Add context sources](#add-context-sources)); use `--skip-sources` only49 when the user has none.5051Do not discover these inputs across multiple setup runs.5253## Install workflow54551. **Detect the install path.** If the working directory contains56 `packages/cli/dist/bin.js` or `pnpm-workspace.yaml` referencing57 `@kaelio/ktx` you are inside the **ktx** monorepo — build and link the58 local CLI with `pnpm` and do **not** run `npm install -g`. Otherwise:5960 ```bash61 node --version # require >= 22; stop and ask the user if older62 ktx --version || npm install -g @kaelio/ktx63 ```64652. **Run scripted setup** (canonical path):6667 ```bash68 ktx setup --no-input --yes \69 --project-dir <path> \70 --llm-backend claude-code \71 --embedding-backend sentence-transformers \72 --database <driver> --database-connection-id <id> \73 --database-url '<raw-url | env:NAME | file:/abs/path>' \74 --database-schema <schema> \75 --skip-sources76 ```7778 - Configure one new database connection per setup invocation. For multiple79 connections, rerun setup once per connection.80 - Pasting a literal `--database-url` is safe: the CLI relocates the URL81 into `.ktx/secrets/<connection-id>-url` and rewrites `ktx.yaml` to a82 `file:` ref automatically.83843. **Resumability and `--skip-*`.** Re-running `ktx setup` against an existing85 project resumes its config. Use `--skip-llm`, `--skip-databases`,86 `--skip-sources`, or `--skip-embeddings` to leave a slice unconfigured but87 let the rest complete instead of aborting on the first failure. **When88 resuming an existing project to change one slice (e.g. only LLM), still89 pass the database flags from the previous run** — setup validates current90 flags, not persisted `ktx.yaml` state.91924. **Build context** if setup did not already complete one:9394 ```bash95 ktx ingest <connection-id> --no-input96 ```9798 `ktx ingest` always builds enriched context and requires a configured model99 and embeddings (set during setup); a database connection without them fails100 with an enrichment-readiness error. Note: `ktx ingest` rejects `--yes`101 together with `--no-input` (*Choose only one runtime install mode*);102 `ktx setup` accepts both. Use `--no-input` only for ingest.1031045. **Install agent integration:**105106 ```bash107 ktx setup --agents --target <claude-code|claude-desktop|codex|cursor|opencode|universal>108 ktx mcp start --project-dir <path>109 ```110111 Agent integration is **not usable until `ktx mcp start` is running**. The112 `--agents` step prints this requirement as `Required before using agents`.1131146. **Fall back to bare `ktx setup` only when a human is at the keyboard** —115 it uses interactive prompts an agent cannot answer.116117## Add context sources118119Context sources (dbt, Metabase, Looker, LookML, MetricFlow, Notion) are added120**one at a time** — `--source` is not repeatable, so run `ktx setup` once per121source. Source setup is resumable against an existing project: pass122`--skip-databases --skip-llm --skip-embeddings` so only the source is123configured. Map warehouse-backed sources (dbt, Metabase, Looker) to an existing124database connection with `--source-warehouse-connection-id <db-connection-id>`.125Prefer `env:VAR` / `file:/abs/path` refs for keys and tokens over literals.126127```bash128# dbt — pick exactly one of --source-path (local) or --source-git-url (remote)129ktx setup --no-input --yes --skip-databases --skip-llm --skip-embeddings \130 --source dbt --source-connection-id <id> \131 --source-git-url <url> --source-branch <branch> \132 --source-warehouse-connection-id <db-connection-id>133134# Metabase135ktx setup --no-input --yes --skip-databases --skip-llm --skip-embeddings \136 --source metabase --source-connection-id <id> \137 --source-url <url> --source-api-key-ref env:METABASE_API_KEY \138 --source-warehouse-connection-id <db-connection-id> \139 --metabase-database-id <metabase-db-id>140141# Notion142ktx setup --no-input --yes --skip-databases --skip-llm --skip-embeddings \143 --source notion --source-connection-id <id> \144 --source-auth-token-ref env:NOTION_TOKEN \145 --notion-crawl-mode selected_roots --notion-root-page-id <page-id>146```147148Notes:149150- `--metabase-database-id` is the **numeric id of the warehouse inside151 Metabase** (not the ktx connection id). Discover it from the Metabase API152 (`GET /api/database`) or UI if the user doesn't know it.153- `--notion-crawl-mode selected_roots` requires at least one154 `--notion-root-page-id` (repeatable); use `all_accessible` to crawl155 everything the token can see.156- After adding sources, ingest each new connection so its context is queryable:157 `ktx ingest <source-connection-id> --no-input`.158159## Files to inspect160161- `ktx.yaml`: project configuration.162- `.ktx/secrets/*`: local secret files. Never commit them.163- `semantic-layer/<connection-id>/*.yaml`: semantic sources for SQL164 compilation.165- `wiki/**/*.md`: project context pages for agents.166- `.claude/skills/ktx/`, `.agents/skills/ktx/`, `.cursor/rules/ktx.mdc`, and167 `.opencode/commands/ktx.md`: generated agent integration files.168169## Verification170171After setup, run:172173```bash174ktx connection test <connection-id>175ktx status --json --no-input176```177178**Judge readiness from `ktx status --json` fields, not the exit code.**179`ktx status` exits 1 whenever the LLM is `none`, even when embeddings and180every database connection are healthy. Treat success as:181182- `verdict: "ready"` at the top of the JSON, and183- every `connections[].status === "ok"`, and184- every `ktx connection test <id>` exited 0.185186A non-zero exit with only the LLM unconfigured is still a usable context187layer — report it as "ready, LLM optional" rather than retrying setup.188189## Troubleshooting190191For known failure signatures (`invalid ELF header`,192`Native CLI binary for <plat> not found`, `Missing Anthropic API key`,193`claude-code` probe failure, `KTX cannot work without a database` on resume),194see [troubleshooting.md](troubleshooting.md).195196## Final report197198End setup work with a concise report:199200```text201ktx SETUP COMPLETE202203Project: <path>204LLM: <backend> / <model>205Embeddings: <backend> / <model>206Connections: <name> (<driver>) status=<ok|warn|fail>207Sources: <list or none>208Verdict: <ready|needs action>209210Next:2111. <copy-pasteable command or action>2122. <copy-pasteable command or action>213214RESULT: PASS215```