CostGuardCatch expensive Firebase and React patterns before they hit production — and before they hit your bill. CostGuard is a VS Code extension that detects runaway Firestore reads, missing listener cleanup, render loops, and other cost-heavy patterns as you write code. It adds inline squiggles, a per-file risk score, and optional gates that block bad code from being committed, merged, or deployed. FeaturesLive diagnosticsSquiggles appear as you type (500ms debounce). No save required. Risk scoringEvery flagged file gets a score and a breakdown by risk category, visible inline and in the status bar.
Deployment gatesThree layers that stop risky code before it ships:
Installation
Setup WizardOn first install (and on every upgrade), a QuickPick appears ~1.5 seconds after VS Code loads:
Select what you want, press Enter. CostGuard writes all the necessary files automatically — no manual path setup. To re-run the wizard at any time: Command Palette → What it detectsFCG001 — Unstable useEffect dependency
|
| Rule | Risk categories | Points |
|---|---|---|
| FCG001 Unstable deps | Cost + Memory Leak | 10 |
| FCG002 Unbounded read | Cost + Scalability | 18 |
| FCG003 Listener UI dep | Cost | 12 |
| FCG004 No snapshot cleanup | Memory Leak | 22 |
| FCG005 Read in loop | Cost + Scalability | 20 |
| FCG006 No interval cleanup | Memory Leak | 18 |
Risk levels per category
| Points | Level |
|---|---|
| 0 | LOW |
| 1 – 24 | MEDIUM |
| 25+ | HIGH |
Deployment gates
Pre-commit hook
Blocks git commit if staged files contain HIGH risk violations.
CostGuard
────────────────────────────────────────────────────────────
src/invoices.tsx
Risk 58/100 | Cost: HIGH | Scalability: LOW | Memory Leak: HIGH
✗ Line 42 [FCG002] Unbounded Firestore read — add .limit()
✗ Line 71 [FCG004] onSnapshot missing cleanup return
────────────────────────────────────────────────────────────
2 violations in 1 file
✗ Blocked — fix HIGH risk violations before proceeding.
Installed automatically by the setup wizard into .git/hooks/pre-commit.
GitHub Actions PR gate
Runs on every pull request and posts a risk card comment. Fails the required check if HIGH risk violations are found, blocking the merge.
| File | Score | Cost | Scalability | Memory Leak | Violations |
|---|---|---|---|---|---|
src/invoices.tsx |
🔴 58/100 | 🔴 HIGH | 🟢 LOW | 🔴 HIGH | 2 |
The workflow is written to .github/workflows/costguard.yml by the setup wizard. Requires costguard in devDependencies (added automatically).
Deploy gate
Runs before firebase deploy or any deploy script and blocks if MEDIUM+ risk violations are found.
npm run predeploy # or wired via firebase.json predeploy hook
CLI
The analyzer is also available as a command-line tool for use in scripts and CI pipelines.
# Scan a directory
node out/cli.js src/
# Scan only staged files (for pre-commit hooks)
node out/cli.js --staged
# Output JSON for downstream tooling
node out/cli.js src/ --json
# GitHub Actions annotation format
node out/cli.js src/ --format=github
# Set the blocking threshold (default: HIGH)
node out/cli.js src/ --max-risk=MEDIUM
Exit codes: 0 = no violations above threshold · 1 = violations found
Configuration
| Setting | Default | Description |
|---|---|---|
costGuard.enable |
true |
Enable / disable all diagnostics |
Toggle from Settings → search costGuard, or add to your workspace settings.json:
{
"costGuard.enable": false
}
Commands
| Command | Description |
|---|---|
CostGuard: Setup |
Re-run the feature setup wizard |
CostGuard: Show Risk Score Details |
Show full risk breakdown for the active file |