All docs
docs / automate
CLI and CI
petri-check in the terminal and in CI: check, lock, watch, rehearse, report and apply, output formats and the GitHub Action.
On this page
petri-check runs Petri's diagnostics without an editor: in a terminal, in CI, or for an agent. It is the same rule engine as the extension, bundled into one file with no dependencies.
npx petri-check .Commands
| Command | What it does | Details |
|---|---|---|
petri-check [dir] |
The diagnostics on a repository (offline or connected) | below |
petri-check experiments [dir] |
Every experiment, one line each, with Petri's verdict | below |
petri-check lock [dir] |
Records running experiments in petri.lock.json (treatment lock), optionally with a pre-registered stop |
below |
petri-check watch [dir] [--refresh] |
Alerts (exit 1) when a running experiment's measurement broke, and blames the commit | Watch |
petri-check report [id] [dir] |
A Markdown decision record with the health scorecard | below |
petri-check rehearse [dir] --url … |
Real visitors through your app, then a recount of what Flagsmith stored (development environments only) | below |
petri-check apply [dir] [--dry-run] |
Applies petri.plan.json: experiments as pull requests, including staged ramp rollouts |
Pull requests |
petri-check mcp |
MCP server for coding agents | MCP |
Two modes
Offline (no Flagsmith key): only the rules that need nothing but the code run.
| Rule | What it catches |
|---|---|
PETRI007 |
The SDK is initialised without enableEvents: true, so exposures and events are dropped |
PETRI008 |
A server SDK never flushes or closes, so the last batch of events is lost |
PETRI012 |
A self-hosted SDK sends its events to Flagsmith Cloud because eventsApiUrl isn't set |
PETRI013 |
A running experiment's code path changed since it started (needs a committed petri.lock.json) |
PETRI014 |
The flag is read with one identity and the conversion tracked with another |
PETRI015 |
A random identity per request, so nobody keeps their variant |
PETRI016 |
An SDK version without the experiment API (package.json) |
PETRI017 |
The variant is rendered into a cached or static response |
PETRI018 |
A browser conversion is lost because the page navigates away before the flush |
PETRI019 |
Python max_buffer_items=1 sends one request per event |
PETRI020 |
The file's language has no Flagsmith SDK that sends experiment events |
A file counts as self-hosted when you pass --self-hosted, when flagsmith.json points at a non-Cloud URL, or when the SDK is created with a literal non-Cloud apiUrl.
Connected (a key and an environment): it loads the live flags, experiments, metrics and results, and runs all twenty rules, exactly as the editor does. The key comes from FLAGSMITH_API_KEY, FLAGSMITH_API_KEY_<host> or a flagsmith.env in the checked folder; the environment from --environment or flagsmith.json. See Configuration.
FLAGSMITH_API_KEY=<org key> npx petri-check . --api-url https://flags.example.com/api/v1/ --environment <env key>Options
| Option | Default | Meaning |
|---|---|---|
[dir] |
. |
Folder to check (it skips node_modules, dist, build, .git, virtualenvs and similar) |
--api-url URL |
flagsmith.json, then Flagsmith Cloud |
Flagsmith API |
--environment KEY |
flagsmith.json |
Environment to check against |
--self-hosted |
off | Offline: treat the code as talking to self-hosted Flagsmith |
--format |
text (github in Actions) |
text, github (Actions annotations), json, or brief |
--fail-on |
error |
Exit 1 on findings of this severity or worse: error, warning, never |
Exit codes: 0 clean, 1 findings at or above --fail-on, 2 Flagsmith couldn't be read (wrong URL or key). The message names the URL it tried.
--format brief
One short line per finding and a summary, for agents and logs where every token counts:
server.mjs:6 E PETRI012 A self-hosted SDK sends events to Flagsmith Cloud because eventsApiUrl isn't set; the experiment gets no data and nothing errors.
2 files, offline: 1E 0WReading experiments: petri-check experiments
Every experiment in the environment, one line each, with Petri's verdict from the decision rule:
npx petri-check experiments .#2 checkout_cta running: SHIP free_shipping (rollout_variant=1) | free_shipping +50.4% [+0.6%, +100.3%] win 98% loss 0.23% n=2028 | srm p=0.244*The fields are the recommended arm's lift and 95% interval, its chance to beat control, its expected loss, the identities exposed, and the sample-ratio p-value (* means Petri computed it because Flagsmith returned none). rollout_variant is the id to pass when completing the experiment. --format json gives the full structure, including every metric and arm. It needs a key and an environment.
GitHub Action
# .github/workflows/petri.yml
on: [pull_request]
jobs:
petri:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v7
- uses: Ivan825/petri@v0.1.5
with:
path: .
self_hosted: "true" # offline: the code talks to self-hosted Flagsmith
# environment: ${{ vars.FLAGSMITH_ENVIRONMENT }} # optional: all 20 rules against live data
# api_url: https://flags.example.com/api/v1/
# env:
# FLAGSMITH_API_KEY: ${{ secrets.FLAGSMITH_API_KEY }}| Input | Default | Meaning |
|---|---|---|
path |
. |
Folder to check |
api_url |
flagsmith.json, then Cloud |
Flagsmith API URL |
environment |
flagsmith.json |
Environment key; needs FLAGSMITH_API_KEY in env |
self_hosted |
"false" |
Offline: treat the code as self-hosted |
fail_on |
error |
error, warning or never |
Findings appear as annotations on the pull request's changed lines. A real run: PR #1 removes eventsApiUrl from the demo shop, and the check fails with PETRI012 on the line that creates the client.
The Action runs the committed bundle action/petri-check.mjs on Node 24, so it installs nothing.
Treatment lock: petri-check lock
Writes petri.lock.json for every running experiment: its variants, split and metrics, and a fingerprint of each code path that serves the flag. Commit it, and PETRI013 then fails any change to those paths, offline, in the editor and in CI. Optionally pre-register when to decide:
npx petri-check lock . --stop-at 2026-11-29T13:00+05:30 # or --stop-n 3600, or --mde 20% (sample size from your baseline)A SHIP verdict before the planned stop is marked provisional. Completing the experiment releases the lock and keeps the decision and its evidence. Details →
Decision record: petri-check report
npx petri-check report 2 . # experiment #2; without an id, the running onePrints a Markdown record of one experiment:
- what was pre-registered in
petri.lock.json: variants, split, metrics, planned stop, and the code serving it; - every metric's arms with lift, 95% interval, chance to beat control and expected loss;
- the checks: sample ratio, treatment lock, Petri Watch and the planned stop;
- the verdict with its reasons;
- the final decision, once completed.
In GitHub Actions it is also written to the job summary, so a scheduled run leaves a readable record on every run page.
Prove it before launch: petri-check rehearse
npx petri-check rehearse . --url http://localhost:3000/ --convert form --visits 30 --rate 0.5Sends real visitors through your running app. Each gets its own cookie identity, and a share of them convert: --convert form posts wherever the page's form points, like a browser, or you can give "POST /checkout". Petri then asks Flagsmith to recompute and recounts: did it record exactly that many enrolments and conversions? A mismatch names the likely causes and the rules that catch them, and exits 1. It refuses environments named like production, so run it against a quiet development environment. A run takes about 6 minutes, because Flagsmith allows one recompute every ~5 minutes.
Two real runs against a throwaway self-hosted Flagsmith (28 Nov 2026):
Recount: sent 30 visitors → Flagsmith enrolled 30 ✓ · sent 15 conversions → Flagsmith counted 15 ✓
Measurement proven end to end. Safe to launch.Recount: sent 30 visitors → Flagsmith enrolled 30 ✓ · sent 15 conversions → Flagsmith counted 7 ✖
8 of 15 conversions missing: events aren't sent or counted on some path (a route without trackEvent; …)
Measurement is broken: fix it before real users arrive.The second shop had one extra commit: free-shipping orders get their own checkout route, and that route forgot trackEvent. Every static rule passes on it, because the code is valid wiring for the other arms. Only an end-to-end recount (or Petri Watch, after launch) sees it.