Running Convex Functions from the CLI

Basic syntax
npx convex run <fileName>:<functionName>
Dev vs Production
# Dev (default)
npx convex run migrations:backfillUsers
# Production
npx convex run migrations:backfillUsers --prod
With arguments
Pass a JSON string as the second argument.
npx convex run migrations:backfillUsers '{"batchSize": 100}'
npx convex run migrations:backfillUsers '{"batchSize": 100}' --prod
Internal functions
Works the same. The CLI can call internal functions even though clients cannot.
# convex/migrations.ts exports an internalMutation called backfillUsers
npx convex run migrations:backfillUsers
npx convex run migrations:backfillUsers --prod
Queries and actions too
Not limited to mutations. Run any Convex function.
npx convex run posts:listAll
npx convex run ai:generateSummary '{"postId": "abc123"}'
Use cases
One-off migrations and backfills
Data fixes in dev or production
Seeding dev data
Testing internal functions manually
Running cleanup scripts






