/scythe:scythefrom scythe
Generates type-safe database access code from annotated SQL across 10 languages and database engines. Includes linting, formatting, security audit, and sqlc migration.
Ships in scythe. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
Read when SKILL.md points to them.
Scythe compiles annotated SQL into type-safe database access code. You write SQL queries with annotations, scythe generates the boilerplate -- structs, functions, type mappings -- for Rust, Python, TypeScript, JavaScript, Go, Java, Kotlin, C#, Elixir, Ruby and PHP across ten database engines. Built-in linting and formatting catch SQL bugs before they ship.
Use this skill when:
@name, @returns, @optional, etc.)scythe.toml for code generationcargo install scythe-cli
# or
brew install Goldziher/tap/scythe
1. Write annotated SQL:
-- @name GetUserById
-- @returns :one
SELECT id, name, email FROM users WHERE id = $1;
2. Configure scythe.toml:
[scythe]
version = "1"
[[sql]]
name = "main"
engine = "postgresql"
schema = ["sql/schema/*.sql"]
queries = ["sql/queries/*.sql"]
[[sql.gen]]
backend = "rust-sqlx"
output = "src/generated"
3. Generate code:
scythe generate
scythe generate [--config <path>] # Generate code (default: scythe.toml)
scythe check [--config <path>] # Validate SQL without generating
scythe lint [--config <path>] [--fix] [files] # Lint SQL files
scythe audit [--config <path>] [files] # Security scan (SC-SEC*)
scythe inspect [database_url] # Operational checks on a live database
scythe fmt [--config <path>] [--check] [files] # Format SQL files
scythe migrate [sqlc_config] # Convert sqlc project
| Flag | Commands | Description |
|---|---|---|
-c, --config | all except migrate | Path to config file (default: scythe.toml) |
--fix | lint | Auto-fix violations |
--check | fmt | Check without modifying (exit 1 if changes needed) |
--diff | fmt | Show unified diff of changes |
--dialect | lint, fmt, audit, inspect | SQL dialect: postgres, mysql, sqlite, mssql, oracle, snowflake |
--database-url | check | Verify types and detect schema drift against a live database (PostgreSQL only) |
--database-url | lint | Also run the live-database inspect checks as part of lint (PostgreSQL or MySQL/MariaDB) |
--format | check, lint, audit, inspect | human (default), sarif, json |
-o, --output | check, lint, audit, inspect | Write findings to a file instead of stdout |
--severity | audit, inspect | Drop findings below off, warn, or error |
--exit-zero | check, lint, audit, inspect | Exit 0 even when error-severity findings are present |
files... | lint, fmt, audit | Specific SQL files (if empty, uses config) |
Exit codes: 0 clean, 2 on error-severity findings from check, lint,
audit or inspect, 1 on operational failure (unreadable config or I/O error). Query parse and
analysis findings from check, lint and audit use exit 2. --exit-zero collapses 2 to 0 and leaves 1 alone. Findings failures and
"scythe could not run" are deliberately distinguishable, so CI never mistakes a
crashed run for a clean one.
See references/cli-reference.md for the full flag tables.
All annotations use -- @ prefix in SQL comments.
| Annotation | Required | Description |
|---|---|---|
@name QueryName | Yes | Names the generated function and struct |
@returns :type | Yes | Return type: :one, :opt, :many, :exec, :exec_result, :exec_rows, :batch, :grouped |
@group_by table.column | With :grouped | Specifies parent table for grouped results |
@optional param | No | Makes a parameter optional (SQL rewritten to skip filter when NULL) |
@param name: desc | No | Documents a parameter |
@nullable col1, col2 | No | Forces columns to be nullable |
@nonnull col1, col2 | No | Forces columns to be non-nullable |
@json col = TypeName | No | Maps column to typed JSON struct |
@deprecated message | No | Marks query as deprecated |
| Value | Description |
|---|---|
:one | Exactly one row (SELECT ... WHERE id = $1) |
:opt | Optional row (zero or one) |
:many | Multiple rows (SELECT ... WHERE status = $1) |
:exec | No return (INSERT, UPDATE, DELETE) |
:exec_result | Driver result or affected count, depending on backend |
:exec_rows | Affected row count |
:batch | Bulk execution |
:grouped | Rows grouped by @group_by key |
@optional rewrites WHERE col = $1 into WHERE ($1 IS NULL OR col = $1). Works with: =, <>, !=, >, <, >=, <=, LIKE, ILIKE.
-- @name SearchUsers
-- @returns :many
-- @optional status
-- @optional name
SELECT id, name FROM users
WHERE status = $1 AND name ILIKE $2;
-- @name GetEvent
-- @returns :one
-- @json data = EventData
SELECT id, data FROM events WHERE id = $1;
Generates Json<EventData> (Rust), EventData (TypeScript), etc.
-- @name GetUsersWithOrders
-- @returns :grouped
-- @group_by users.id
SELECT u.id, u.name, o.id AS order_id, o.total
FROM users u JOIN orders o ON o.user_id = u.id;
Generates a parent struct with nested child collection.
[scythe]
version = "1"
[[sql]]
name = "main"
engine = "postgresql" # postgresql, mysql, sqlite, duckdb, cockroachdb, mssql, oracle, mariadb, redshift, snowflake
schema = ["sql/schema/*.sql"]
queries = ["sql/queries/*.sql"]
# Multiple backends from one SQL block
[[sql.gen]]
backend = "rust-sqlx"
output = "src/generated/rust"
[[sql.gen]]
backend = "typescript-pg"
output = "src/generated/ts"
row_type = "zod" # optional: interface (default) or zod
[[sql.gen]]
backend = "python-psycopg3"
output = "src/generated/python"
row_type = "pydantic" # optional: dataclass (default), pydantic, or msgspec
# Type overrides
[[sql.type_overrides]]
column = "users.metadata" # specific column
type = "json"
[[sql.type_overrides]]
db_type = "citext" # all columns of this type
type = "string"
# Lint configuration
[lint.categories]
safety = "error"
naming = "warn"
[lint.rules]
"SC-S03" = "off" # disable SELECT * warning
| Alias | Engine |
|---|---|
postgresql, postgres, pg | PostgreSQL |
mysql | MySQL |
sqlite, sqlite3 | SQLite |
duckdb | DuckDB |
cockroachdb, crdb | CockroachDB |
mssql, sqlserver | MSSQL |
oracle | Oracle |
mariadb | MariaDB |
redshift | Redshift |
snowflake | Snowflake |
| Language | Values |
|---|---|
| Python | dataclass (default), pydantic, msgspec |
| TypeScript | interface (default), zod |
structs_only = "true" emits only row types (interfaces/Zod schemas, enums, composites) and suppresses query functions and the driver import. Supported by rust-sqlx and every TypeScript backend (typescript-postgres, typescript-pg, typescript-mysql2, typescript-better-sqlite3, typescript-node-sqlite, typescript-wasm-sqlite, typescript-duckdb, typescript-mssql, typescript-oracledb, typescript-snowflake, typescript-kysely). Combine with row_type = "zod" for a types-only package with no driver dependency:
[[sql.gen]]
backend = "typescript-pg"
output = "src/generated/types"
row_type = "zod"
structs_only = "true"
Use exact backend identifiers from references/backends.md. That reference covers each engine, aliases, synchronous SQLite output, JavaScript JSDoc mode and option restrictions. Driver dependencies belong to the generated application; installing this skills-only plugin does not install Scythe or drivers.
SQL type --> neutral type --> language type
SERIAL int32 i32 (Rust) / int (Python) / number (TS)
TIMESTAMPTZ datetime_tz chrono::DateTime<Utc> / datetime / Date
TEXT[] array<string> Vec<String> / list[str] / string[]
Scythe infers nullability from SQL context:
Override with @nullable and @nonnull annotations.
# Column-level (takes precedence)
[[sql.type_overrides]]
column = "users.metadata"
type = "json"
# Database type-level
[[sql.type_overrides]]
db_type = "ltree"
type = "string"
Common PostgreSQL extension mappings:
| DB Type | Neutral Type |
|---|---|
ltree, citext, tsvector, macaddr | string |
hstore | json |
money | decimal |
geometry (PostGIS) | string |
24 built-in scythe lint rules + 35 audit rules = 59 built-in, plus sqruff's 69 style rules via integration.
The 11 SC-PRV* provenance rules and the 7 SC-DRF* schema drift rules are not part of the 59. They
run only from scythe check and never appear in scythe lint or scythe audit --list-rules output.
| Category | Prefix | Examples |
|---|---|---|
| Safety | SC-S | UPDATE/DELETE without WHERE, SELECT *, unused params |
| Naming | SC-N | snake_case tables/columns, verb prefixes on queries |
| Style | SC-T | Prefer explicit JOINs, COALESCE, COUNT(*) |
| Performance | SC-P | Missing ORDER BY with LIMIT, leading wildcard LIKE |
| Antipattern | SC-A | NULL comparisons with =, implicit type coercion |
| Codegen | SC-C | Missing @returns, duplicate @name |
| Security | SC-SEC, SC-RLS | Dangerous functions, GRANT ALL, RLS misconfiguration |
| Migration | SC-MIG | Irreversible or lock-prone DDL |
| Provenance | SC-PRV | scythe check only: generated artifact vs. current schema/engine/backend/version |
| Drift | SC-DRF | scythe check --database-url only: committed DDL vs. a live database |
[lint.categories]
safety = "error"
naming = "warn"
style = "off"
[lint.rules]
"SC-S03" = "off" # allow SELECT *
"SC-N03" = "error" # enforce query naming
SC-PRV* and SC-DRF* are configured from the same table -- scythe check applies [lint] to their
registries before resolving severities:
[lint.rules]
"SC-PRV02" = "error" # fail CI on scythe version drift
"SC-DRF02" = "error" # fail on tables the DDL never declares
[lint.categories]
provenance = "off" # skip provenance verification
drift = "off" # skip schema drift checking
repos:
- repo: https://github.com/Goldziher/scythe
rev: v0.20.3
hooks:
- id: scythe-fmt # Format SQL files
- id: scythe-lint # Lint SQL with auto-fix
- id: scythe-audit # Security scan
- id: scythe-inspect # Live-database operational checks
- id: scythe-generate # Regenerate code on SQL changes
- id: scythe-check # Validate SQL without generating
@returns: Every query needs both @name and @returns annotations.:one vs :many: Use :one when a missing row is an error and :opt for zero-or-one rows. :opt returns Option<T> / T | null.@nonnull to override if you know better.@optional parameter names: Must match a parameter in the query. Typos produce errors.python-asyncpg only works with postgresql).[[sql.gen]] blocks: Each needs its own output directory.column and db_type are mutually exclusive in each override entry.Detailed reference files for specific topics:
Full documentation: https://goldziher.github.io/scythe GitHub: https://github.com/Goldziher/scythe
What SKILL.md sets; muted values are Claude Code's defaults
Three short reads, in order
SQL, Rust, Python, TypeScript, Go
npx claudepluginhub goldziher/scythe --plugin scytheOther plugins' skills for the same job