AgentSkillsCN

convex

当您需要与Convex后端协同工作——例如开发服务器、部署应用、执行函数、导入或导出数据时,这一工具能为您提供便利。它封装了npx convex CLI,涵盖Convex、后端、无服务器架构、函数与Schema。注意:此工具不适用于其他数据库(如Supabase、Firebase等),也不适用于仅涉及前端的工作。

SKILL.md
--- frontmatter
name: convex
description: Use when working with Convex backend - dev server, deployment, function execution, data import/export. Wraps npx convex CLI. Covers convex, backend, serverless, functions, schema. NOT for: other databases (Supabase, Firebase, etc.), frontend-only work.

Convex Operations

Backend skill wrapping npx convex CLI. Routes to workflows for specific operations.

Project Detection

Run first to verify you're in a Convex project:

bash
[ -d "convex" ] && echo "Convex project detected" || echo "ERROR: No convex/ directory found"

If no convex/ directory: Run npx convex init to initialize.


Quick Actions

What you want to doWorkflow
Start dev serverworkflows/dev.md
Deploy to productionworkflows/deploy.md
Run a Convex functionworkflows/run-function.md
Export dataworkflows/data-export.md
Import dataworkflows/data-import.md
Inspect/validate schemaworkflows/schema.md
Delete user and all dataworkflows/user-deletion.md
Fix errorsworkflows/troubleshooting.md

Available Scripts

Execute directly - they handle errors and edge cases:

ScriptPurposeUsage
scripts/dev.shStart dev server with auto-cleanupbash ~/.claude/commands/convex/scripts/dev.sh [--deployment <name>]
scripts/deploy.shDeploy to productionbash ~/.claude/commands/convex/scripts/deploy.sh [--1p] [--dry-run]
scripts/run-function.shExecute queries/mutations/actionsbash ~/.claude/commands/convex/scripts/run-function.sh api:funcName [--args '{}']
scripts/export-data.shExport database backupbash ~/.claude/commands/convex/scripts/export-data.sh [--path <file>]
scripts/import-data.shImport data (with safety prompts)bash ~/.claude/commands/convex/scripts/import-data.sh --path <file.zip>

Common Commands Reference

bash
# Development
npx convex dev                    # Start dev server with hot reload

# Deployment
npx convex deploy                 # Deploy to production

# Functions
npx convex run api:functionName   # Run a function
npx convex run api:func --arg '{"key":"value"}'  # With arguments

# Data
npx convex export --path ./backup.zip   # Export all data
npx convex import --path ./backup.zip   # Import data

# Environment
npx convex env list               # List env vars
npx convex env set KEY=value      # Set env var
npx convex env get KEY            # Get env var

# Other
npx convex dashboard              # Open dashboard in browser
npx convex codegen                # Regenerate types
npx convex logs --name prod       # View production logs

Safety Rules

  1. Always check project - Verify convex/ directory exists before running commands
  2. Deploy key for CI - Production deploys need CONVEX_DEPLOY_KEY (see deploy workflow)
  3. Backup before import - Always export before importing data
  4. Review schema changes - Schema migrations can be destructive

🚨 CRITICAL: Auto-Clean Before Any Convex Command

ALWAYS prefix Convex commands with this cleanup:

bash
rm -f convex/*.js 2>/dev/null; npx convex dev

The "Two output files" Error

If you see:

code
✘ [ERROR] Two output files share the same path but have different contents: out/auth.js

Cause: Orphan .js files in convex/ folder (from git worktrees, crashes, or manual operations).

Fix: rm -f convex/*.js then retry.

Prevention: Always use the cleanup prefix. Only .ts files belong in convex/.

See workflows/troubleshooting.md for details.