# AI Code Generation

> For AI agents: see [llms.txt](/llms.txt) for the complete documentation index. Markdown versions are available by adding .md to a page URL or requesting Accept: text/markdown.

Convex is designed around a small set of composable abstractions with strong guarantees that result in code that is not only faster to write, but easier to read and maintain, whether written by a team member or an LLM. Key features make sure you get bug-free AI generated code:

1. **Queries are Just TypeScript** Your database queries are pure TypeScript functions with end-to-end type safety and IDE support. This means AI can generate database code using the large training set of TypeScript code without switching to SQL.
2. **Less Code for the Same Work** Since so much infrastructure and boilerplate is automatically managed by Convex there is less code to write, and thus less code to get wrong.
3. **Automatic Reactivity** The reactive system automatically tracks data dependencies and updates your UI. AI doesn't need to manually manage subscriptions, WebSocket connections, or complex state synchronization—Convex handles all of this automatically.
4. **Transactional Guarantees** Queries are read-only and mutations run in transactions. These constraints make it nearly impossible for AI to write code that could corrupt your data or leave your app in an inconsistent state.

Together, these features mean AI can focus on your business logic while Convex's guarantees prevent common failure modes. For up-to-date information on which models work best with Convex, check out our LLM [leaderboard](https://convex.dev/llm-leaderboard).

## Agent plugins[​](#plugins "Direct link to Agent plugins")

Convex publishes official plugins for coding agents that include:

* **Tools** that let your agent securely interact with your dev deployment (e.g. read the data/logs/insights or run functions).
* **Hooks and monitors** that help your agent automatically identify issues in your code.
* **Skills and specialized agents** that teach your agent how to use Convex the most effectively.

See these documents for install instructions:

* [Claude Code](/ai/using-claude-code.md#install-the-convex-plugin-in-claude-code)
* [Codex](/ai/using-codex.md#install-the-convex-plugin)
* [Cursor](/ai/using-cursor.md#install-the-convex-plugin-in-cursor)

## Convex AI rules[​](#convex-ai-rules "Direct link to Convex AI rules")

AI code generation is most effective when you provide it with a set of rules to follow.

See these documents for install instructions:

* [GitHub Copilot](/ai/using-github-copilot.md)
* [![](/assets/images/conductor-logo-fa2224a9c0b89cba358b3a954a8e9051.png)](/ai/using-conductor.md)

  [Conductor](/ai/using-conductor.md)

When using  Claude Code,  Codex, or

 Cursor, we recommend installing the [Convex plugin](/ai/overview.md#plugins), which automatically include these rules.

For all other IDEs, add the following rules file to your project and refer to it when prompting for changes:

* [convex\_rules.txt](https://convex.link/convex_rules.txt)

We're constantly working on improving the quality of these rules for Convex by using rigorous evals. You can help by [contributing to our evals repo](https://github.com/get-convex/convex-evals).

## Convex AI files[​](#convex-ai-files "Direct link to Convex AI files")

The Convex CLI can install and maintain AI helper files in your project:

* `convex/_generated/ai/guidelines.md`
* Managed sections in `AGENTS.md` and `CLAUDE.md`
* Agent skills installed via `npx skills`

Use these commands to manage AI files:

* `npx convex ai-files install` - Install or refresh AI files
* `npx convex ai-files update` - Update to latest available AI files
* `npx convex ai-files status` - Show what is installed and what is stale
* `npx convex ai-files disable` - Suppress install and staleness messages in `npx convex dev`
* `npx convex ai-files enable` - Re-enable install and staleness messages
* `npx convex ai-files remove` - Remove Convex-managed AI files

The message preference and target agents are controlled in `convex.json` with:

convex.json

```
{

  "aiFiles": {

    "enabled": false,

    "skills": {

      "agents": ["claude-code", "codex", "cursor"]

    }

  }

}
```

By default, `aiFiles.skills.agents` targets `["claude-code", "codex"]`. You can override this to target other agents supported by `npx skills`, such as `cursor` see <https://github.com/vercel-labs/skills?tab=readme-ov-file#supported-agents> for a full list.

## Using Convex with Background Agents[​](#using-convex-with-background-agents "Direct link to Using Convex with Background Agents")

Remote cloud-based coding agents like Jules, Devin, Codex, and Cursor background agents can use Convex deployments when the CLI is in [Agent Mode](/cli/agent-mode.md). This limits the permissions necessary for these remote dev environments while letting agents run codegen, iterate on code, run tests, run one-off functions.

A good setup script for e.g. ChatGPT Codex might include

```
npm i

# npx convex init # allows setting environment variables before pushing

# npx convex env set --from-file ./path/to/.env.agent (optional)

npx convex dev --once
```

or

```
bun i

bun x convex dev --once
```

This command requires "full" internet access to download the binary.

### Cloud dev deployments per agent[​](#cloud-dev-deployments-per-agent "Direct link to Cloud dev deployments per agent")

If you'd rather give each agent (or each worktree) its own throwaway *cloud* dev deployment instead of an anonymous local one, a setup script can provision one and hand the agent a deploy key scoped only to it:

```
# Create a new dev deployment and select it.

npx convex deployment create --type dev --select \

  team-slug:project-slug:dev/$USER/$(basename "$PWD") \

  --expiration "in 5 days"



# Mint a deploy key scoped only to this deployment and save it to .env.local

# as CONVEX_DEPLOY_KEY.

npx convex deployment token create agent-token --save-env



# Push code once.

npx convex dev --once
```

Once `CONVEX_DEPLOY_KEY` is set in `.env.local`, the agent can only push to and develop against its own dev deployment — not prod or other developers' deployments.

If the agent needs environment variables, the easiest path is to set them as [project environment variable defaults](/production/environment-variables.md#project-environment-variable-defaults) so they're applied automatically to every new cloud deployment. You can also seed values from another source via `npx convex env set` (which accepts multiple variables on stdin or via `--from-file`).

See [Creating and deleting deploy keys from the CLI](/cli/deploy-key-types.md#deployment-token) for the full options on `npx convex deployment token`, and [Working with Multiple Deployments](/production/multiple-deployments.md) for worktree-based recipes (Conductor, Cursor, Codex, T3 Code) that you can adapt to this flow.

## Convex MCP Server[​](#convex-mcp-server "Direct link to Convex MCP Server")

[Setup the Convex MCP server](/ai/convex-mcp-server.md) to give your AI coding agent access to your Convex deployment to query and optimize your project.

## Agent Skills[​](#agent-skills "Direct link to Agent Skills")

[Agent Skills](/ai/agent-skills.md) are portable packages of instructions and workflows that teach AI coding agents how to perform specialized Convex tasks like setting up auth, designing a schema, and running migrations.
