Claude Code Supabase Integration

Use Claude Code with Supabase to design your Postgres schema, write and run migrations, generate Row Level Security policies, configure auth, and ship edge functions from one AI-assisted workflow.

By David Iya - Updated 2026-08-27

You are building on Supabase and using Claude Code to write the app, but the database work still stalls you. You hand-write migrations, second-guess your Row Level Security policies, and copy schema back and forth to keep your TypeScript types in sync. Connecting Claude Code to Supabase closes that loop: Claude reads your real schema, drafts the migration and the RLS policy, generates the types, and explains what each policy allows before you run supabase db push.

Before you start

  • Claude Code available in the environment where the project lives (desktop app or CLI).
  • A Supabase account and a project, either cloud-hosted or self-hosted.
  • The supabase CLI installed locally if you want migration, type-generation, and edge-function workflows.
  • Your project reference and, for the MCP server, a personal access token scoped to only the project you are working on.
  • Any database or service credentials stored as environment variables or in a secrets manager, never committed to the repository.

What it unlocks

Faster Schema Design

Describe the data you need and let Claude Code propose a normalized Postgres schema with sensible types, foreign keys, indexes, and constraints you can review before creating a single table.

SQL Migrations Without the Guesswork

Have Claude Code read the current schema and write a forward migration that applies cleanly, so you spend less time hand-crafting ALTER TABLE statements and more time shipping features.

Correct Row Level Security Policies

Turn a plain-English access rule such as 'users can only read their own orders' into a reviewable RLS policy, and have Claude explain exactly what the policy allows before you enable it.

Better Query Writing and Optimization

Ask Claude Code to write, explain, or optimize a SQL query, suggest the index a slow query needs, and read an EXPLAIN plan so you understand why it is slow before you change anything.

Smoother Auth Setup

Wire up Supabase Auth with the right session handling, protect routes, and pair auth rules with matching RLS policies so access is enforced at the database, not just the UI.

Storage Buckets and Policies Done Right

Create storage buckets and generate the access policies that decide who can upload, read, and delete files, so private assets stay private and public assets stay public.

Edge Functions Built Faster

Scaffold, write, and deploy Supabase edge functions for webhooks, background jobs, and server-side logic, with the secrets handled as environment variables rather than hardcoded.

Always-Current TypeScript Types

Generate TypeScript types from the live database so your client code is type-safe against the real schema, and regenerate them the moment a migration changes a table.

Realistic Seed and Test Data

Produce seed scripts and test fixtures that respect your foreign keys and constraints, so local development and CI run against data that looks like production.

Safer Changes With a Human in the Loop

Every migration, policy, and query Claude Code produces is reviewable SQL you approve before it runs, which keeps a person in control of anything that touches a production database.

How to connect Supabase

1

Install and authenticate the Supabase CLI

Install the supabase CLI, then log in so it can reach your projects. This is what lets Claude Code create migrations, push schema changes, and generate types on your behalf.

supabase login
2

Link the CLI to your project

From the project folder, link the local repository to your remote Supabase project using its project reference. This connects your local migrations and config to the correct database.

supabase link --project-ref your-project-ref
3

Connect the Supabase MCP server

Register the official Supabase MCP server with Claude Code so it can inspect tables, run read-only queries, and read project configuration in context. Scope the personal access token to a single project and prefer read-only mode.

claude mcp add supabase
4

Verify the connection

Restart Claude Code and ask it to list your tables or describe the schema. If it returns your real tables through the MCP server, the connection is live and Claude has the context it needs.

5

Run a small test change

Ask Claude Code to create a trivial migration, such as adding a nullable column, review the generated SQL, then apply it with supabase db push to confirm the full loop works end to end.

Design a Table, Add RLS, and Generate Types

  1. Inspect the current schema

    Ask Claude Code to read the existing schema through the Supabase MCP server so any new work fits your real tables and relationships.

  2. Design the new table

    Describe the feature and have Claude Code propose the table, its columns, types, foreign keys, and indexes for you to review.

  3. Create the migration

    Have Claude Code write the migration file for the new table and the changes it depends on, using supabase migration new to name it.

  4. Generate RLS policies

    Give Claude Code the access rule in plain English and ask it to enable RLS and write the select, insert, update, and delete policies, then confirm what each one allows.

  5. Apply and generate types

    After you review the SQL, apply it with supabase db push, then regenerate TypeScript types so your client code stays type-safe against the new schema.

  6. Review before production

    Read the final SQL and policies yourself, run them against a local or staging database first, and only then apply to production.

