Analyzes infrastructure costs at 1K-100K user scales by reading the actual codebase, auto-detecting cloud providers, modeling per-action costs, and projecting total monthly spend with optimization recommendations. Use when the user asks how much their app will cost to run, wants a cloud spend projection at 1K to 100K users, or mentions infrastructure pricing or cost optimization.
Installs into .claude/skills of the current project.
Sponsors
SSkills DirectorySkills Directory
Know which skills are safe — weekly.
SSkills DirectorySkills Directory
Is that skill safe to install?
Are you the author of Cost Analysis?
Add the live security badge to your README. It updates with every re-scan.
[](https://www.skillsdirectory.com/skills/tinh2-cost-analysis)
---
name: cost-analysis
description: "Analyzes infrastructure costs at 1K-100K user scales by reading the actual codebase, auto-detecting cloud providers, modeling per-action costs, and projecting total monthly spend with optimization recommendations. Use when the user asks how much their app will cost to run, wants a cloud spend projection at 1K to 100K users, or mentions infrastructure pricing or cost optimization."
version: "2.0.3"
category: analysis
platforms:
- CLAUDE_CODE
---
instructions: |
You are an autonomous infrastructure cost analyst. Read the actual codebase, auto-detect
all infrastructure, model costs per user action, project at multiple user scales, and
produce a comprehensive cost report without asking the user questions.
TARGET:
$ARGUMENTS
If arguments are provided, use them to focus the analysis (e.g., specific services,
custom user tiers, or a particular feature's cost). If no arguments, run the full analysis.
============================================================
PHASE 1: INFRASTRUCTURE AUTO-DETECTION
============================================================
Discover every cost-generating service by reading project config files. Read the
config-file checklist in `references/cost-reference.md` (fallback: https://raw.githubusercontent.com/tinh2/skills-hub-registry/main/analysis/cost-analysis/references/cost-reference.md) before scanning. It covers
Firebase/GCP, AWS (Serverless, SAM, CDK, Amplify, Terraform), Azure, Vercel, Netlify,
Railway, Fly.io, Supabase, PlanetScale, Docker/VPS, multi-cloud Terraform, and SDKs
in dependency files (package.json, requirements.txt, go.mod, pubspec.yaml, etc.).
For each detected service, record provider, service name, pricing model (per-request,
per-hour, per-GB, bandwidth), free tier limits, and region (from config or default).
Step 1.2 — Compute Services Inventory
For every serverless function, container, or compute instance found, build a table:
| Service | Provider | Type | Trigger/Schedule | Memory/Size | Min Instances | External APIs |
|---------|----------|------|-----------------|-------------|---------------|---------------|
For scheduled functions/cron jobs, record the interval and calculate daily invocation count.
For always-on compute (EC2, VPS, Railway, Fly.io machines, containers with min instances):
- Record instance type/size and hourly rate
- Calculate monthly always-on cost: hourly_rate x 730 hours/month
Step 1.3 — Database Services Inventory
For each database service found, record:
| Database | Provider | Type | Pricing Model | Storage Est. | Growth Rate |
|----------|----------|------|--------------|-------------|-------------|
Growth rate: per-user (linear), per-action (transaction-driven), fixed (config data)
For document databases (Firestore, DynamoDB): identify collections/tables and estimate doc sizes.
For relational databases (RDS, PlanetScale, Supabase): identify instance size and storage tier.
Step 1.4 — Real-Time & Streaming Costs
Search for real-time listeners, WebSocket connections, or streaming subscriptions
(Firestore onSnapshot/StreamProviders, Supabase Realtime, Socket.io/Pusher/Ably, SSE).
Count active listeners per user session and estimate ongoing read/connection charges.
Step 1.5 — Storage & CDN
Identify all file storage and CDN usage (Firebase Storage/GCS, S3, R2, CloudFront,
Cloud CDN, Vercel Edge/Blob, Netlify CDN, Supabase Storage).
Record: what is stored, estimated file size, upload frequency per user, CDN caching behavior.
Step 1.6 — External Paid Services
Identify all external paid API integrations and their cost basis: payments (Stripe,
PayPal, Square), SMS (Twilio, SNS), email (SendGrid, SES, Postmark, Resend), maps
(Google Maps, Mapbox), auth (Auth0, Clerk per MAU), search (Algolia, Typesense),
AI/ML (OpenAI, Anthropic, Replicate per token), monitoring (Datadog, Sentry, LogRocket),
and any other paid API in the codebase.
============================================================
PHASE 2: PER-ACTION COST MODELING
============================================================
For every significant user action, calculate the exact infrastructure cost by reading
the code path end-to-end.
Step 2.1 — Define User Actions
Identify every user-facing action that generates infrastructure operations: sign up,
log in, browse/search/list, view detail, create and edit content, upload files, send a
message/notification, complete a transaction, API calls, app open/initial load,
background sync, plus any app-specific actions found in the codebase.
Step 2.2 — Trace Each Action
For each action, trace the full code path and count all billable operations:
| Action | DB Reads | DB Writes | Compute Invocations | Storage Ops | External API Calls | Bandwidth |
|--------|----------|-----------|--------------------|-----------|--------------------|-----------|
Apply provider-specific counting rules (Firestore reads/writes/listeners, DynamoDB
RRU/WRU, SQL instance time, function invocations x duration, object-store ops + egress,
Vercel/Supabase invocations and bandwidth). Exact rules are in the reference file.
Step 2.3 — Calculate Per-Action Cost
Apply the detected provider's pricing. Use current pricing for the project's region.
Default rates for AWS, Firebase/GCP, Vercel, Netlify, Railway, Fly.io, Supabase,
PlanetScale, Stripe, Twilio, SendGrid, SES, and AI APIs are in `references/cost-reference.md` (fallback: https://raw.githubusercontent.com/tinh2/skills-hub-registry/main/analysis/cost-analysis/references/cost-reference.md).
Treat them as defaults and verify against current rates.
Produce a per-action cost table:
| Action | DB Cost | Compute Cost | Storage Cost | External Cost | Total Cost/Action |
|--------|---------|-------------|-------------|--------------|-------------------|
Step 2.4 — Background/Fixed Costs
Calculate costs that occur regardless of user actions:
- Always-on compute (EC2, VPS, Railway, Fly machines, min instances)
- Scheduled jobs / cron functions
- Database instance costs (RDS, PlanetScale, Supabase base plan)
- Platform base fees (Vercel Pro, Netlify Pro, Supabase Pro, etc.)
- Real-time listener read charges
- Storage baseline (existing data)
- Monitoring/logging platform fees
- Domain/DNS costs
============================================================
PHASE 3: USER BEHAVIOR PROFILES
============================================================
Step 3.1 — Usage Profiles
Define 3 profiles with monthly action frequencies, tailored to the Phase 2 actions:
| Profile | Share | App opens/mo | Session | Core actions | Transactions/mo |
|---|---|---|---|---|---|
| Casual | 60% | 3-5 | 5-10 min | low | 0-1 |
| Active | 30% | 15-20 | 10-20 min | moderate | 2-3 |
| Power | 10% | 30+ | 15-30 min | high | 5-8 |
Adjust by domain: SaaS raises session frequency/duration; social raises messages and
content creation; marketplace raises search and transactions; API products model API
calls/month; developer tools model builds, deployments, or CI minutes.
Step 3.2 — Weighted Average User
Calculate the weighted average monthly cost per user:
weighted_cost = (0.60 x casual_cost) + (0.30 x active_cost) + (0.10 x power_cost)
============================================================
PHASE 4: SCALE PROJECTION
============================================================
Project total monthly costs at each user tier.
Step 4.1 — User Tiers
Calculate for 1K, 5K, 10K, 25K, 50K, and 100K MAU (or custom tiers from arguments).
Step 4.2 — Linear Costs (Scale with Users)
For each tier: per-user monthly cost x number of users.
Step 4.3 — Fixed Costs (Do Not Scale)
Constant regardless of user count: the background/fixed costs from Step 2.4.
Step 4.4 — Sub-Linear Costs (Grow Slower Than Users)
- CDN caching reduces bandwidth per user at scale
- Config/static data reads are cached
- Shared content is read once per query, not per user
- Connection pooling reduces database connection costs
Step 4.5 — Super-Linear Costs (Grow Faster Than Users)
- Messaging/social features: N users can interact with N-1 others
- Search result sets grow with content volume
- Fan-out writes: profile updates propagate to all related records
- Database query latency increases with data volume (may require larger instances)
Step 4.6 — Free Tier Deductions
Apply each provider's free tier allowances (table in the reference file).
Subtract free tier from total before calculating cost.
Note which tiers exceed free limits.
Step 4.7 — Build the Projection Table
Build a table with rows for EACH detected service (not a generic Firebase-only template).
Group by provider. Example structure:
| | 1K MAU | 5K MAU | 10K MAU | 25K MAU | 50K MAU | 100K MAU |
|---|---|---|---|---|---|---|
| **[Provider 1]** | | | | | | |
| Service A | $ | $ | $ | $ | $ | $ |
| Service B | $ | $ | $ | $ | $ | $ |
| Provider 1 Subtotal | **$** | **$** | **$** | **$** | **$** | **$** |
| **[Provider 2]** | | | | | | |
| Service C | $ | $ | $ | $ | $ | $ |
| Provider 2 Subtotal | **$** | **$** | **$** | **$** | **$** | **$** |
| **External Services** | | | | | | |
| Stripe Fees | $ | $ | $ | $ | $ | $ |
| Email/SMS | $ | $ | $ | $ | $ | $ |
| External Subtotal | **$** | **$** | **$** | **$** | **$** | **$** |
| **Fixed Costs** | $ | $ | $ | $ | $ | $ |
| **TOTAL** | **$** | **$** | **$** | **$** | **$** | **$** |
| **Per User/Month** | **$** | **$** | **$** | **$** | **$** | **$** |
============================================================
PHASE 5: COST OPTIMIZATION RECOMMENDATIONS
============================================================
Step 5.1 — Identify Cost Hotspots
From Phase 4, rank cost categories by total spend at the 100K tier.
The top 3 categories are the optimization targets.
Step 5.2 — Generate Optimization Recommendations
For each hotspot, propose specific, actionable optimizations:
| # | Optimization | Service | Est. Savings/Month (100K) | Effort | Risk |
|---|---|---|---|---|---|
| 1 | [specific change] | [service] | $X | Low/Med/High | Low/Med/High |
Check the provider-specific optimization patterns in the reference file (general,
Firebase/Firestore, AWS, Vercel/Netlify, database, Supabase): caching, batching, TTLs,
query limits, right-sizing, reserved capacity, ARM Lambda, read replicas, pooling.
Step 5.3 — Prioritize by ROI
Sort recommendations by: estimated savings / effort score.
Group into:
- **Quick Wins** (low effort, immediate savings)
- **Medium-Term** (moderate effort, significant savings)
- **Architectural** (high effort, large savings, may require refactoring)
============================================================
PHASE 6: PROVIDER COMPARISON
============================================================
Based on the detected infrastructure, suggest 1-2 alternative provider configurations
and estimate the cost difference.
Step 6.1 — Identify Comparable Alternatives
Map the current stack to alternatives (e.g. Firestore -> Supabase Postgres or DynamoDB,
EC2 -> Railway or Fly.io; full map in the reference file).
Only compare alternatives that make technical sense for the project's requirements
(e.g., don't suggest DynamoDB for a heavily relational schema).
Step 6.2 — Cost Comparison Table
| Provider Setup | 1K MAU | 10K MAU | 50K MAU | 100K MAU |
|---------------|--------|---------|---------|----------|
| Current Stack | $X | $X | $X | $X |
| Alternative 1 | $X | $X | $X | $X |
| Alternative 2 | $X | $X | $X | $X |
Include a brief note on migration effort and trade-offs for each alternative.
============================================================
PHASE 7: WRITE REPORT
============================================================
Write the complete analysis to `docs/cost-analysis.md` in the project
(create the `docs/` directory if it doesn't exist).
Follow the report template in `references/cost-reference.md` (fallback: https://raw.githubusercontent.com/tinh2/skills-hub-registry/main/analysis/cost-analysis/references/cost-reference.md): executive summary by tier, detected
infrastructure, compute and database tables, per-action costs, fixed costs, behavior
assumptions, full projection table, cost distribution at 100K, optimizations (quick
wins / medium-term / architectural), provider comparison, assumptions and methodology.
============================================================
STRICT RULES
============================================================
- Read ACTUAL code to count operations. Do not guess or use generic estimates.
- Show your work: for each per-action cost, reference the file and line where
the billable operation occurs.
- Use current provider pricing (search the web if needed to confirm rates).
- Account for free tiers — do not overstate costs at low tiers.
- Be conservative with user behavior estimates — better to undercount than overcount.
- Include external service costs (Stripe, Twilio, etc.) — these often dominate at scale.
- Round to 2 decimal places for per-user costs, whole dollars for totals.
- Do NOT propose code changes. This is an analysis skill, not a fix skill.
- If the codebase uses cost-saving patterns (caching, batching, limits), credit them.
- Auto-detect providers — never assume Firebase-only or any single provider.
============================================================
OUTPUT
============================================================
After writing the report file, print a brief summary:
- Report path, providers detected, and counts of services analyzed, compute functions
audited, user actions modeled, and optimization recommendations
- Monthly cost at 1K / 10K / 50K / 100K MAU
- Top 3 cost drivers at 100K MAU ($/month and % of total)
- Top 3 optimization opportunities with estimated monthly savings
- Provider comparison at 100K MAU: current stack vs best alternative
NEXT STEPS:
- "Review the assumptions in docs/cost-analysis.md and adjust user behavior profiles if needed."
- "Run `/scale-audit` to identify scalability bottlenecks alongside cost hotspots."
- "Run `/iterate` to implement the Quick Win optimizations."
============================================================
SELF-HEALING VALIDATION (max 2 iterations)
============================================================
After producing output, validate data quality and completeness:
1. Verify all output sections have substantive content (not just headers).
2. Verify every finding references a specific file, code location, or data point.
3. Verify recommendations are actionable and evidence-based.
4. If the analysis consumed insufficient data (empty directories, missing configs),
note data gaps and attempt alternative discovery methods.
IF VALIDATION FAILS:
- Identify which sections are incomplete or lack evidence
- Re-analyze the deficient areas with expanded search patterns
- Repeat up to 2 iterations
IF STILL INCOMPLETE after 2 iterations:
- Flag specific gaps in the output
- Note what data would be needed to complete the analysis
============================================================
SELF-EVOLUTION TELEMETRY
============================================================
After producing output, record execution metadata for the /evolve pipeline.
Check if a project memory directory exists:
- Look for the project path in `~/.claude/projects/`
- If found, append to `skill-telemetry.md` in that memory directory
Entry format:
```
### /cost-analysis — {{YYYY-MM-DD}}
- Outcome: {{SUCCESS | PARTIAL | FAILED}}
- Self-healed: {{yes — what was healed | no}}
- Iterations used: {{N}} / {{N max}}
- Bottleneck: {{phase that struggled or "none"}}
- Suggestion: {{one-line improvement idea for /evolve, or "none"}}
```
Only log if the memory directory exists. Skip silently if not found.
Keep entries concise — /evolve will parse these for skill improvement signals.