If your Supabase bill keeps creeping and you can't say exactly why, this is the prompt to run. Point Claude at your code and it audits everything — SELECT *s, N+1 loops, missing indexes, runaway realtime subscriptions, orphaned storage, expensive RLS policies — then hands back a ranked, copy-paste fix list with estimated monthly savings.
How to run it
- Give Claude your code. Connect your GitHub repo (via the GitHub connector) so it can read the whole project, or paste the relevant files/folders into the chat.
- Paste the prompt below and send.
- Work the checklist it gives you top-down. It ranks every fix by ROI, so you start with the change that saves the most for the least effort.
The prompt
Copy it, paste it into Claude with your codebase in context:
Act as a senior backend engineer and Supabase infrastructure expert. Your only objective is to minimize my Supabase bill while maintaining or improving performance, scalability, and reliability. Perform a complete audit of my project and inspect every part of the stack. 1. Backend Query Audit - Find every query returning more data than the UI actually needs. - Replace SELECT * with explicit columns. - Remove unnecessary joins. - Remove duplicate queries. - Remove repeated fetches. - Show optimized replacements. 2. N+1 Query Audit - Find every N+1 query. - Find loops making database requests. - Batch queries where possible. - Convert repeated queries into joins or RPCs. - Explain expected performance improvements. 3. SQL Optimization - Analyze every SQL query. - Identify missing indexes. - Detect full table scans. - Detect inefficient WHERE clauses. - Detect slow ORDER BY operations. - Detect inefficient JOINs. - Generate the exact CREATE INDEX statements needed. - Estimate query speed improvements. 4. Database Connection Audit - Find connections that are never closed. - Find abandoned transactions. - Find unnecessary new connections. - Check connection pooling. - Check serverless connection behavior. - Recommend improvements that reduce concurrent database connections. 5. Background Job Audit - Find every cron job. - Find every queue worker. - Find polling loops. - Find scheduled tasks. - Find background processes that continue running unnecessarily. - Ensure no hidden workers are keeping database connections alive. 6. Supabase Realtime Audit - Find duplicate subscriptions. - Find subscriptions that never unsubscribe. - Find listeners attached to inactive screens. - Find subscriptions that are too broad. - Recommend more efficient subscription patterns. 7. Storage Audit - Find orphaned files. - Find duplicate uploads. - Find temporary files that were never deleted. - Find unused profile images. - Find files without database references. - Estimate reclaimable storage. 8. Authentication Audit - Find repeated getUser() calls. - Find repeated getSession() calls. - Find unnecessary auth refreshes. - Find duplicate authentication requests. - Recommend caching where appropriate. 9. Edge Function Audit - Analyze every Edge Function. - Find duplicate database queries. - Find unnecessary API calls. - Find expensive operations. - Find long-running executions. - Recommend optimizations to reduce execution time and cost. 10. Frontend Data Fetching Audit - Analyze every screen. - List every Supabase request. - Find duplicate requests. - Find requests that should run in parallel. - Find requests that should be cached. - Find requests that should only happen once. - Rewrite inefficient loading strategies. 11. Row Level Security Audit - Analyze every RLS policy. - Detect policies causing unnecessary scans. - Detect expensive EXISTS statements. - Detect missing indexes used by policies. - Recommend faster policies without weakening security. 12. API Audit - Find unnecessary backend endpoints. - Find duplicate endpoints. - Find repeated business logic. - Find expensive serialization. - Recommend simplifications. 13. React Performance Audit - Find unnecessary rerenders. - Find components repeatedly fetching data. - Find repeated useEffect calls. - Find unnecessary state updates. - Recommend memoization where appropriate. 14. Caching Audit - Identify every place where caching could reduce database reads. - Recommend client caching. - Recommend server caching. - Recommend edge caching. - Recommend cache invalidation strategies. 15. Network Audit - Find oversized payloads. - Find duplicate API calls. - Find unnecessary retries. - Find unnecessary polling. - Recommend batching requests. 16. Cost Audit Analyze all Supabase usage including: - Database reads - Database writes - Storage - Bandwidth - Realtime - Edge Functions - Authentication - Database connections Rank the biggest cost drivers from highest to lowest. For EVERY issue you find provide: - Severity (Critical / High / Medium / Low) - Why it costs money - Exact file(s) and code location(s) - Current implementation - Optimized implementation - Replacement code - Estimated monthly savings - Expected performance improvement - Any tradeoffs Finally: 1. Rank every optimization by ROI. 2. Estimate the total monthly savings. 3. Estimate the total performance improvement. 4. Generate a checklist ordered from highest priority to lowest priority. 5. Continue auditing until you cannot find any additional opportunities to reduce Supabase costs or improve backend performance.
What it actually checks
Sixteen audits, so nothing hides. Here's what each one catches and why it costs you money:
SELECT * pulling columns you never render, duplicate fetches, needless joins — the quiet everyday bloat on every read.
Loops that hit the database once per item. The classic silent killer — 1 list = 200 queries. Batched into one, it's a massive win.
Full table scans, slow ORDER BYs, bad WHEREs. It writes the exact CREATE INDEX statements and estimates the speedup.
Connections never closed, abandoned transactions, serverless functions each opening their own — the thing that quietly maxes your pool.
Cron jobs, queue workers, polling loops still running and holding connections open when nothing needs them.
Duplicate subscriptions, listeners that never unsubscribe, screens still subscribed after you left them. Realtime bills add up fast.
Orphaned files, duplicate uploads, temp files never deleted, images with no DB reference — and how much space you can reclaim.
Repeated getUser() / getSession() calls and needless token refreshes firing on every render, when one cached call would do.
Duplicate queries inside functions, unnecessary API calls, long-running executions — you pay per execution and per second.
Per-screen: every request, which are duplicates, which should run in parallel, which should be cached or fire only once.
RLS policies causing full scans and expensive EXISTS checks — often the hidden reason simple queries are slow and pricey.
Duplicate endpoints, repeated business logic, expensive serialization you can simplify.
Unnecessary rerenders and re-fetches, repeated useEffects — the front-end habits that trigger extra DB reads.
Every place a client / server / edge cache would kill a repeat database read, plus how to invalidate it safely.
Oversized payloads, duplicate calls, needless retries and polling — batch them and cut bandwidth.
Finally ranks your actual cost drivers (reads, writes, storage, bandwidth, realtime, functions, auth, connections) highest to lowest.
Before you apply anything
Treat the output as a senior engineer's PR review, not gospel. The savings are estimates — verify them against your real Supabase usage dashboard. And never run a CREATE INDEX straight into production blind: test it in staging first, because a wrong or redundant index can slow writes. Claude finds the opportunities fast; you make the call on each one.
One more tip for big codebases: if the project is large, run the audit one section at a time (paste the prompt, then say "start with sections 1–4"). You'll get deeper, more accurate results than trying to swallow the whole repo in a single pass.
Want the next one first?
The Input Daily — a 5-minute AI brief every weekday. 3 stories that matter, 1 tool worth trying, 1 prompt to steal.
Free. Every morning. Unsubscribe in one click. Privacy Policy.