What people build with it

Schema Design

Describe your product's data model and have Claude Code propose the tables, relationships, types, and indexes, then refine the design before you create anything.

Writing Migrations

Ask Claude Code to read the current schema and generate a migration file that adds a column, table, or constraint, ready for supabase db push after you review it.

RLS Policy Generation

Turn an access rule into a Row Level Security policy for select, insert, update, and delete, and confirm with Claude exactly which rows each policy exposes.

Query Writing

Describe the result you want and have Claude Code write the SQL or the Supabase client query, including joins, filters, and aggregation, against your real tables.

Query Optimization

Share a slow query and its EXPLAIN plan and ask Claude Code to identify the missing index or rewrite that removes the sequential scan.

Auth Setup

Configure Supabase Auth for email, OAuth, or magic links, handle sessions correctly, and pair the flow with RLS so access is enforced in the database.

Storage Policies

Create storage buckets and generate policies that control upload, read, and delete access so private files are never exposed to anonymous users.

Edge Functions

Scaffold and write a Deno-based edge function for a Stripe webhook, a scheduled job, or server-side logic, then deploy it with the CLI.

TypeScript Type Generation

Generate types from the live schema and wire them into the Supabase client so the compiler catches a mismatch before it reaches production.

Seeding and Test Data

Generate a seed script that populates your tables with valid, related sample data so local and CI environments behave like the real app.

Realtime Subscriptions

Set up realtime subscriptions on a table and have Claude Code write the client code that reacts to inserts, updates, and deletes as they happen.

Connection Pooling

Decide between the pooler and a direct connection for a given workload, and configure the pooled connection string correctly for serverless environments.

Database Documentation

Generate a plain-language description of your schema, its relationships, and its policies so a new contributor can understand the backend quickly.

Data Model Refactoring

Plan a schema change, such as splitting a table or normalizing a column, as an ordered set of migrations that keep the app shippable at each step.

Security Review of Policies

Ask Claude Code to audit your RLS and storage policies for gaps, such as a table with RLS disabled or a policy that leaks other users' rows.

Commands & configuration

Authenticate the Supabase CLI

supabase login

Required before Claude Code can create migrations, push schema changes, or generate types.

Link the repo to a project

supabase link --project-ref your-project-ref

Connects local migrations and config to the correct remote Supabase project.

Create a new migration

supabase migration new add_orders_table

Creates a timestamped SQL file under supabase/migrations for Claude Code to fill in and you to review.

Apply migrations to the database

supabase db push

Runs pending migrations against the linked project. Review the SQL and test on staging before pushing to production.

Generate TypeScript types from the schema

supabase gen types typescript --linked > types/database.types.ts

Regenerate after any migration so the compiler catches a schema mismatch before it ships.

Deploy an edge function

supabase functions deploy your-function

Deploys a Deno edge function. Store secrets as environment variables, never in the function code.

Prompts to steal

Design a schema from a feature description

I am building the following feature. Design a normalized Postgres schema for it in Supabase: the tables, columns and types, primary and foreign keys, useful indexes, and any constraints. Explain the trade-offs and show the SQL, but do not run anything yet.

Review my existing schema

Read my current Supabase schema through the MCP server and review it. Point out missing indexes, denormalization or normalization issues, columns that should be non-nullable or constrained, and any tables that do not have Row Level Security enabled.

Write a migration for a change

Based on the current schema, write a Supabase migration that makes the following change. Produce the SQL for a new file under supabase/migrations, keep it idempotent where possible, and explain what it does. I will review before running supabase db push.

Generate an RLS policy from a rule

Enable Row Level Security on this table and write the policies so that: each user can only read and modify their own rows, and inserts must set the user id to the authenticated user. Show the SQL, then explain in plain language exactly what each policy allows and denies.

