1---2name: convex-deploy3description: Implement Convex deployment workflows, environments, and CI/CD configuration. Use for dev/prod/preview deployments, deploy keys, local deployments, environment variables, schema/index rollout safety, and HTTP action URLs. Use proactively when users mention deploy, preview, staging, CI, env vars, or local backend. Examples: - user: "Set up Convex deploy in CI" → configure deploy key + npx convex deploy steps - user: "How do preview deployments work?" → explain preview keys, lifecycle, limits - user: "Deploy to prod safely" → list safe schema/function change patterns - user: "Use local convex" → explain npx convex dev --local and limitations4---5
6<overview>
7Cover deployment lifecycle, environments, and safe rollout strategies for Convex backends and full-stack apps.
8</overview>
9
10<context name="Deployment Concepts">
11- Model: one prod deployment per project, one dev deployment per team member, preview deployments per branch.
12- Preview deployments are beta and auto-cleaned; data seeding requires `--preview-run`.
13- Local deployments: `npx convex dev --local --once`, no public URL, Node actions require Node 18.
14- Agent Mode: Use `CONVEX_AGENT_MODE=anonymous` for AI coding agents to limit permissions during development.
15- Env vars are per-deployment; system vars `CONVEX_CLOUD_URL` and `CONVEX_SITE_URL`.
16- Safe change rules: schema MUST match data; use optional/backfill/union migrations; keep functions backwards compatible; scheduled args MUST remain valid.
17- Project config: `convex.json` CAN change functions path, node runtime; static codegen is beta.
18- Pausing deployments returns errors for new calls, queues scheduled jobs, skips crons; You SHOULD test on dev first.
19</context>
20
21<rules>
22
23### Deployment Operations
24- Core commands: `npx convex dev`, `npx convex deploy`, `npx convex codegen`, `npx convex run` (use `--prod` for prod).
25- Agent Mode: You SHOULD use `CONVEX_AGENT_MODE=anonymous npx convex dev --once` when iterating as an AI agent to safely generate codegen artifacts.
26- Deploy target resolution: `CONVEX_DEPLOY_KEY` overrides, else uses production of `CONVEX_DEPLOYMENT` project.
27- Build step: `npx convex deploy --cmd "npm run build"` and `--cmd-url-env-var-name` if needed.
28- Deploy keys: production, preview, dev, admin (You MUST NOT commit/log).
29- Hosting flows:
30 - Vercel/Netlify build command SHOULD use `npx convex deploy --cmd 'npm run build'`.
31 - You MUST set `CONVEX_DEPLOY_KEY` per environment (Preview vs Production).
32 - Preview seeding via `--preview-run 'functionName'`.
33 - Custom hosting: deploy backend, host frontend elsewhere; custom domains require overriding `CONVEX_CLOUD_URL` and redeploying; optional `CONVEX_SITE_URL`.
34
35### Required Outputs
36- You MUST use exact CLI commands and flags from docs.
37- You MUST state target deployment resolution (deploy key vs CONVEX_DEPLOYMENT).
38- You MUST call out deploy-side effects: schema validation, index backfill, codegen, bundling.
39- You SHOULD always mention `.convex.site` vs `.convex.cloud` URL usage where relevant.
40
41### Deployment Model
42- Each project has one production deployment and one cloud dev deployment per team member.
43- Preview deployments are per-branch and are auto-cleaned after a time window.
44- Local deployments are dev-only and run as subprocesses of `npx convex dev`.
45
46### CLI Workflow
47
48#### Dev
49- `npx convex dev`:
50 - Watches files, pushes changes to dev deployment.
51 - Regenerates `convex/_generated/*`.
52 - You SHOULD use `--tail-logs` to control log output.
53- Local dev:
54 - `npx convex dev --local --once` for local backend.
55 - Note: No public URL; HTTP requests need a proxy (e.g., ngrok).
56 - Node actions require Node 18 locally.
57
58#### Deploy
59- `npx convex deploy`:
60 - Typechecks functions.
61 - Regenerates codegen.
62 - Bundles and pushes functions, schema, and indexes.
63- Deploy target resolution:
64 - If `CONVEX_DEPLOY_KEY` is set, deploys to that key's target.
65 - Else uses the production deployment of `CONVEX_DEPLOYMENT`'s project.
66- Optional build command:
67 - `npx convex deploy --cmd "npm run build"`
68 - Use `--cmd-url-env-var-name` to customize env var name.
69
70### Deploy Keys
71- Production deploy key: targets project production deployment (typical CI).
72- Preview deploy key: creates preview deployment per branch.
73- Dev deploy key: scoped to a single dev deployment.
74- Admin key: full control; used for anonymous local deployments.
75- **Security**: You MUST NOT paste deploy keys into code or commit history.
76
77### Preview Deployments
78- Beta feature, lifecycle auto-cleans (5 days default).
79- Preview deployment name is tied to branch; redeploy replaces previous preview.
80- Data seeding requires running a function during deploy (`--preview-run`).
81
82### Environment Variables
83- You MUST set per-deployment via dashboard or `npx convex env`.
84- Same key MAY require values in both dev and prod.
85- System vars:
86 - `CONVEX_CLOUD_URL` for client RPCs.
87 - `CONVEX_SITE_URL` for HTTP actions.
88- You MUST NOT branch exports on `process.env` at runtime; functions set at deploy time.
89
90### Safe Rollout Rules
91- Schema MUST match existing data; deploy blocks on validation failures.
92- Safe schema changes:
93 - Add tables.
94 - Add optional fields, backfill, then make required.
95 - Widen via `v.union`, backfill, then narrow.
96- Functions MUST remain backward compatible while old clients are running.
97- Scheduled functions MUST accept previously scheduled args.
98
99### Index Backfill
100- New indexes backfill during deploy; CAN slow production push.
101- You SHOULD use staged indexes (including search/vector) for large tables.
102- Removing indexes deletes them on deploy; You MUST ensure no code paths depend on them.
103
104### URLs
105- HTTP actions: `https://<deployment>.convex.site`.
106- Client URLs: `https://<deployment>.convex.cloud` (via `CONVEX_CLOUD_URL`).
107- You SHOULD warn about mixing `.convex.site` and `.convex.cloud`.
108
109### Response Checklist
110- [ ] State environment (dev/prod/preview/local).
111- [ ] Provide exact commands and required env vars.
112- [ ] List safety considerations (schema, functions, scheduled).
113- [ ] Mention logs location (CLI or dashboard) when troubleshooting.
114
115</rules>