Supabase CLI for AI agents
The Supabase CLI for coding agents: run the local stack, create and diff migrations, generate types, and dry-run pushes, with the remote commands to avoid.
What Supabase CLI does for an agent
The Supabase CLI is Supabase's official tool for local development. It runs the full Supabase stack locally in Docker, manages SQL migrations, generates TypeScript types from the schema, and links a project to push changes.
Installed as a dev dependency, it runs as npx supabase. The local stack is where an agent should do its work: migrations can be created, reset, and tested freely there, and only a reviewed migration reaches the hosted database.
Official site: supabase.com
Install Supabase CLI
The install commands from the official docs. Check it worked with supabase --version.
brew install supabase/tap/supabase
npm install supabase --save-dev
Signing in Supabase CLI for an agent
Local development needs no sign-in. Linking a hosted project needs supabase login, or a personal access token in SUPABASE_ACCESS_TOKEN for CI.
supabase login
supabase link --project-ref your-project-ref
Environment variables: SUPABASE_ACCESS_TOKEN. Set them in the agent's environment; never paste values into prompts or commit them.
What agents use Supabase CLI for
Example commands with placeholder names. Swap in your own project, app, or file names.
Start the local stack
supabase start
Needs Docker running. Prints local URLs and keys.
Create a new migration file
supabase migration new add_profiles
Diff local schema changes into a migration
supabase db diff -f add_profiles
Generate TypeScript types from the local database
supabase gen types typescript --local > src/types/supabase.ts
Preview which migrations a push would apply
supabase db push --dry-run
Safety rules for agents
Safe to run without asking
supabase statussupabase db push --dry-runsupabase gen types --localsupabase migration list
Ask a human first
supabase db pushsupabase db reset --linkedsupabase functions deploysupabase secrets set
- Do all schema work against the local stack; supabase db reset is fine locally and catastrophic with --linked.
- Never run supabase db reset --linked; it wipes the hosted database.
- Show the dry-run output of db push before a human applies migrations.
- Keep the service role key out of client code, logs, and chat.
AGENTS.md or CLAUDE.md snippet
Paste this into the instruction file your agent reads at the start of every session, then adjust the rules to your setup.
## Supabase CLI (supabase) Use `supabase` for running Supabase locally, writing database migrations, and generating types. - Check it is installed with `supabase --version`. If it is missing, ask before installing it. - Auth: credentials are set up by a human. Never print or commit them (SUPABASE_ACCESS_TOKEN). - Run without asking (read-only): `supabase status`, `supabase db push --dry-run`, `supabase gen types --local`, `supabase migration list`. - Ask a human first (changes or deletes things): `supabase db push`, `supabase db reset --linked`, `supabase functions deploy`, `supabase secrets set`. - Do all schema work against the local stack; supabase db reset is fine locally and catastrophic with --linked. - Never run supabase db reset --linked; it wipes the hosted database. - Show the dry-run output of db push before a human applies migrations. - Keep the service role key out of client code, logs, and chat. - Prefer JSON output where the command supports it, and keep output short.
Supabase CLI or an MCP server?
An official MCP option exists. Supabase publishes an official MCP server for managing projects, running SQL, and reading logs, with a read-only mode. Point it at a development project; use the CLI for migrations in the repository.
Rule of thumb: in a terminal agent that a human has signed in, the CLI is usually faster and cheaper in context. In a chat client without a shell, or when you want a fixed set of typed tools, use an MCP server.
Other Databases tools
Supabase CLI questions
How do I install Supabase CLI?
Homebrew: brew install supabase/tap/supabase. Other official options: Project dev dependency. Check the install with supabase --version, and see the Supabase docs for other platforms.
How does an AI agent authenticate Supabase CLI?
Local development needs no sign-in. Linking a hosted project needs supabase login, or a personal access token in SUPABASE_ACCESS_TOKEN for CI.
Which Supabase CLI commands are safe for an agent to run?
Commands that only read state are safe to run without asking: supabase status; supabase db push --dry-run; supabase gen types --local; supabase migration list. Ask a human before anything that changes or deletes something: supabase db push; supabase db reset --linked; supabase functions deploy; supabase secrets set.
Is there an MCP server for Supabase CLI?
Supabase publishes an official MCP server for managing projects, running SQL, and reading logs, with a read-only mode. Point it at a development project; use the CLI for migrations in the repository.