Audit my RLS policies for gaps

Review the Row Level Security policies across my Supabase tables. Identify any table with RLS disabled, any policy that could expose another user's rows, and any table where insert or update is unprotected. For each finding, explain the risk and the fix.

Write a query

Write a SQL query for my Supabase database that returns the following result. Use the real table and column names from my schema, include the necessary joins and filters, and explain how the query works.

Optimize a slow query

This query is slow. Here is the query and its EXPLAIN ANALYZE output. Identify why it is slow, tell me which index would help, and rewrite the query if a better formulation exists. Explain the reasoning before suggesting any change.

Set up Supabase Auth

Help me set up Supabase Auth in this project for email and OAuth sign-in. Show the client setup, correct session handling, how to protect routes, and how to pair the auth rules with matching RLS policies so access is enforced at the database.

Create a storage bucket with policies

I need a storage bucket for user avatars where each user can upload and replace their own avatar and anyone can read them. Create the bucket configuration and the storage policies, and explain who can upload, read, and delete.

Write an edge function for a webhook

Write a Supabase edge function that handles an incoming Stripe webhook: verify the signature, handle the relevant event types, and update the database accordingly. Read secrets from environment variables, never hardcode them, and show me how to deploy it.

Generate TypeScript types

Show me the exact supabase CLI command to generate TypeScript types from my linked project, and how to wire the generated types into the Supabase client so my queries are type-safe. Then remind me to regenerate after each migration.

Create seed data

Generate a seed script for my Supabase database that inserts realistic sample data across these tables while respecting all foreign keys and constraints. The data should be varied enough to exercise the app locally and in CI.

Set up a realtime subscription

Set up a realtime subscription on this table so my client reacts to inserts, updates, and deletes. Show the Supabase client code, explain how to filter events, and note any RLS or replication settings the table needs for realtime to work.

Choose pooler versus direct connection

My app runs in a serverless environment. Explain whether I should use the Supabase connection pooler or a direct connection, why, and give me the correctly formatted connection string for the right one. Note any settings that matter for serverless.

Refactor a table safely

I want to split this table into two related tables without downtime. Plan the change as an ordered series of migrations that keep the app working at each step, including how to backfill and cut over, and flag the highest-risk migration.

Explain what a policy actually does

Here is a Row Level Security policy. Explain in plain language exactly which rows it allows each role to read or write, walk through an example for an authenticated user and an anonymous user, and tell me if it does anything I might not expect.

Debug a failing migration

supabase db push failed with the following error. Explain what the migration was trying to do, why it failed, and the smallest correct fix. If the failure could have left the database in a partial state, tell me how to check and recover.

Add an index for a query pattern

Given these frequent queries against my Supabase tables, recommend the indexes that would speed them up. Explain the trade-off in write cost and storage for each index, and write the migration to add the ones that are clearly worth it.

Document my database

Read my Supabase schema and generate documentation for it: a short description of each table, its columns and relationships, and a summary of its Row Level Security policies. Write it so a new contributor can understand the backend without reading the SQL.

Review an edge function before deploy

Review this Supabase edge function before I deploy it. Check for hardcoded secrets, missing input validation, unhandled errors, and any database call that bypasses RLS with the service_role key. For each issue, explain the risk and the fix.

Recommended MCP servers

  • Supabase MCP Server

    The official Supabase MCP server (@supabase/mcp-server-supabase) exposes your project's tables, configuration, and read queries as tools, letting Claude Code reason against the real schema. Scope the access token to a single project and run it read-only where possible.

  • Postgres MCP Server

    A community Postgres MCP server connects Claude Code directly to a Postgres database over a connection string for read-only schema inspection and query analysis, useful when you want database access without full project scope.

