Firebase is the default backend for many Flutter apps, and setting it up is full of steps that are easy to get subtly wrong: the wrong project, rules left open, a key in the wrong place. An AI agent is quick at the typing and bad at knowing which of these mistakes matter. This page gives a setup sequence with Claude Code, using Firebase’s own documentation, read on the day this post was written, and the practices MobileKit’s Firebase setup follows. The rules about what an agent should never do alone are the important part.
1. Decide the projects first
Create at least two Firebase projects: one for development and one for production. Never point a development build at production data. MobileKit’s setup keeps a dev project and a prod project from the start, and does not create the production project until it is needed. This pairs with the dev and prod flavors in Flutter project setup with Claude Code.
2. Connect the app with FlutterFire
Firebase’s Flutter setup guide gives the sequence:
firebase login
dart pub global activate flutterfire_cli
flutterfire configure
According to Firebase’s documentation, flutterfire configure registers your Flutter app for each platform you select, and “creates a Firebase configuration file (firebase_options.dart) and adds it” to your project. Your app then initialises Firebase with that file at startup.
Do these steps with Claude Code, but run firebase login yourself: the login is an interactive step tied to your account. For flavors, run flutterfire configure once per flavor with flavor-specific outputs, so each build talks to the right project.
3. Lock the rules before you write data
Firebase’s rules documentation says the default for Cloud Firestore and Realtime Database in Locked mode is to deny access to all users, and that Test mode allows anyone access. It warns that with open rules your data is publicly accessible even before you launch.
A minimal sound pattern, from the documentation: allow access only to signed-in users, then narrow it to the owner of each document. For example, a user reads and writes only their own users/{uid} data, and nobody writes entitlement records from the client. Write the intent in plain words first, then the rules, then a test for each rule, run as a signed-out user and as a second signed-in user.
Ask Claude Code to write the rules and the tests, and then read them yourself. A rule that allows all reads or all writes is the most serious mistake available. See the mobile app security checklist.
4. Add App Check
Firebase’s documentation says App Check “helps protect your app backends from abuse by preventing unauthorized clients from accessing your backend resources.” It is one of the abuse checks worth turning on before release, especially for any function that costs money per call. Use debug tokens in development and make sure they are removed from release builds.
5. Crash reporting and analytics
Add crash reporting early, so every beta build is observed. Make sure the release build uploads debug symbols to the crash reporter, or the stack traces will be unreadable. See the weekly app monitoring routine for how to read the numbers.
6. Script it; do not click through consoles
MobileKit’s rule is “never click through consoles for this”. It keeps a bundled setup script in the repo that checks state and then changes it, so every step is repeatable and recorded: APIs, authentication, App Check, a budget alert, rules, functions and configuration. Add new setup as a step in that script, never as a one-off command, and keep a list of what cannot be scripted.
What an agent must not do alone
These are the points to hold firm on:
- Do not let it run setup against production without your approval. MobileKit’s procedure runs a dry run first, shows you the output and asks for explicit approval, because a real run deploys to a live project and grants roles to the functions’ service account.
- Never paste secrets into the chat. Service account files, signing passwords and private keys stay out of prompts. The agent should read them from a git-ignored file or the environment.
- Do not let it relax rules to make an error go away. A “permission denied” error is information. Ask why, and fix the rule or the code, not by opening access.
- Keep feature flags for risky features off until their checks pass. MobileKit keeps an AI feature’s flag off in its remote configuration until its safety and cost checks are done.
- Set a budget alert on the billing account before you enable anything that costs money.
A prompt sequence
- “Read the Firebase Flutter setup guide and list the steps. Do not run anything.”
- “Show me the exact commands for the dev project. I will run the login myself.”
- “Write Firestore rules where a user can only read and write their own documents, and write tests for them. Show me the rules and the tests before you run anything.”
- “List every secret or key you would need for this step, and where it should live. Do not ask me to paste any of them.”
Where MobileKit fits
The pack’s Firebase setup is a script with a dry run, an explicit approval gate and a standard operating procedure for the steps it cannot automate, and the security pass checks the rules, functions and abuse controls before release. The whole route is in Build a Flutter app with Claude Code.
Related: the mobile app requirements document template.
Sources read on the day this post was written: Firebase: add Firebase to your Flutter app, Firebase security rules basics and Firebase App Check.