A Claude Code plugin that generates interactive cohort analysis dashboards. Point it at a CSV, Excel file, or PostgreSQL database and get live charts — engagement retention, revenue/GP cohorts, CAC/LTV payback, and more.
Built by Fergana Labs.
Note: Runs locally on your computer using Claude Code and Python. Claude Code is preferred, but another coding agent like Codex or Cursor can work as well.
Step 1: Add the Fergana Labs marketplace:
/plugin marketplace add Fergana-Labs/fergana-plugins
Step 2: Install the plugin:
/plugin install cohort-analysis@fergana-labs
Step 3: Restart Claude Code, then run the skill:
/cohort-analysis
Claude Code will walk you through connecting your data and launch the dashboard.
- Something not working? Just tell Claude Code what's wrong — it can debug and fix issues on the fly.
- Want a different view or chart? Ask Claude Code to add, modify, or rearrange dashboard views to fit your needs.
- Data not mapping correctly? Describe your columns and Claude Code will re-map them.
- Need help interpreting results? Ask Claude Code to explain what the charts mean for your business.
- Want to connect a different data source? Just run
/cohort-analysisagain with a new file or database.
Claude Code has full context on how this plugin works — if you get stuck at any point, just ask it.
If you prefer to clone and run directly:
git clone https://github.com/Fergana-Labs/cohort-analysis.git
cd cohort-analysis
python3 -m venv .venv
source .venv/bin/activate
pip install -r requirements.txt
python app/server.py
# Open http://localhost:8000After installing the plugin, paste one of these prompts:
For CSV/Excel files:
I want to analyze my cohort data.
Here's my data file: [filename.csv or filename.xlsx].
Please run /cohort-analysis to set it up and launch the dashboard.
For a PostgreSQL database:
I want to analyze my cohort data.
My database connection string is: postgresql://user:pass@host:port/dbname
Please run /cohort-analysis to explore my schema, set it up, and launch the dashboard.
Claude Code will:
- Detect your data files or explore your database schema
- Ask you to confirm column mappings (customer ID, dates, revenue, etc.)
- Ask about accrual vs cash revenue recognition if relevant
- Calculate cohort dates from each customer's first appearance (default)
- Generate the config, install dependencies, and launch the dashboard at http://localhost:8000
You can run analyses for different companies or products side by side. Each time you run the skill, it asks for a profile name. Switch between profiles using the dropdown in the dashboard header.
- Required: user/customer ID, event/action date
- Optional: event type, event count, explicit cohort date
- Required: customer ID, action/transaction date, revenue amount
- Optional: gross margin % or GP column, plan/segment type, explicit cohort date
- Required: everything for Revenue & GP, plus monthly marketing spend data
- Marketing spend can be in a separate sheet/file or provided as a simple monthly table
If your data doesn't have an explicit cohort date column, the tool calculates it automatically as each customer's first appearance date, floored to the start of the month.
- CSV files (
.csv) - Excel files (
.xlsx) — including multi-sheet workbooks - PostgreSQL — provide a connection string (
postgresql://user:pass@host:port/db)
- Engagement — User retention, total actions, active users, avg cumulative actions per user (all by cohort)
- Revenue & GP — Monthly revenue/GP layer cakes, lifetime $/customer, GP/user, active paying customers, paying customer retention
- CAC/LTV Payback — CAC per cohort, cumulative GP vs spend, payback triangles, time to 2x/3x
- GP → CAC layer cake (cumulative payback progression)
- Dollar retention / net revenue retention (NRR)
- Customer concentration (Pareto / top 100)
- Unique active customers over time (new vs returning)
Both engagement and revenue retention charts support two counting methods:
- Standard — was the user active in that specific period?
- Future — was the user active in that period or any later period?
Toggle between them directly on the retention charts.
The plugin is a three-tier system: a React frontend, a FastAPI backend, and a Python data processing pipeline.
bling_cohorts/
├── app/
│ ├── server.py # FastAPI server & API routes
│ ├── cohort_engine.py # Core analytics computation
│ ├── data_processor.py # Data loading & normalization
│ └── static/
│ └── index.html # Self-contained React SPA
├── data/
│ ├── config.json # Default config
│ └── configs/ # Named profile configs
├── skills/
│ └── cohort-analysis/
│ └── SKILL.md # Claude Code skill definition
├── .claude-plugin/
│ └── plugin.json # Plugin metadata
├── .claude/
│ └── settings.local.json # Claude Code permissions
└── requirements.txt # Python dependencies
-
Skill invocation — When you run
/cohort-analysis, Claude Code follows the interactive guide inskills/cohort-analysis/SKILL.md. It walks through data source detection, column mapping, accrual vs cash recognition, cohort date calculation, and profile naming. -
Config generation — A JSON config is written to
data/configs/{profile}.jsonmapping your source columns to the internal schema (customer_id,action_month,revenue,gp, etc.). -
Data loading — On server startup,
data_processor.pyloads your data (CSV, Excel, or PostgreSQL), parses dates (including Excel serial numbers), buckets them to month or week, and calculates cohort dates as each customer's first appearance. -
Computation —
cohort_engine.pycomputes all metrics in-memory from normalized DataFrames: retention rates, revenue/GP layer cakes, CAC payback milestones, dollar retention, customer concentration, and more. -
API serving —
server.pyexposes endpoints like/api/engagement,/api/revenue,/api/cac,/api/retention, etc. Results are cached in memory after initial load; profile switches trigger a reload via/api/reload. -
Frontend rendering —
index.htmlis a single-file React app (no build step) using Recharts for charts and Tailwind for styling, all loaded via CDN. It fetches from the API endpoints and renders interactive charts with hover highlighting, legend toggling, and cohort filtering.
| Endpoint | Purpose |
|---|---|
/api/config |
Current config |
/api/profiles |
List available profiles |
/api/reload |
Switch profile & reload data |
/api/engagement |
Engagement cohort analysis |
/api/revenue |
Revenue & GP cohorts |
/api/cac |
CAC/LTV payback analysis |
/api/retention |
Retention rates (standard & future) |
/api/layer-cake |
Cumulative GP vs CAC payback |
/api/dollar-retention |
Net revenue retention |
/api/customers |
Customer concentration (Pareto) |
/api/active-customers |
New vs returning active users |
All endpoints accept query parameters for filtering: period (month/week), include_current, start, end, mode (standard/future), basis (accrual/cash).
{
"period": "month",
"engagement": {
"source_type": "file",
"filepath": "data.xlsx",
"sheet": "Engagement",
"calculate_cohort": true,
"column_map": {
"customer_id": "User ID",
"action_month": "Event Date",
"event_type": "Event",
"event_count": "Count"
}
},
"revenue": {
"source_type": "file",
"filepath": "data.xlsx",
"sheet": "Accrual",
"cash_sheet": "Cash",
"calculate_cohort": true,
"column_map": {
"customer_id": "Customer ID",
"action_month": "Date",
"revenue": "Amount",
"gp": "Gross Profit"
}
},
"inputs": {
"filepath": "data.xlsx",
"sheet": "Inputs"
}
}For PostgreSQL, replace filepath/sheet with connection_string and query.
Python: FastAPI, Uvicorn, Pandas, openpyxl, psycopg2-binary
Frontend (CDN): React 18, Recharts, Tailwind CSS, Babel
- New endpoint: Add a compute function in
cohort_engine.py, wire it inserver.py, add a React component inindex.html. - New data source: Implement a reader in
data_processor.pythat returns a normalized DataFrame with the required columns. - Styling: Modify the
COHORT_COLORSarray or Tailwind classes inindex.html.