Skills worth having

  • Schema Design

    Model a product's data as normalized Postgres tables with the right types, keys, and indexes before writing a single migration.

  • Migration Writing

    Turn a schema change into a clean, reversible migration that applies without locking tables or breaking existing data.

  • RLS Policy Generation

    Translate access rules into Row Level Security policies and verify exactly which rows each policy exposes.

  • Query Optimization

    Read EXPLAIN plans, spot missing indexes, and rewrite slow queries so they scale with your data.

  • Auth Configuration

    Set up Supabase Auth flows and pair them with database-level policies so access is enforced everywhere.

  • Edge Function Development

    Scaffold, write, and deploy Deno edge functions for webhooks and server-side logic with secrets kept out of code.

  • Type Generation

    Generate TypeScript types from the live schema and keep the client type-safe as the database evolves.

  • Database Security Review

    Audit RLS, storage policies, and key handling to catch tables without protection and rules that leak data.

Troubleshooting

Keep it safe

  • Never expose the service_role key client-side. It bypasses Row Level Security and grants full database access, so keep it server-only and use the anon key in any browser or client code.
  • Enable Row Level Security on every table. A table without RLS is readable and writable by anyone with the anon key, so turn it on and add explicit policies before you ship.
  • Store keys as secrets, never in code. Keep the service_role key, database URL, and any tokens in environment variables or a secrets manager, and add them to .gitignore.
  • Rotate keys deliberately and after any exposure. Rotate the service_role key on a schedule and immediately if it is ever committed, logged, or shared, then update it everywhere it is used.
  • Grant least privilege. Scope MCP personal access tokens to a single project, prefer read-only access for inspection, and give each workflow only the permissions it needs.
  • Keep a human in the loop on production. Review every migration, policy, and edge function before it runs against production, and never let Claude Code apply schema changes to a live database without your approval.

Supabase + Claude Code: FAQ

What is the Claude Code Supabase integration?

It is a workflow that lets Claude Code work directly with your Supabase backend. Claude Code can design your Postgres schema, write and run migrations, generate Row Level Security policies, write queries, configure auth and storage, build edge functions, and generate TypeScript types, using your real database as the source of truth. It enhances your existing Supabase workflow rather than replacing it.

How do I connect Claude Code to Supabase?

There are two paths. Connect the official Supabase MCP server so Claude Code can inspect tables, run read-only queries, and read project configuration in context. Or install and authenticate the supabase CLI with supabase login and link your project, so Claude Code can create migrations, run supabase db push, and generate types. Many developers use both together.

Can Claude Code write SQL migrations for Supabase?

Yes. Claude Code reads your current schema, then writes a migration file under supabase/migrations that adds the tables, columns, or constraints you asked for. You review the generated SQL, test it against a local or staging database, and apply it with supabase db push when you are satisfied it is correct.

Can Claude Code generate Row Level Security policies?

Yes. Describe an access rule in plain English, such as users can only read their own rows, and Claude Code enables RLS and writes the select, insert, update, and delete policies. It can also explain exactly which rows each policy exposes and audit your existing policies for gaps before you rely on them.

Is it safe to give Claude Code database access?

It is safe when you follow least privilege. Scope the MCP access token to a single project, prefer read-only access for inspection, and keep the service_role key server-side only. Claude Code produces reviewable SQL that you approve before it runs, so a human stays in control of anything that touches production data.

Can Claude Code generate TypeScript types from my schema?

Yes. Claude Code can run supabase gen types typescript against your linked project to produce types that match the live schema, then wire them into the Supabase client so your queries are type-safe. Regenerate the types after each migration so the compiler catches any mismatch before it ships.

Can Claude Code build Supabase edge functions?

Yes. Claude Code can scaffold and write a Deno-based edge function for a webhook, scheduled job, or server-side logic, and deploy it with supabase functions deploy. It keeps secrets in environment variables rather than in the function code, which is essential because edge functions often use privileged keys.

Should I use the connection pooler or a direct connection?

Use the connection pooler for serverless or high-concurrency environments where many short-lived functions each open a connection, since the pooler prevents connection exhaustion. Use a direct connection for long-lived servers and for migration tooling. Claude Code can tell you which to use for your setup and give you the correctly formatted connection string.

Go deeper

More integrations

Build Your Backend Faster With Claude Code

Join Claude Code Club to access practical tutorials, prompts, skills, MCP guides, workflows, templates, and real builds designed to help you ship a production Supabase backend with Claude Code.

Related: what is Claude Code, glossary, and use cases.