Back to home

Integration · Codex CLI & IDE Extension · Open Source (Apache-2.0) & Cloud

OpenAI Codex
Claix

OpenAI Codex + Claix: The Best Way to Connect Codex to Your SQL Database

OpenAI Codex is built for deep, autonomous execution — inspecting repositories, running multi-step tasks in the terminal or IDE, and finishing headless codex exec jobs until tests pass. Giving Codex real visibility into your schema and rows turns guesswork into accurate migrations and fixes. Giving it an unrestricted database connection turns one wrong assumption into lost data.

Claix sits over MCP between Codex and PostgreSQL, MySQL, or MariaDB: row-scoped reads plus a deny-by-default SQL firewall that inspects affected rows in milliseconds, with zero model calls at check time. Configure once in config.toml and protect every CLI and IDE session — on Claix Core (Apache-2.0) or Claix Cloud.

The problem

Why autonomous Codex workflows need more than raw MCP or local hooks

Teams wiring OpenAI Codex to SQL databases quickly hit three structural traps that prompts and regex hooks cannot close.

  • Unscoped read-only MCP leaks data context: generic database MCP servers expose entire schemas and unfiltered tables. A broad query or prompt injection in user-submitted text can pull sensitive columns or cross-customer rows into the model context.
  • Client-side shell hooks cannot parse SQL impact (and can skip headless runs): .codex/hooks.json regex scripts cannot tell whether an UPDATE touches 1 test row or 25,000 paid orders, and non-interactive codex exec workflows have shown hook-dispatch gaps where user hooks never fire while commands still execute.
  • Standing write credentials fail open: once an autonomous agent holds a write-capable DATABASE_URL, a single --force flag, TRUNCATE, or session-level security change can execute before anyone reviews it.

How Claix helps

Database boundaries outside the prompt and outside fragile regex scripts

  • Deny-by-default SQL firewall

    A statement passes only when an active permission covers it. A permission written for one targeted DELETE never covers a DROP, ALTER, TRUNCATE, or GRANT. With no matching permission, writes are denied.

  • Session-escape immunity

    Plain SELECT and transaction statements (BEGIN, COMMIT) pass. Session changes that could turn security off — switching roles or disabling row-level security (RLS) — cannot be permitted.

  • Affected-row inspection

    Claix connects with a read-only claix_agent role, inspects the exact rows a proposed write would touch, and returns allow, deny, or needs_approval without running the write itself.

  • Scoped retrieval per agent

    Reads always pass through a defined Claix agent whose row scope is enforced on every query, isolating tenants, branches, or environments automatically.

Core vs Cloud

Claix Core on your machine vs Claix Cloud for your team

Both editions run the same deterministic check. Solo developers and multi-team companies pick how they want to operate it.

