Claude Skills Guide

Claude Code with Supabase Backend Integration Guide

Integrating Claude Code with Supabase provides a powerful workflow for building backend services. This guide walks through connecting Claude Code to your Supabase project, executing database operations, and deploying serverless functions. For project structure, migration strategies, RLS policy patterns, and CI/CD pipelines, see the Claude Code Supabase Backend Development Workflow Tips guide.

Prerequisites

You need a Supabase project with the following credentials:

Store these in your environment variables:

export SUPABASE_URL="https://your-project.supabase.co"
export SUPABASE_SERVICE_KEY="your-service-role-key"

Setting Up the Connection

Create a simple Supabase client in your project:

import { createClient } from '@supabase/supabase-js';

const supabase = createClient(
  process.env.SUPABASE_URL,
  process.env.SUPABASE_SERVICE_KEY
);

The service role key bypasses Row Level Security (RLS), so use it only in server-side code or Claude Code workflows where you need full database access.

Database Operations with Claude Code

Claude Code can execute SQL queries directly against your Supabase database. Here’s how to perform common operations:

Inserting Records

async function createUser(email: string, name: string) {
  const { data, error } = await supabase
    .from('users')
    .insert({ email, name })
    .select()
    .single();
  
  if (error) throw error;
  return data;
}

Querying with Filters

async function getUserByEmail(email: string) {
  const { data, error } = await supabase
    .from('users')
    .select('*')
    .eq('email', email)
    .single();
  
  if (error) return null;
  return data;
}

Real-time Subscriptions

Supabase provides real-time capabilities. Subscribe to database changes:

const channel = supabase
  .channel('users-changes')
  .on(
    'postgres_changes',
    { event: 'INSERT', schema: 'public', table: 'users' },
    (payload) => console.log('New user:', payload.new)
  )
  .subscribe();

For real-time features, consider using the frontend-design skill to build reactive UI components that update automatically when data changes.

Authentication Integration

Supabase handles authentication with multiple providers. Claude Code can manage user sessions and protected routes.

Sign Up New Users

async function signUpUser(email: string, password: string) {
  const { data, error } = await supabase.auth.signUp({
    email,
    password,
  });
  
  if (error) throw error;
  return data;
}

Session Management

async function signInUser(email: string, password: string) {
  const { data, error } = await supabase.auth.signInWithPassword({
    email,
    password,
  });
  
  if (error) throw error;
  return data.session;
}

The tdd skill pairs well here—write tests for your authentication flow before implementing to ensure secure user management.

Edge Functions

Supabase Edge Functions run Deno at the edge and integrate tightly with your database. For detailed examples of writing Edge Functions with full error handling, authentication checks, and deployment patterns, see the Claude Code Supabase Backend Development Workflow Tips guide.

The short form: create a function file in supabase/functions/<name>/index.ts, implement your handler, then deploy:

supabase functions deploy <function-name>

Working with Storage

Supabase Storage handles file uploads. Here’s a practical workflow:

async function uploadFile(bucket: string, path: string, file: File) {
  const { data, error } = await supabase.storage
    .from(bucket)
    .upload(path, file, {
      cacheControl: '3600',
      upsert: false,
    })
  
  if (error) throw error;
  return data;
}

async function getPublicUrl(bucket: string, path: string) {
  const { data } = supabase.storage
    .from(bucket)
    .getPublicUrl(path)
  
  return data.publicUrl;
}

Combine this with the pdf skill to generate reports, store them in Supabase Storage, and share via public URLs.

Database Migrations

When schema changes are needed, use the Supabase CLI:

supabase migration new add_user_preferences

Edit the generated SQL file, then apply:

supabase db push

Claude Code can help generate migration scripts by analyzing your existing schema and suggesting improvements.

Best Practices

  1. Use RLS everywhere — Enable Row Level Security on all tables, even during development
  2. Separate service and anon keys — Use service role only in trusted environments
  3. Handle errors gracefully — Always check for Supabase errors in your callbacks
  4. Use connection pooling — For high-traffic applications, configure connection pooling
  5. Monitor with Supabase logs — Check the dashboard for query performance and errors

Using Claude Skills Together

The supermemory skill helps maintain context across sessions when working on complex Supabase projects. Document your database schema, API endpoints, and edge function configurations.

For testing, the tdd skill generates comprehensive test suites for your Supabase operations. Combined with proper RLS policies, you get a reliable backend that passes security audits.

The frontend-design skill complements backend work by generating UI components that connect smoothly to your Supabase data layer.

Built by theluckystrike — More at zovo.one