# ktx
ktx is an **executable context layer for data agents** ; it lets [[How Coding Agents Work|AI agents]] ([[Claude Code]], [[Codex CLI|Codex]], [[Cursor CLI|Cursor]], [[OpenCode]]) query data warehouses accurately using *approved* metric definitions and company knowledge, instead of inventing their own SQL and returning numbers that don't match the business. Not to be confused with `kubectx`/`ktx` for Kubernetes context switching ; this is a data tool by Kaelio.
> The context layer for data agents.
## The problem
General-purpose agents are bad at data work: they re-explore the warehouse every time, invent ad-hoc metric logic, and return figures misaligned with approved definitions. Traditional semantic layers fix accuracy but demand constant manual upkeep. ktx automates both ; it learns company knowledge and maps the data stack itself.
## How it works
- **Automatic context learning** ; ingests wiki/docs content, dedupes it, and flags contradictions
- **Data stack mapping** ; samples tables, captures metadata, detects joinable columns
- **Semantic layer building** ; combines raw tables and metrics through a join graph, resolving chasm/fan traps
- **Agent-ready serving** ; exposes a CLI and an [[Model Context Protocol (MCP)|MCP]] server with full-text and semantic search; agents query MCP, which returns approved metrics and compiles **read-only** SQL
- **Read-only by design** ; never writes to your database
Under the hood it turns databases, BI tools, and modeling code into searchable wiki Markdown plus semantic-layer YAML.
## Stack & install
Primarily [[TypeScript]], with [[Python]] for semantic-layer query planning and compute. Apache-2.0.
```bash
npm install -g @kaelio/ktx
ktx setup
```
## Where it fits
It's the data-warehouse-specific answer to the same problem [[RTK]] and [[lowfat (CLI)|lowfat]] address for shell output: agents waste effort and produce noise without the right context. ktx supplies *governed* context (approved metrics, mapped joins) so a data agent's output is trustworthy, not just plausible.
## References
- GitHub: https://github.com/Kaelio/ktx
- Documentation: https://docs.kaelio.com/ktx/docs
## Related
- [[Claude Code]]
- [[Codex CLI]]
- [[Cursor CLI]]
- [[OpenCode]]
- [[Model Context Protocol (MCP)]]
- [[How Coding Agents Work]]
- [[TypeScript]]
- [[Python]]