sql

A read-only command for running SQL queries against ctx's indexed view of a codebase. SQL is a language for selecting, joining, grouping, and filtering structured data.

In plain words
What is it for?
Use it for custom reports and investigations involving symbols, files, relationships, aggregations, joins, or filters.
Why use it?
It answers custom questions that fixed commands cannot, while preventing the query from changing the index.

Command

Install

Getting it into your agent

One page per mod, every tool's command on it. A separate URL per tool would split the same page into five that compete with each other.

agentmods
npx agentmods add commands/agentis-tools/ctx/sql
Clone the repo
git clone --depth 1 https://github.com/agentis-tools/ctx
Per session 0 Only the description is in the session, so the agent can decide to use it. The body loads when it is invoked.
When invoked 1,363 The whole file, excluding the scripts and references it only reads on demand.
Security scan A 0 findings. Scan, not verified.
Origin original No closer match found in the catalogue.
Token cost

What it costs to keep this loaded

Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.

ModelPer sessionOnce invoked
Fable 5 $0.00000 $0.01363
Opus 5 $0.00000 $0.00681
Sonnet 5 $0.00000 $0.00273
Haiku 4.5 $0.00000 $0.00136

Measured yesterday against content hash 8322c7658f6b, method: parsed. Prices are Anthropic first-party input rates as of 2026-08-30, from the pricing page.

Security

Grade A, and why

sql scanned grade A with 0 findings against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured yesterday.

A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.

Nothing flagged

None of the 26 patterns this scan looks for appear in this file: no shell pipes, no recursive deletes, no credential paths, no hidden text, no instruction-override or anti-refusal phrasing, no agent-config snooping. That is not a guarantee, it is the absence of the things that are checkable.

docs/website/docs/commands/sql.md · 158 lines

How it starts

The opening of the file, as written. The whole thing — 158 lines — stays where its author put it; the contents beside it link to each section on GitHub.

ctx sql

Run read-only SQL against the code-intelligence index through DuckDB, over a stable v1 view layer.

Synopsis

ctx sql [QUERY] [OPTIONS]

Description

ctx sql gives you raw SQL access to the code-intelligence index. Where the canned ctx query subcommands answer fixed questions (callers, deps, impact), ctx sql lets you ask arbitrary ones: aggregations, joins across symbols and edges, and custom WHERE conditions. Prefer ctx sql whenever you need a grouping, a join, or a filter the canned commands do not expose.

The query surface is the versioned v1 schema — a set of stable views (v1.symbols, v1.edges, v1.files, v1.meta). See the full SQL Schema (v1) reference for every column.

  • Query v1.* only. It is the compatibility contract: columns and views may be added within schema_version 1, but nothing is renamed or removed without bumping v1.meta.schema_version.
  • Anything outside v1.* is internal and unstable. The raw index is reachable as code.*, but its shape can change at any time. Do not depend on it.

The query is read from the first of: the [QUERY] argument, --file, or stdin (when QUERY is - or omitted and stdin is piped).

Programmatic use

For agents and scripts, pass --json for machine-readable rows and --max-rows to bound the result set:

ctx sql --json --max-rows 50 "SELECT name, complexity FROM v1.symbols ORDER BY complexity DESC"

An index must exist first (ctx index); querying without one exits with code 2.

Options

Option Description Default
[QUERY] SQL text. If - or omitted while stdin is piped, read from stdin.
--file <PATH> Read the query from a file (mutually exclusive with QUERY).
--output <F> Output format: table, csv, or json. table
--json Alias for --output json.
--max-rows <N> Cap returned rows (0 = unlimited). 1000
--timeout <SECS> Abort the query after N seconds. 10
--fail-on-rows Exit 1 if the query returns >= 1 row (for gate usage). false
--schema Print the v1 schema reference and exit 0.

Read the full file on GitHub · 158 lines

Changes

What this file has done since we first saw it

Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.

  1. yesterday First seen · 158 lines · 0 tokens per session scan A 8322c7658f6b

Subscribe to this mod's changes

sql is a command published in the GitHub repository agentis-tools/ctx (11 stars, last pushed 15d ago), licensed Apache-2.0. It costs nothing until one of its globs matches a file; then it loads 1,363 tokens. A static security scan graded it A with 0 findings. No closer match exists in the catalogue, so it is treated as the original; first seen 2026-08-30.