How you run CodexClaix Core (Open Source · Self-Hosted)Claix Cloud (Hosted · Team Governance)
Best fitIndividual developers, local Docker stacks, private VPCs, Git-tracked YAML permissions beside your code.Engineering teams, shared staging/production databases, CI/background Codex runs, Slack sign-off & compliance.
Where it runsYour laptop, server, or container (Node.js 22+, @claix-dev/core, ghcr.io/claix-dev/claix-core). License: Apache-2.0.Hosted by Claix at claix.dev with database secrets stored in Cloud Vault. No runtime to maintain.
Codex connectionLocal stdio MCP (npx -y @claix-dev/core mcp) or local HTTP API.Streamable HTTP MCP (https://claix.dev/mcp) with workspace API keys.
When needs_approval triggersReturns needs_approval directly to Codex so execution stops safely before touching data.Sends the statement straight to Slack so an engineer or owner can approve it from a channel.
Audit & tracesLocal append-only traces.jsonl on the host machine.Central company audit log and isolated workspaces across all engineers and agents.
Writing permissionsYAML files validated against your database catalog with claix validate.Visual policy editor in the Cloud dashboard — update permissions instantly without redeploying.

Choose your edition

Why Core locally · why Cloud for teams

  • Why run open-source Claix Core on your machine?

    Local databases still take time to rebuild when an autonomous loop drops columns or wipes seed tables — and developers routinely switch branches while .env still points at a tunnelled remote instance. Claix Core needs no Claix account, keeps configuration in local YAML, validates routes and permissions with claix validate, and blocks unpermitted statements in milliseconds.

  • Why standardize team repos on Claix Cloud?

    When multiple engineers and CI pipelines run Codex against shared environments, nobody should keep raw database passwords in local config, and local traces.jsonl gives security teams no central visibility. Claix Cloud stores the claix_agent credential in Cloud Vault, isolates projects into workspaces, routes risky statements to Slack, and logs every decision centrally.

Option 1 · Claix Core

Set up Claix Core locally with OpenAI Codex (open source)

Codex shares MCP servers between the CLI and the IDE extension through ~/.codex/config.toml (or project-scoped .codex/config.toml). Initialize your ./claix folder, validate against your catalog, then register the local stdio MCP server.

Init & validate

npx -y @claix-dev/core init
npx -y @claix-dev/core validate

Docker quickstart

git clone https://github.com/claix-dev/claix-core
cd claix-core
docker compose up -d --build --wait

codex mcp add

codex mcp add claix -- npx -y @claix-dev/core mcp

.codex/config.toml (env_vars)

[mcp_servers.claix]
command = "npx"
args = ["-y", "@claix-dev/core", "mcp"]
env_vars = [
  "CLAIX_API_KEY",
  "CLAIX_DB_PASSWORD"
]

[mcp_servers.claix.env]
CLAIX_CONFIG_DIR = "./claix"
CLAIX_DB_ENGINE = "postgres"
CLAIX_DB_HOST = "127.0.0.1"
CLAIX_DB_NAME = "app"
CLAIX_DB_USER = "claix_agent"
  • Pass secrets via env_vars so CLAIX_API_KEY and CLAIX_DB_PASSWORD stay in your environment rather than hardcoded in plaintext.
  • Confirm Codex sees the server with codex mcp list.

Option 2 · Claix Cloud

Connect OpenAI Codex to Claix Cloud (teams & shared environments)

For zero local containers, visual policy editing, workspaces, central audit logs, and Slack approvals, connect Codex directly to Claix Cloud over Streamable HTTP. Point bearer_token_env_var at your Cloud API key environment variable so no secret is committed to Git.

codex mcp add (Cloud)

codex mcp add claix --url https://claix.dev/mcp

.codex/config.toml (Cloud)

[mcp_servers.claix]
url = "https://claix.dev/mcp"
bearer_token_env_var = "CLAIX_CLOUD_API_KEY"

Policy

Guide Codex with AGENTS.md (and keep raw write keys out of the sandbox)

OpenAI Codex automatically reads AGENTS.md in your repository to understand how to use configured MCP tools. Pair credential isolation — never exposing superuser database credentials inside the Codex shell — with this policy block in your root AGENTS.md.

AGENTS.md

## Database Access & SQL Policy (Claix MCP)
- Do not invoke raw `psql`, `mysql`, or destructive ORM flags (`--force`, `--accept-data-loss`) from the shell.
- Use `claix_retrieve_ask` on the `claix` MCP server whenever you need database rows so agent scopes and route boundaries apply.
- Before applying or proposing any `INSERT`, `UPDATE`, `DELETE`, or schema statement, call `claix_guard_check`.
- Only proceed when `claix_guard_check` returns `allow`. Halt immediately and surface the reason if the verdict is `deny` or `needs_approval`.

Migrate

Move from Claix Core to Claix Cloud without rewriting rules

Many developers start solo with Claix Core and move to Claix Cloud when teammates, Slack approvals, or staging governance enter the picture. Import your Core setup from /dashboard/database-connection.

  1. 01

    Gather your Core files

    Collect your Core .env (CLAIX_DB_HOST, CLAIX_DB_PORT, CLAIX_DB_NAME, CLAIX_DB_USER=claix_agent, CLAIX_DB_PASSWORD, and CLAIX_DB_SSL=require or verify-full), plus claix/guards/*.yaml, claix/routes/*.yaml, claix/agents/*.yaml, and optionally traces.jsonl (up to 8 MB; Cloud keeps the newest 2,000 events).

  2. 02

    Open Import from Core

    Sign in at /dashboard/database-connection as the workspace owner and choose Import from Core.

  3. 03

    Upload and import

    Upload your files and choose Import into Cloud. Any file error detected before the connection saves aborts cleanly without half-applying changes and lists every error by filename.

  4. 04

    Go live on Cloud

    Your password is stored in Cloud Vault, deny-by-default guards and row scopes stay active, and needs_approval verdicts connect to Slack.

Frequently asked questions

What is the best way to connect OpenAI Codex to PostgreSQL, MySQL, or MariaDB?
Connect OpenAI Codex over MCP through Claix using either open-source Claix Core (@claix-dev/core, Apache-2.0) on your own machine or hosted Claix Cloud (https://claix.dev/mcp). Claix enforces row-scoped reads and a deny-by-default SQL firewall with zero model calls at check time.
Does Claix call a model to check SQL statements from Codex?
No. Deciding whether a SQL statement is allowed never calls a model in either Claix Core or Claix Cloud. Claix parses the statement deterministically, inspects the rows a write would touch through a read-only database role, and returns allow, deny, or needs approval.
Should I use Claix Core (open source) or Claix Cloud with Codex?
Use Claix Core (Apache-2.0) when you want to operate the engine yourself via Docker or Node.js 22+ with YAML permissions stored in Git and zero signup. Use Claix Cloud when teams need shared workspaces, visual policy editing in a dashboard, Slack approvals for sensitive statements, and a central company audit log.
How do I prevent OpenAI Codex from bypassing Claix via shell commands?
Never expose superuser or standing write database credentials in the shell environment Codex runs in. Connect Claix via a read-only claix_agent role (stored in Cloud Vault on Claix Cloud or an isolated Core container) and run writes only after an explicit allow verdict.
Can I start on Claix Core and import my setup into Claix Cloud later?
Yes. Workspace owners can use Import from Core at /dashboard/database-connection to import their database connection, YAML guards, routes, agents, and up to 8 MB (newest 2,000 events) of traces.jsonl into Claix Cloud.

Protect every Codex session with Claix

Scoped reads, deny-by-default writes, and the same MCP config for CLI and IDE. Start on open-source Core, or standardize the team on Claix Cloud with Slack approvals.