All docs
docs / get started
Quick start
From nothing to a running experiment with results next to the code, on the demo shop.
On this page
About ten minutes from nothing to a running experiment with results in your editor. You need VS Code 1.90+, Node 22 and Docker.
1. Install Petri
curl -fsSL -o petri.vsix https://github.com/Ivan825/petri/releases/latest/download/petri.vsix
code --install-extension petri.vsixIn Cursor, VSCodium or Windsurf, search Petri in Extensions (Open VSX). To build from source: git clone https://github.com/Ivan825/petri && cd petri/extension && npm ci && npm run package. To hack on it, open extension/ in VS Code and press F5.
No editor needed to try the checks: npx petri-check . in any repo that uses the Flagsmith SDK runs the code-only rules in a few seconds.
For the steps below, also clone the repo for the demo shop: git clone https://github.com/Ivan825/petri && cd petri.
2. Start Flagsmith with experimentation
Fastest: docker compose -f selfhost/docker-compose.yml up -d && node selfhost/bootstrap.mjs from the repo root, then open the repo in VS Code. Petri connects by itself and you can skip to step 3, using node --env-file=../flagsmith.env server.mjs there. (Or open the repo in GitHub Codespaces, which does all of this for you.) By hand:
Command palette → Petri: Start Self-Hosted Flagsmith (Docker). When it reports Flagsmith is up:
- Open http://localhost:8000 and create the admin account, an organisation and a project (e.g. Petri Coffee).
- Organisation Settings → API Keys → create a key.
- Back in VS Code: Petri: Connect to Flagsmith →
http://localhost:8000→ paste the key → pick the Development environment.
The Petri sidebar now lists the environment's flags and experiments. More detail in self-hosting.md.
3. Run the demo shop
cd demo-app
npm ci
FLAGSMITH_ENVIRONMENT_KEY=<the environment's client-side key> node server.mjs
# → Petri Coffee on http://localhost:3000Open demo-app/ in VS Code. server.mjs reads the flag checkout_cta with getExperimentFlag and tracks checkout_completed and order_value. Until the flag exists, Petri marks the read with PETRI001.
4. Create the experiment with the copilot
- Petri: Set Anthropic API Key.
- Select the
buyButtonLabelfunction → right-click → Turn Selection into Experiment… → "mention a delivery promise on the button". - The copilot posts its plan, then asks for approval at each step: the flag and variants, the two metrics, the experiment, and starting it. Each dialog shows the exact request.
Prefer clicking? Create the flag (multivariate, with variant keys), the metrics and the experiment in the Flagsmith dashboard, then start it from the Petri tree (▶).
5. Send shoppers
node simulate.mjs --shoppers 300 # one burst
node simulate.mjs --per-minute 6 --hours 24 # steady trafficEach simulated shopper is a real HTTP visitor with its own cookie identity, so assignment, $flag_exposure and the conversion events all go through the real SDK. Only the decision to buy is random.
6. Read the results where the code is
- The CodeLens above
getExperimentFlag("checkout_cta", …)shows the leading arm, its lift and its chance to win. - Hover the flag name for the split and per-arm results.
- Click the experiment in the sidebar for the results panel: credible intervals for every arm and metric, and Petri's verdict.
- Ask the copilot "How is the running experiment doing? Should we ship?"
7. Finish it
When the verdict says ship, click Complete & roll out…, pick the winner and approve. Petri then offers to remove the losing code path: the copilot proposes a diff that keeps only the winning label, removes the flag read and the now-unused branch, and leaves the trackEvent calls in place.
Troubleshooting
| Symptom | Likely cause |
|---|---|
| Results stay at 0 | Check the Problems panel: PETRI012 (events going to Cloud), PETRI011 (no event storage) or PETRI007 (events disabled) |
| "collecting" forever | Flagsmith needs ≥ 50 identities and ≥ 5 conversions per arm before it reports inference |
| Status bar shows an error | Hover it. Usually a wrong API URL or a revoked key; run Petri: Connect to Flagsmith again |
| Copilot says the key was rejected | Run Petri: Set Anthropic API Key again |